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