Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix TestTraceKernelModule test #2433

Merged
merged 2 commits into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions pkg/sensors/tracing/kprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6026,13 +6026,34 @@ spec:
observertesthelper.LoopEvents(ctx, t, &doneWG, &readyWG, obs)
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)
module := "nfsv4"
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
Loading