aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/internal/sandbox/assert.go
diff options
context:
space:
mode:
Diffstat (limited to 'test/internal/sandbox/assert.go')
-rw-r--r--test/internal/sandbox/assert.go40
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)