Switch to IPv4 zeroconf, add test framework with discovery test, fix serial enumeration
This commit is contained in:
73
cmd/test/main.go
Normal file
73
cmd/test/main.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/theater/picomap/lib/client"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Fprintf(os.Stderr, "usage: test <name>\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := run(os.Args[1]); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run(name string) error {
|
||||
devs, err := client.ListSerial()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testDev string
|
||||
for _, dev := range devs {
|
||||
c, err := client.NewSerial(dev, 2*time.Second)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
info, err := c.Info()
|
||||
c.Close()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if info.FirmwareName == "picomap_test" {
|
||||
testDev = dev
|
||||
break
|
||||
}
|
||||
}
|
||||
if testDev == "" {
|
||||
return fmt.Errorf("no picomap_test device found")
|
||||
}
|
||||
|
||||
fmt.Printf("test %s on %s\n", name, testDev)
|
||||
|
||||
c, err := client.NewSerial(testDev, 10*time.Second)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
result, err := c.Test(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("remote: %w", err)
|
||||
}
|
||||
|
||||
for _, msg := range result.Messages {
|
||||
fmt.Printf(" [remote] %s\n", msg)
|
||||
}
|
||||
|
||||
if result.Pass {
|
||||
fmt.Println("PASS")
|
||||
} else {
|
||||
fmt.Println("FAIL")
|
||||
os.Exit(1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user