Skip to content

Commit

Permalink
pkg/sensors: test long cwd in process exec
Browse files Browse the repository at this point in the history
Add a checker for a long cwd. Maybe this should be split into two
different tests but in a way it tests the same thing, reuse the same
directory structure, and we end up not having to restart tetragon twice.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
  • Loading branch information
mtardy committed Feb 21, 2025
1 parent 43727ce commit ab9fdf5
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions pkg/sensors/tracing/kprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7214,7 +7214,9 @@ spec:
assert.NoError(t, err)
}

func TestKprobeMatchArgsLongFile(t *testing.T) {
// TestLongPath could be split into a test checking for long args from kprobe
// events and a test checking for long cwd
func TestLongPath(t *testing.T) {
var doneWG, readyWG sync.WaitGroup
defer doneWG.Wait()

Expand Down Expand Up @@ -7249,12 +7251,15 @@ spec:

createCrdFile(t, fdinstallHook)

longFileArgChecker := ec.NewProcessKprobeChecker("longFile").
kprobeLongFileArgChecker := ec.NewProcessKprobeChecker("longFile").
WithFunctionName(sm.Full("fd_install")).
WithArgs(ec.NewKprobeArgumentListMatcher().WithValues(
ec.NewKprobeArgumentChecker().WithFileArg(ec.NewKprobeFileChecker().WithPath(sm.Full(longPathWithFile))),
))

processLongCWDChecker := ec.NewProcessExecChecker("longCWD").
WithProcess(ec.NewProcessChecker().WithBinary(sm.Suffix("ls")).WithCwd(sm.Full(longPath)))

obs, err := observertesthelper.GetDefaultObserverWithFile(t, ctx, testConfigFile, tus.Conf().TetragonLib, observertesthelper.WithMyPid())
if err != nil {
t.Fatalf("GetDefaultObserverWithFile error: %s", err)
Expand All @@ -7267,7 +7272,21 @@ spec:
require.NoError(t, err)
file.Close()

checker := ec.NewUnorderedEventChecker(longFileArgChecker)
// generate an event by exec with cwd
cwd, err := os.Getwd()
require.NoError(t, err)

err = os.Chdir(longPath)
require.NoError(t, err)

cmd := exec.Command("ls")
err = cmd.Run()
require.NoError(t, err)

err = os.Chdir(cwd)
require.NoError(t, err)

checker := ec.NewUnorderedEventChecker(kprobeLongFileArgChecker, processLongCWDChecker)
err = jsonchecker.JsonTestCheck(t, checker)
assert.NoError(t, err)
}

0 comments on commit ab9fdf5

Please sign in to comment.