Skip to content

Commit

Permalink
Add TestKprobeMatchBinariesPrefixLargePath
Browse files Browse the repository at this point in the history
Adding test that has Prefix operator in matchBinaries selector.
The file path of test binary (direct-write-tester) being executed is
larger than 256 bytes.

Signed-off-by: Andrei Fedotov <[email protected]>
  • Loading branch information
anfedotoff committed Jul 23, 2024
1 parent ac9d609 commit a8c593b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions pkg/sensors/tracing/kprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3886,6 +3886,50 @@ func TestKprobeMatchBinaries(t *testing.T) {
})
}

func TestKprobeMatchBinariesPrefixLargePath(t *testing.T) {
if !kernels.EnableLargeProgs() {
t.Skip()
}
repoBinPath := testutils.RepoRootPath("contrib/tester-progs/direct-write-tester")
tmpDir, err := os.MkdirTemp("/tmp", "tetragon-matchbinlarge-*")
assert.NoError(t, err)
defer os.RemoveAll(tmpDir)

tmpDirLarge := tmpDir + "/" + strings.Repeat("a", 250)
err = os.Mkdir(tmpDirLarge, 0755)
assert.NoError(t, err)

tmpBinaryPath := tmpDirLarge + "/direct-write-tester"

err = exec.Command("cp", repoBinPath, tmpBinaryPath).Run()
assert.NoError(t, err)

var doneWG, readyWG sync.WaitGroup
defer doneWG.Wait()

ctx, cancel := context.WithTimeout(context.Background(), tus.Conf().CmdWaitTime)
defer cancel()

createCrdFile(t, getMatchBinariesCrd("Prefix", []string{tmpDir}))

obs, err := observertesthelper.GetDefaultObserverWithFile(t, ctx, testConfigFile, tus.Conf().TetragonLib, observertesthelper.WithMyPid())
if err != nil {
t.Fatalf("GetDefaultObserverWithFile error: %s", err)
}
observertesthelper.LoopEvents(ctx, t, &doneWG, &readyWG, obs)
readyWG.Wait()

if err := exec.Command(tmpBinaryPath, tmpDirLarge+"/test").Run(); err != nil {
t.Fatalf("failed to run direct-write-tester: %s", err)
}

checker := ec.NewUnorderedEventChecker(ec.NewProcessKprobeChecker("").
WithProcess(ec.NewProcessChecker().WithBinary(sm.Full(tmpBinaryPath))).
WithFunctionName(sm.Full("fd_install")))
err = jsonchecker.JsonTestCheck(t, checker)
assert.NoError(t, err)
}

// matchBinariesPerfringTest checks that the matchBinaries do correctly
// filter the events i.e. it checks that no other events appear.
func matchBinariesPerfringTest(t *testing.T, operator string, values []string) {
Expand Down

0 comments on commit a8c593b

Please sign in to comment.