Skip to content

Commit

Permalink
tetragon: Move TestKprobeSigkill functionality to testSigkill function
Browse files Browse the repository at this point in the history
Moving TestKprobeSigkill functionality to testSigkill function,
so it can be used be following change.

Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Dec 4, 2023
1 parent f1c56d1 commit dc69517
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions pkg/sensors/tracing/kprobe_sigkill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

"github.com/cilium/tetragon/api/v1/tetragon"
"github.com/cilium/tetragon/api/v1/tetragon/codegen/eventchecker"
ec "github.com/cilium/tetragon/api/v1/tetragon/codegen/eventchecker"
"github.com/cilium/tetragon/pkg/arch"
"github.com/cilium/tetragon/pkg/jsonchecker"
Expand All @@ -25,11 +26,7 @@ import (
_ "github.com/cilium/tetragon/pkg/sensors/exec"
)

func TestKprobeSigkill(t *testing.T) {
if !kernels.MinKernelVersion("5.3.0") {
t.Skip("sigkill requires at least 5.3.0 version")
}

func testSigkill(t *testing.T, makeSpecFile func(pid string) string, checker *eventchecker.UnorderedEventChecker) {
var doneWG, readyWG sync.WaitGroup
defer doneWG.Wait()

Expand All @@ -55,19 +52,6 @@ func TestKprobeSigkill(t *testing.T) {
return pidStr
}

// makeSpecFile creates a new spec file bsed on the template, and the provided arguments
makeSpecFile := func(pid string) string {
data := map[string]string{
"MatchedPID": pid,
"NamespacePID": "false",
}
specName, err := testutils.GetSpecFromTemplate("sigkill.yaml.tmpl", data)
if err != nil {
t.Fatal(err)
}
return specName
}

if err := testCmd.Start(); err != nil {
t.Fatal(err)
}
Expand All @@ -94,6 +78,28 @@ func TestKprobeSigkill(t *testing.T) {
t.Fatalf("command failed with %s. Context error: %s", err, ctx.Err())
}

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

func TestKprobeSigkill(t *testing.T) {
if !kernels.MinKernelVersion("5.3.0") {
t.Skip("sigkill requires at least 5.3.0 version")
}

// makeSpecFile creates a new spec file bsed on the template, and the provided arguments
makeSpecFile := func(pid string) string {
data := map[string]string{
"MatchedPID": pid,
"NamespacePID": "false",
}
specName, err := testutils.GetSpecFromTemplate("sigkill.yaml.tmpl", data)
if err != nil {
t.Fatal(err)
}
return specName
}

kpChecker := ec.NewProcessKprobeChecker("").
WithFunctionName(sm.Full(arch.AddSyscallPrefixTestHelper(t, "sys_lseek"))).
WithArgs(ec.NewKprobeArgumentListMatcher().
Expand All @@ -104,8 +110,7 @@ func TestKprobeSigkill(t *testing.T) {
WithAction(tetragon.KprobeAction_KPROBE_ACTION_SIGKILL)
checker := ec.NewUnorderedEventChecker(kpChecker)

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

func testUnprivilegedUsernsKill(t *testing.T, pidns bool) {
Expand Down

0 comments on commit dc69517

Please sign in to comment.