aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/sandbox/tool/main.go
blob: 490c3c5ebff6f9db38fcdacdb95c9a0e7d8e301b (plain)
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
46
47
48
//go:build testtool

package main

import (
	"flag"
	"log"
	"os"
	"os/signal"
	"syscall"

	"hakurei.app/test/internal/sandbox"
)

var (
	flagMarkerPath string
	flagTestCase   string
	flagBpfHash    string
)

func init() {
	flag.StringVar(&flagMarkerPath, "p", "/tmp/sandbox-ok", "Pathname of completion marker")
	flag.StringVar(&flagTestCase, "t", "", "Nix store path to test case file")
	flag.StringVar(&flagBpfHash, "s", "", "String representation of expected bpf sha512 hash")
}

func main() {
	log.SetFlags(0)
	log.SetPrefix("test: ")
	flag.Parse()

	args := flag.Args()
	if len(args) < 1 {
		s := make(chan os.Signal, 1)
		signal.Notify(s, syscall.SIGINT)
		go func() { <-s; log.Println("exiting on signal (likely from verifier)"); os.Exit(0) }()

		(&sandbox.T{FS: os.DirFS("/")}).MustCheckFile(flagTestCase)
		if _, err := os.Create(flagMarkerPath); err != nil {
			log.Fatalf("cannot create success marker: %v", err)
		}
		log.Printf("blocking for seccomp check (%s)", flagMarkerPath)
		select {}
		return
	}

	log.Fatal("invalid argument")
}