summaryrefslogtreecommitdiff
path: root/test/differential/session.go
diff options
context:
space:
mode:
Diffstat (limited to 'test/differential/session.go')
-rw-r--r--test/differential/session.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/differential/session.go b/test/differential/session.go
new file mode 100644
index 0000000..3fda214
--- /dev/null
+++ b/test/differential/session.go
@@ -0,0 +1,45 @@
+package main
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "fmt"
+ "github.com/knusbaum/go9p"
+ "github.com/knusbaum/go9p/fs"
+ "os/exec"
+ "strconv"
+ "time"
+)
+
+func sessionProbe(binary string, seed int64, rounds int) map[string]any {
+ tree, root := fs.NewFS("user", "user", 0755)
+ check(root.AddChild(fs.NewStaticFile(tree.NewStat("file", "user", "user", 0600), nil)))
+ ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+ defer cancel()
+ command := exec.CommandContext(ctx, binary, strconv.FormatInt(seed, 10), strconv.Itoa(rounds))
+ input, e := command.StdinPipe()
+ check(e)
+ output, e := command.StdoutPipe()
+ check(e)
+ var stderr bytes.Buffer
+ command.Stderr = &stderr
+ check(command.Start())
+ done := make(chan error, 1)
+ go func() { done <- go9p.ServeReadWriter(output, input, tree.Server()) }()
+ e = command.Wait()
+ input.Close()
+ if e != nil {
+ panic(fmt.Sprintf("session probe: %v: %s", e, stderr.String()))
+ }
+ select {
+ case <-done:
+ case <-time.After(time.Second):
+ panic("reference server did not stop")
+ }
+ var result map[string]any
+ check(json.Unmarshal(stderr.Bytes(), &result))
+ result["server"] = "go9p v1.18.0 StaticFile"
+ result["checks"] = "walk/open/write/read/stat/EOF/clunk, content oracle, fragmented requests and replies"
+ return result
+}