diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-10-04 01:05:10 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-10-06 19:41:06 +0900 |
| commit | a7383510fb05abc98b992240cb76ad4b6c598956 (patch) | |
| tree | 90881e9d6952e050128f1378d66452c7d733d012 /test/internal/testsuite/ptrace.go | |
| parent | b452e1047ccd3e1826da16416430e6638270155b (diff) | |
test/sandbox: migrate tests
This significantly improves performance, removing overhead of nix,
python, and virtualisation. Running this in an unprivileged container
required patching the kernel, but since special runner setup was already
needed, that was an acceptable tradeoff.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'test/internal/testsuite/ptrace.go')
| -rw-r--r-- | test/internal/testsuite/ptrace.go | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/test/internal/testsuite/ptrace.go b/test/internal/testsuite/ptrace.go index 4fcf1508..ccf0900c 100644 --- a/test/internal/testsuite/ptrace.go +++ b/test/internal/testsuite/ptrace.go @@ -2,7 +2,7 @@ package testsuite import ( "crypto/sha512" - "encoding/hex" + "encoding/base64" "errors" "fmt" "os" @@ -58,10 +58,26 @@ func ptraceAttach(pid int) error { } return os.NewSyscallError("wait4", err) } - break - } + switch { + case status.Stopped(): + return nil - return nil + case status.Continued(): + continue + + case status.Signaled(): + return fmt.Errorf( + "tracee terminated by signal %s", + status.Signal(), + ) + + case status.Exited(): + return fmt.Errorf( + "tracee terminated unexpectedly with code %d", + status.ExitStatus(), + ) + } + } } // ptraceDetach detaches from the attached process referred to by pid. @@ -95,8 +111,8 @@ func getFilter(pid, index int) ([]syscall.SockFilter, error) { } // CheckFilter checks the process at pid to have its first filter's contents -// match the sha512 checksum specified in hexadecimal string representation. -func CheckFilter(pid, index int, sum string) (err error) { +// match the specified sha512 checksum. +func CheckFilter(pid, index int, sum [sha512.Size]byte) (err error) { if err = ptraceAttach(pid); err != nil { return } @@ -106,15 +122,7 @@ func CheckFilter(pid, index int, sum string) (err error) { } }() - var ( - buf []syscall.SockFilter - want []byte - ) - - if want, err = hex.DecodeString(sum); err != nil { - return - } - + var buf []syscall.SockFilter h := sha512.New() if buf, err = getFilter(pid, index); err != nil { return @@ -125,11 +133,11 @@ func CheckFilter(pid, index int, sum string) (err error) { )) } - if got := h.Sum(nil); string(got) != string(want) { + if got := h.Sum(nil); string(got) != string(sum[:]) { return fmt.Errorf( "bad filter\n\t got: %s\n\twant: %s", - hex.EncodeToString(got), - sum, + base64.StdEncoding.EncodeToString(got), + base64.StdEncoding.EncodeToString(sum[:]), ) } return |
