From 6262f0905b5034b12b6030205d5940c7f2a664a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geyslan=20Greg=C3=B3rio?= Date: Tue, 31 Oct 2023 16:47:54 -0300 Subject: [PATCH] fix(tests): check PinProccessToCPU err --- tests/integration/syscaller/cmd/syscaller.go | 8 ++++++-- tests/testutils/cpu.go | 5 +++-- tests/testutils/errors.go | 10 ++++++++++ tests/testutils/exec.go | 5 ++++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/integration/syscaller/cmd/syscaller.go b/tests/integration/syscaller/cmd/syscaller.go index a9fe8c98820d..5353c774ee30 100644 --- a/tests/integration/syscaller/cmd/syscaller.go +++ b/tests/integration/syscaller/cmd/syscaller.go @@ -11,7 +11,11 @@ import ( ) func main() { - testutils.PinProccessToCPU() + err := testutils.PinProccessToCPU() + if err != nil { + fmt.Fprintf(os.Stderr, "PinProccessToCPU: %v\n", err) + os.Exit(1) + } runtime.LockOSThread() defer runtime.UnlockOSThread() @@ -31,7 +35,7 @@ func main() { syscallsToCall = append(syscallsToCall, events.ID(syscallNum)) } - err := changeOwnComm(callerComm) + err = changeOwnComm(callerComm) if err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) os.Exit(1) diff --git a/tests/testutils/cpu.go b/tests/testutils/cpu.go index 92a797f03292..4f4b239e9be0 100644 --- a/tests/testutils/cpu.go +++ b/tests/testutils/cpu.go @@ -7,7 +7,7 @@ import ( const CPUForTests = 0 // CPU to pin test processes to // PinProccessToCPU pins the current process to a specific CPU -func PinProccessToCPU(id ...int) { +func PinProccessToCPU(id ...int) error { if len(id) == 0 { id = append(id, CPUForTests) } @@ -16,5 +16,6 @@ func PinProccessToCPU(id ...int) { for _, i := range id { cpuMask.Set(i) } - _ = unix.SchedSetaffinity(0, &cpuMask) + + return unix.SchedSetaffinity(0, &cpuMask) } diff --git a/tests/testutils/errors.go b/tests/testutils/errors.go index b367c17cfb2e..b9fad51861c6 100644 --- a/tests/testutils/errors.go +++ b/tests/testutils/errors.go @@ -52,6 +52,16 @@ func (e *commandFailed) Error() string { return fmt.Sprintf("command '%s' failed with error: %s", e.command, e.err) } +// failedToPinProcessToCPU is returned when a command fails to pin to a CPU. +type failedToPinProcessToCPU struct { + command string + err error +} + +func (e *failedToPinProcessToCPU) Error() string { + return fmt.Sprintf("failed to pin command '%s' to CPU: %s", e.command, e.err) +} + // failedToParseCmd is returned when a command fails to parse. type failedToParseCmd struct { command string diff --git a/tests/testutils/exec.go b/tests/testutils/exec.go index 024d2f84a272..ce17af097e18 100644 --- a/tests/testutils/exec.go +++ b/tests/testutils/exec.go @@ -49,7 +49,10 @@ func ParseCmd(fullCmd string) (string, []string, error) { // ExecPinnedCmdWithTimeout executes a cmd with a timeout and returns the PID of the process. func ExecPinnedCmdWithTimeout(command string, timeout time.Duration) (int, error) { - PinProccessToCPU() // pin this goroutine to a specific CPU + err := PinProccessToCPU() // pin this goroutine to a specific CPU + if err != nil { + return 0, &failedToPinProcessToCPU{command: command, err: err} + } runtime.LockOSThread() // wire this goroutine to a specific OS thread defer runtime.UnlockOSThread() // unlock the thread when we're done