From f0087bcd4d595518e5f1c3938ec2f224a712ee27 Mon Sep 17 00:00:00 2001 From: Djalal Harouni Date: Wed, 15 May 2024 09:46:58 +0100 Subject: [PATCH 1/2] test: show errors on TestTraceKernelModule Signed-off-by: Djalal Harouni --- pkg/sensors/tracing/kprobe_test.go | 31 +++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/pkg/sensors/tracing/kprobe_test.go b/pkg/sensors/tracing/kprobe_test.go index 9f11f8754f7..38c503d0e7d 100644 --- a/pkg/sensors/tracing/kprobe_test.go +++ b/pkg/sensors/tracing/kprobe_test.go @@ -6027,12 +6027,33 @@ spec: readyWG.Wait() module := "xfs" - if err := exec.Command("/usr/sbin/modprobe", module).Run(); err != nil { - t.Fatalf("failed to load %s module: %s", module, err) + var stdout, stderr bytes.Buffer + testCmd := exec.CommandContext(ctx, "/usr/sbin/modprobe", module) + testCmd.Stdout = &stdout + testCmd.Stderr = &stderr + if err := testCmd.Start(); err != nil { + t.Fatal(err) + } + if err := testCmd.Wait(); err != nil { + stderr := stderr.String() + t.Fatalf("Load '%s' module failed with %s. Context error: %v, error output: %v", module, err, ctx.Err(), stderr) + } + if len(stdout.String()) > 0 { + t.Logf("Load '%s' module stdout:\n%v\n", module, stdout.String()) } - if err := exec.Command("/usr/sbin/modprobe", "-r", module).Run(); err != nil { - t.Fatalf("failed to unload %s module: %s", module, err) + testCmd = exec.CommandContext(ctx, "/usr/sbin/modprobe", "-r", module) + testCmd.Stdout = &stdout + testCmd.Stderr = &stderr + if err := testCmd.Start(); err != nil { + t.Fatal(err) + } + if err := testCmd.Wait(); err != nil { + stderr := stderr.String() + t.Fatalf("Unload '%s' module failed with %s. Context error: %v, error output: %v", module, err, ctx.Err(), stderr) + } + if len(stdout.String()) > 0 { + t.Logf("Unload '%s' module stdout:\n%v\n", module, stdout.String()) } process := ec.NewProcessChecker(). @@ -6044,7 +6065,7 @@ spec: WithValues( ec.NewKprobeArgumentChecker().WithFileArg( ec.NewKprobeFileChecker(). - WithPath(sm.Suffix(fmt.Sprintf("%s.ko", module)))), + WithPath(sm.Contains(fmt.Sprintf("%s.ko", module)))), ec.NewKprobeArgumentChecker().WithIntArg(2), ), ) From 8e62a63830318ef751f87e0350623530771cc49e Mon Sep 17 00:00:00 2001 From: Djalal Harouni Date: Wed, 15 May 2024 13:33:31 +0100 Subject: [PATCH 2/2] test: test trace module operation Switch to NFS nfsv4 instead of xfs module as it seems it's builtin on the actuated Ubuntu arm Signed-off-by: Djalal Harouni --- pkg/sensors/tracing/kprobe_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/sensors/tracing/kprobe_test.go b/pkg/sensors/tracing/kprobe_test.go index 38c503d0e7d..3a05b126ab3 100644 --- a/pkg/sensors/tracing/kprobe_test.go +++ b/pkg/sensors/tracing/kprobe_test.go @@ -6026,7 +6026,7 @@ spec: observertesthelper.LoopEvents(ctx, t, &doneWG, &readyWG, obs) readyWG.Wait() - module := "xfs" + module := "nfsv4" var stdout, stderr bytes.Buffer testCmd := exec.CommandContext(ctx, "/usr/sbin/modprobe", module) testCmd.Stdout = &stdout