diff --git a/harness/main.go b/harness/main.go index e9d2afe..3152f09 100644 --- a/harness/main.go +++ b/harness/main.go @@ -1,6 +1,6 @@ -// Runs cabletest for a fixed time, dumps the panel to png, and streams it as -// png deltas on :8080, since the machine with the display on it is not the -// machine looking at it. +// Runs cabletest until interrupted or for -for, dumps the panel to png, and +// streams it as png deltas on :8080, since the machine with the display on it +// is not the machine looking at it. // // sudo go run ./harness -for 20s -at 3s,15s -- -a enp1s0f0np0 -b enp1s0f1np1 package main @@ -35,7 +35,7 @@ const ( ) func main() { - runFor := flag.Duration("for", 15*time.Second, "how long to let cabletest run") + runFor := flag.Duration("for", 0, "how long to let cabletest run; 0 runs until interrupted") at := flag.String("at", "", "offsets to capture the panel at, comma separated, e.g. 3s,10s") fuzzN := flag.Int("fuzz", 0, "repeat the whole lifecycle this many times; full output only for runs that fail or log module events") flag.Parse() @@ -49,6 +49,11 @@ func main() { var err error if *fuzzN > 0 { + if *runFor <= 0 { + restoreTerm() + fmt.Fprintln(os.Stderr, "fuzz needs a bounded -for") + os.Exit(1) + } err = fuzz(*fuzzN, *runFor, flag.Args()) } else { err = run(*runFor, *at, os.Stdout, flag.Args()) @@ -122,7 +127,7 @@ func parseShots(s string, runFor time.Duration) ([]time.Duration, error) { if err != nil { return nil, fmt.Errorf("bad offset %q: %w", f, err) } - if d < 0 || d >= runFor { + if d < 0 || (runFor > 0 && d >= runFor) { return nil, fmt.Errorf("offset %s falls outside the %s run", d, runFor) } out = append(out, d) @@ -189,12 +194,16 @@ func run(runFor time.Duration, at string, out io.Writer, args []string) error { fmt.Printf("captured %s\n", name) } + var expire <-chan time.Time + if runFor > 0 { + expire = time.After(time.Until(start.Add(runFor))) + } select { case err := <-done: return exited(start, err) case <-sigs: return interrupted(start, pgid, done) - case <-time.After(time.Until(start.Add(runFor))): + case <-expire: } return stop(pgid, done) } diff --git a/harness/stream.go b/harness/stream.go index 349087d..af1e81f 100644 --- a/harness/stream.go +++ b/harness/stream.go @@ -24,23 +24,31 @@ const page = `