summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-10 07:42:04 +0200
committerPaul Buetow <paul@buetow.org>2026-03-10 07:42:04 +0200
commit34f286d38d1329e8f904bbb63c4cfea2f7fe7642 (patch)
tree178389382b1a90f9f738a67ce3efd8e70a324c8a
parent590b3acdae8f4adb34d96889fad483fafa880e93 (diff)
integrationtests: return errors for pidfd syscall lookup (task 377)
-rw-r--r--integrationtests/cmd/ioworkload/scenario_pidfd.go46
-rw-r--r--integrationtests/cmd/ioworkload/scenario_pidfd_test.go57
2 files changed, 87 insertions, 16 deletions
diff --git a/integrationtests/cmd/ioworkload/scenario_pidfd.go b/integrationtests/cmd/ioworkload/scenario_pidfd.go
index 1ac7c4d..2aafced 100644
--- a/integrationtests/cmd/ioworkload/scenario_pidfd.go
+++ b/integrationtests/cmd/ioworkload/scenario_pidfd.go
@@ -76,7 +76,11 @@ func pidfdGetfdFailure() error {
}
func pidfdOpen(pid int, flags uintptr) (int, error) {
- fd, _, errno := syscall.Syscall(pidfdOpenSyscallNr(), uintptr(pid), flags, 0)
+ syscallNr, err := pidfdOpenSyscallNr()
+ if err != nil {
+ return 0, err
+ }
+ fd, _, errno := syscall.Syscall(syscallNr, uintptr(pid), flags, 0)
if errno != 0 {
return 0, errno
}
@@ -84,8 +88,12 @@ func pidfdOpen(pid int, flags uintptr) (int, error) {
}
func pidfdGetfd(pidfd int, targetFd int, flags uintptr) (int, error) {
+ syscallNr, err := pidfdGetfdSyscallNr()
+ if err != nil {
+ return 0, err
+ }
fd, _, errno := syscall.Syscall(
- pidfdGetfdSyscallNr(),
+ syscallNr,
uintptr(pidfd),
uintptr(targetFd),
flags,
@@ -96,24 +104,30 @@ func pidfdGetfd(pidfd int, targetFd int, flags uintptr) (int, error) {
return int(fd), nil
}
-func pidfdOpenSyscallNr() uintptr {
+func pidfdOpenSyscallNr() (uintptr, error) {
+ return pidfdOpenSyscallNrForArch(runtime.GOARCH)
+}
+
+func pidfdGetfdSyscallNr() (uintptr, error) {
+ return pidfdGetfdSyscallNrForArch(runtime.GOARCH)
+}
+
+func pidfdOpenSyscallNrForArch(arch string) (uintptr, error) {
// Go's syscall package does not expose pidfd constants on all toolchains.
- if runtime.GOARCH == "amd64" {
- return 434
+ switch arch {
+ case "amd64", "arm64":
+ return 434, nil
+ default:
+ return 0, fmt.Errorf("pidfd_open syscall number not defined for GOARCH=%s", arch)
}
- if runtime.GOARCH == "arm64" {
- return 434
- }
- panic("pidfd_open syscall number not defined for GOARCH=" + runtime.GOARCH)
}
-func pidfdGetfdSyscallNr() uintptr {
+func pidfdGetfdSyscallNrForArch(arch string) (uintptr, error) {
// Go's syscall package does not expose pidfd constants on all toolchains.
- if runtime.GOARCH == "amd64" {
- return 438
- }
- if runtime.GOARCH == "arm64" {
- return 438
+ switch arch {
+ case "amd64", "arm64":
+ return 438, nil
+ default:
+ return 0, fmt.Errorf("pidfd_getfd syscall number not defined for GOARCH=%s", arch)
}
- panic("pidfd_getfd syscall number not defined for GOARCH=" + runtime.GOARCH)
}
diff --git a/integrationtests/cmd/ioworkload/scenario_pidfd_test.go b/integrationtests/cmd/ioworkload/scenario_pidfd_test.go
new file mode 100644
index 0000000..5ee1002
--- /dev/null
+++ b/integrationtests/cmd/ioworkload/scenario_pidfd_test.go
@@ -0,0 +1,57 @@
+package main
+
+import "testing"
+
+func TestPidfdOpenSyscallNrForArch(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ arch string
+ want uintptr
+ wantErr bool
+ }{
+ {name: "amd64", arch: "amd64", want: 434},
+ {name: "arm64", arch: "arm64", want: 434},
+ {name: "unsupported", arch: "riscv64", wantErr: true},
+ } {
+ got, err := pidfdOpenSyscallNrForArch(tc.arch)
+ if tc.wantErr {
+ if err == nil {
+ t.Fatalf("%s: expected error", tc.name)
+ }
+ continue
+ }
+ if err != nil {
+ t.Fatalf("%s: unexpected error: %v", tc.name, err)
+ }
+ if got != tc.want {
+ t.Fatalf("%s: got %d, want %d", tc.name, got, tc.want)
+ }
+ }
+}
+
+func TestPidfdGetfdSyscallNrForArch(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ arch string
+ want uintptr
+ wantErr bool
+ }{
+ {name: "amd64", arch: "amd64", want: 438},
+ {name: "arm64", arch: "arm64", want: 438},
+ {name: "unsupported", arch: "riscv64", wantErr: true},
+ } {
+ got, err := pidfdGetfdSyscallNrForArch(tc.arch)
+ if tc.wantErr {
+ if err == nil {
+ t.Fatalf("%s: expected error", tc.name)
+ }
+ continue
+ }
+ if err != nil {
+ t.Fatalf("%s: unexpected error: %v", tc.name, err)
+ }
+ if got != tc.want {
+ t.Fatalf("%s: got %d, want %d", tc.name, got, tc.want)
+ }
+ }
+}