Skip to content

Commit

Permalink
test: show errors on TestTraceKernelModule
Browse files Browse the repository at this point in the history
Signed-off-by: Djalal Harouni <tixxdz@gmail.com>
  • Loading branch information
tixxdz committed May 15, 2024
1 parent 58d92f0 commit f0087bc
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions pkg/sensors/tracing/kprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand All @@ -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),
),
)
Expand Down

0 comments on commit f0087bc

Please sign in to comment.