summaryrefslogtreecommitdiff
path: root/test/differential/session.go
blob: 3fda21433fef7d050080d394f8d90380aaaa9588 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
}