Add an auto-measure toggle with a cable length range, and console keys through the harness
This commit is contained in:
@@ -20,6 +20,8 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
var errInterrupted = errors.New("interrupted")
|
||||
@@ -43,18 +45,40 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
restoreTerm := rawKeys()
|
||||
|
||||
var err error
|
||||
if *fuzzN > 0 {
|
||||
err = fuzz(*fuzzN, *runFor, flag.Args())
|
||||
} else {
|
||||
err = run(*runFor, *at, os.Stdout, flag.Args())
|
||||
}
|
||||
restoreTerm()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Console keys reach cabletest as they are pressed, the same as at the
|
||||
// appliance; isig stays on so ^C still stops the run through the relay.
|
||||
func rawKeys() func() {
|
||||
fd := int(os.Stdin.Fd())
|
||||
orig, err := unix.IoctlGetTermios(fd, unix.TCGETS)
|
||||
if err != nil {
|
||||
return func() {}
|
||||
}
|
||||
saved := *orig
|
||||
raw := *orig
|
||||
raw.Lflag &^= unix.ICANON | unix.ECHO
|
||||
raw.Cc[unix.VMIN] = 1
|
||||
raw.Cc[unix.VTIME] = 0
|
||||
if unix.IoctlSetTermios(fd, unix.TCSETS, &raw) != nil {
|
||||
return func() {}
|
||||
}
|
||||
return func() { unix.IoctlSetTermios(fd, unix.TCSETS, &saved) }
|
||||
}
|
||||
|
||||
func fuzz(n int, runFor time.Duration, args []string) error {
|
||||
failed := 0
|
||||
for i := 1; i <= n; i++ {
|
||||
@@ -133,6 +157,13 @@ func run(runFor time.Duration, at string, out io.Writer, args []string) error {
|
||||
// killed when go run dies, and an orphan holding the wire poisons every
|
||||
// measurement after it.
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
// The child's own process group makes the tty off limits to it (reading
|
||||
// from the background raises SIGTTIN), so the harness reads and forwards.
|
||||
stdin, err := cmd.StdinPipe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
go io.Copy(stdin, os.Stdin)
|
||||
if err := cmd.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user