-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tetragon: Add test for exec events generated throgh main
Execute tetragon through main and make sure we get exec events generated. Signed-off-by: Jiri Olsa <jolsa@kernel.org>
- Loading branch information
Showing
3 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Tetragon | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
ec "github.com/cilium/tetragon/api/v1/tetragon/codegen/eventchecker" | ||
"github.com/cilium/tetragon/pkg/defaults" | ||
"github.com/cilium/tetragon/pkg/jsonchecker" | ||
"github.com/cilium/tetragon/pkg/option" | ||
"github.com/cilium/tetragon/pkg/testutils" | ||
tus "github.com/cilium/tetragon/pkg/testutils/sensors" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
ec := tus.TestSensorsRun(m, "SensorBugtool") | ||
os.Exit(ec) | ||
} | ||
|
||
func TestGeneratedExecEvents(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
|
||
ready := func() { | ||
cancel() | ||
} | ||
|
||
option.Config.ExportRateLimit = -1 | ||
option.Config.DataCacheSize = 1024 | ||
option.Config.ProcessCacheSize = 65536 | ||
option.Config.BpfDir = defaults.DefaultMapPrefix | ||
option.Config.HubbleLib = tus.Conf().TetragonLib | ||
option.Config.TracingPolicyDir = defaults.DefaultTpDir | ||
|
||
f, err := testutils.CreateExportFile(t) | ||
if err != nil { | ||
t.Fatalf("testutils.CreateExportFilefailed: %v\n", err) | ||
} | ||
defer f.Close() | ||
|
||
fname, err := testutils.GetExportFilename(t) | ||
if err != nil { | ||
t.Fatalf("testutils.GetExportFilename failed: %v\n", err) | ||
} | ||
option.Config.ExportFilename = fname | ||
|
||
err = tetragonExecuteCtx(ctx, cancel, ready) | ||
assert.NoError(t, err) | ||
|
||
checker := ec.NewUnorderedEventChecker( | ||
ec.NewProcessExecChecker("").WithProcess( | ||
ec.NewProcessChecker().WithPid(1)), | ||
) | ||
|
||
err = jsonchecker.JsonTestCheck(t, checker) | ||
assert.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters