Skip to content

Commit

Permalink
tetragon: Add test for uprobe function argument retrieval
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri committed Jan 17, 2024
1 parent e2e5eff commit dad139a
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions pkg/sensors/tracing/uprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/cilium/tetragon/pkg/jsonchecker"
"github.com/cilium/tetragon/pkg/kernels"
"github.com/cilium/tetragon/pkg/logger"
lc "github.com/cilium/tetragon/pkg/matchers/listmatcher"
sm "github.com/cilium/tetragon/pkg/matchers/stringmatcher"
"github.com/cilium/tetragon/pkg/observer/observertesthelper"
"github.com/cilium/tetragon/pkg/sensors"
Expand Down Expand Up @@ -365,3 +366,65 @@ spec:
err = jsonchecker.JsonTestCheck(t, checker)
assert.NoError(t, err)
}

func TestUprobeArgsInt(t *testing.T) {
execBinary := testutils.RepoRootPath("contrib/tester-progs/uprobe-test-1")
libUprobe := testutils.RepoRootPath("contrib/tester-progs/libuprobe.so")

pathHook := `
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
name: "uprobe"
spec:
uprobes:
- path: "` + libUprobe + `"
symbols:
- "uprobe_test_lib_arg1"
args:
- index: 0
type: "int"
selectors:
- matchBinaries:
- operator: "In"
values:
- "` + execBinary + `"
`

pathConfigHook := []byte(pathHook)
err := os.WriteFile(testConfigFile, pathConfigHook, 0644)
if err != nil {
t.Fatalf("writeFile(%s): err %s", testConfigFile, err)
}

upChecker := ec.NewProcessUprobeChecker("UPROBE_ARGS_INT").
WithProcess(ec.NewProcessChecker().
WithBinary(sm.Full(execBinary))).
WithSymbol(sm.Full("uprobe_test_lib_arg1")).
WithArgs(ec.NewKprobeArgumentListMatcher().
WithOperator(lc.Ordered).
WithValues(
ec.NewKprobeArgumentChecker().WithIntArg(123),
))
checker := ec.NewUnorderedEventChecker(upChecker)

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

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

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(execBinary).Run(); err != nil {
t.Fatalf("Failed to execute test binary: %s\n", err)
}

err = jsonchecker.JsonTestCheck(t, checker)
assert.NoError(t, err)
}

0 comments on commit dad139a

Please sign in to comment.