diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-10-03 18:46:38 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-10-03 18:52:11 +0900 |
| commit | f2e188c4a0f472bcbd87189f63099d2c73936789 (patch) | |
| tree | 1b96bd5bb8ae99460d93e6d477e5ee024a08b009 /test/internal/sandbox/assert.go | |
| parent | aa41002e8078a3ab00896cbd403e573c6dd817c2 (diff) | |
test/internal/testsuite: move ptrace helpers
This also cleans up their API.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'test/internal/sandbox/assert.go')
| -rw-r--r-- | test/internal/sandbox/assert.go | 40 |
1 files changed, 5 insertions, 35 deletions
diff --git a/test/internal/sandbox/assert.go b/test/internal/sandbox/assert.go index 2125419b..e2bcc8ae 100644 --- a/test/internal/sandbox/assert.go +++ b/test/internal/sandbox/assert.go @@ -9,8 +9,6 @@ package sandbox import ( - "crypto/sha512" - "encoding/hex" "encoding/json" "errors" "io/fs" @@ -21,6 +19,7 @@ import ( "syscall" "hakurei.app/test/internal/mountinfo" + "hakurei.app/test/internal/testsuite" ) var ( @@ -204,20 +203,20 @@ func (t *T) MustCheck(want *TestCase) { } func MustCheckFilter(pid int, want string) { - err := CheckFilter(pid, want) + err := testsuite.CheckFilter(pid, 0, want) if err == nil { return } - perr, ok := errors.AsType[*ptraceError](err) + e, ok := errors.AsType[*os.SyscallError](err) if !ok { fatalf("%s", err) } - switch perr.op { + switch e.Syscall { case "PTRACE_ATTACH": fatalf("cannot attach to process %d: %v", pid, err) case "PTRACE_SECCOMP_GET_FILTER": - if perr.errno == syscall.ENOENT { + if errors.Is(e.Err, syscall.ENOENT) { fatalf("seccomp filter not installed for process %d", pid) } fatalf("cannot get filter: %v", err) @@ -228,35 +227,6 @@ func MustCheckFilter(pid int, want string) { *(*int)(nil) = 0 // not reached } -func CheckFilter(pid int, want string) error { - if err := ptraceAttach(pid); err != nil { - return err - } - defer func() { - if err := ptraceDetach(pid); err != nil { - printf("cannot detach from process %d: %v", pid, err) - } - }() - - h := sha512.New() - - if buf, err := getFilter[[8]byte](pid, 0); err != nil { - return err - } else { - for _, b := range buf { - h.Write(b[:]) - } - } - - if got := hex.EncodeToString(h.Sum(nil)); got != want { - printf("[FAIL] %s", got) - return syscall.ENOTRECOVERABLE - } else { - printf("[ OK ] %s", got) - return nil - } -} - func mustDecode(wantFilePath string, v any) { if f, err := os.Open(wantFilePath); err != nil { fatalf("cannot open %q: %v", wantFilePath, err) |
