Skip to content

Commit

Permalink
tetragon: Remove ctx argument from getTestSensorManager function
Browse files Browse the repository at this point in the history
Now we removed StopSensorManager call from getTestSensorManager
we no longer need it to have the ctx argument.

Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Oct 30, 2024
1 parent f6a7026 commit fdbff84
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pkg/metrics/policymetrics/policymetrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ tetragon_tracingpolicy_loaded{state="load_error"} %d
// manager because in the observer tests we only initialize metrics while the observer
// changes for every test (see:
// https://github.com/cilium/tetragon/blob/22eb995b19207ac0ced2dd83950ec8e8aedd122d/pkg/observer/observertesthelper/observer_test_helper.go#L272-L276)
manager := tus.GetTestSensorManagerWithDummyPF(context.TODO(), t).Manager
manager := tus.GetTestSensorManagerWithDummyPF(t).Manager
observer.SetSensorManager(manager)
t.Cleanup(observer.ResetSensorManager)

Expand Down
12 changes: 6 additions & 6 deletions pkg/sensors/exec/cgroups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@ func setupTgRuntimeConf(t *testing.T, trackingCgrpLevel, logLevel, hierarchyId,
}
}

func setupObserver(ctx context.Context, t *testing.T) *tus.TestSensorManager {
testManager := tus.GetTestSensorManager(ctx, t)
func setupObserver(t *testing.T) *tus.TestSensorManager {
testManager := tus.GetTestSensorManager(t)
if err := observer.InitDataCache(1024); err != nil {
t.Fatalf("failed to call observer.InitDataCache %s", err)
}
Expand Down Expand Up @@ -650,7 +650,7 @@ func TestCgroupNoEvents(t *testing.T) {

tus.LoadSensor(t, base.GetInitialSensor())

testManager := setupObserver(ctx, t)
testManager := setupObserver(t)

testManager.AddAndEnableSensors(ctx, t, getLoadedSensors())

Expand Down Expand Up @@ -702,7 +702,7 @@ func TestCgroupEventMkdirRmdir(t *testing.T) {

tus.LoadSensor(t, base.GetInitialSensor())

testManager := setupObserver(ctx, t)
testManager := setupObserver(t)

testManager.AddAndEnableSensors(ctx, t, getLoadedSensors())
t.Cleanup(func() {
Expand Down Expand Up @@ -881,7 +881,7 @@ func testCgroupv2HierarchyInUnified(ctx context.Context, t *testing.T,
// Test Cgroupv2 tries to emulate k8s hierarchy without exec context
// Works in systemd unified and hybrid mode according to parameter
func testCgroupv2K8sHierarchy(ctx context.Context, t *testing.T, mode cgroups.CgroupModeCode, withExec bool) {
testManager := setupObserver(ctx, t)
testManager := setupObserver(t)

testManager.AddAndEnableSensors(ctx, t, getLoadedSensors())
t.Cleanup(func() {
Expand Down Expand Up @@ -1095,7 +1095,7 @@ func testCgroupv1K8sHierarchyInHybrid(t *testing.T, withExec bool, selectedContr

tus.LoadSensor(t, base.GetInitialSensor())

testManager := setupObserver(ctx, t)
testManager := setupObserver(t)

testManager.AddAndEnableSensors(ctx, t, getLoadedSensors())

Expand Down
2 changes: 1 addition & 1 deletion pkg/sensors/test/lseek_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestSensorLseekEnable(t *testing.T) {

sensor := GetTestSensor()

smanager := tus.GetTestSensorManager(ctx, t)
smanager := tus.GetTestSensorManager(t)
smanager.AddAndEnableSensor(ctx, t, sensor, sensor.Name)

observertesthelper.LoopEvents(ctx, t, &doneWG, &readyWG, obs)
Expand Down
8 changes: 4 additions & 4 deletions pkg/sensors/tracing/kprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3975,7 +3975,7 @@ func matchBinariesPerfringTest(t *testing.T, operator string, values []string) {
option.Config.HubbleLib = tus.Conf().TetragonLib
tus.LoadSensor(t, base.GetInitialSensor())
tus.LoadSensor(t, testsensor.GetTestSensor())
sm := tus.GetTestSensorManager(ctx, t)
sm := tus.GetTestSensorManager(t)

matchBinariesTracingPolicy := tracingpolicy.GenericTracingPolicy{
Metadata: v1.ObjectMeta{
Expand Down Expand Up @@ -4089,7 +4089,7 @@ func TestKprobeMatchBinariesEarlyExec(t *testing.T) {
option.Config.HubbleLib = tus.Conf().TetragonLib
tus.LoadSensor(t, base.GetInitialSensor())
tus.LoadSensor(t, testsensor.GetTestSensor())
sm := tus.GetTestSensorManager(ctx, t)
sm := tus.GetTestSensorManager(t)

matchBinariesTracingPolicy := tracingpolicy.GenericTracingPolicy{
Metadata: v1.ObjectMeta{
Expand Down Expand Up @@ -4156,7 +4156,7 @@ func TestKprobeMatchBinariesPrefixMatchArgs(t *testing.T) {
option.Config.HubbleLib = tus.Conf().TetragonLib
tus.LoadSensor(t, base.GetInitialSensor())
tus.LoadSensor(t, testsensor.GetTestSensor())
sm := tus.GetTestSensorManager(ctx, t)
sm := tus.GetTestSensorManager(t)

matchBinariesTracingPolicy := tracingpolicy.GenericTracingPolicy{
Metadata: v1.ObjectMeta{
Expand Down Expand Up @@ -6094,7 +6094,7 @@ func TestLinuxBinprmExtractPath(t *testing.T) {
option.Config.HubbleLib = tus.Conf().TetragonLib
tus.LoadSensor(t, base.GetInitialSensor())
tus.LoadSensor(t, testsensor.GetTestSensor())
sm := tus.GetTestSensorManager(ctx, t)
sm := tus.GetTestSensorManager(t)

bprmTracingPolicy := tracingpolicy.GenericTracingPolicy{
Metadata: v1.ObjectMeta{
Expand Down
2 changes: 1 addition & 1 deletion pkg/sensors/tracing/policyfilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestNamespacedPolicies(t *testing.T) {

tus.LoadSensor(t, base.GetInitialSensor())
tus.LoadSensor(t, testsensor.GetTestSensor())
sm := tus.GetTestSensorManager(ctx, t)
sm := tus.GetTestSensorManager(t)

// First, we create two lseek-pipe commands and add them to a different cgroup. See
// contrib/tester-progs/go/lseek-pipe for details of how lseek-pipe wowkrs, but basically it
Expand Down
6 changes: 3 additions & 3 deletions pkg/sensors/tracing/tracepoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestGenericTracepointSimple(t *testing.T) {
t.Fatalf("GetDefaultObserver error: %s", err)
}

sm := tus.GetTestSensorManager(ctx, t)
sm := tus.GetTestSensorManager(t)
// create and add sensor
sensor, err := createGenericTracepointSensor(&spec, "GtpLseekTest", policyfilter.NoFilterID, "policyName", "", nil)
if err != nil {
Expand Down Expand Up @@ -145,7 +145,7 @@ func doTestGenericTracepointPidFilter(t *testing.T, conf v1alpha1.TracepointSpec
Lists: []v1alpha1.ListSpec{},
}

sm := tus.GetTestSensorManager(ctx, t)
sm := tus.GetTestSensorManager(t)
// create and add sensor
sensor, err := createGenericTracepointSensor(&spec, "GtpLseekTest", policyfilter.NoFilterID, "policyName", "", nil)
if err != nil {
Expand Down Expand Up @@ -541,7 +541,7 @@ func TestTracepointCloneThreads(t *testing.T) {
t.Fatalf("GetDefaultObserver error: %s", err)
}

sm := tus.GetTestSensorManager(ctx, t)
sm := tus.GetTestSensorManager(t)
// create and add sensor
sensor, err := createGenericTracepointSensor(&spec, "GtpLseekTest", policyfilter.NoFilterID, "policyName", "", nil)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions pkg/testutils/sensors/sensors.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ type TestSensorManager struct {
// Otherwise, it creates a new one. If it creates a new one it will use the test name to create a
// unqique directory for maps/etc, and will also register the necessary cleanup functions using
// t.Cleanup()
func GetTestSensorManager(ctx context.Context, t *testing.T) *TestSensorManager {
func GetTestSensorManager(t *testing.T) *TestSensorManager {
pfState, err := policyfilter.GetState()
if err != nil {
t.Fatalf("failed to initialize policy filter state: %s", err)
}
return getTestSensorManager(ctx, t, pfState)
return getTestSensorManager(t, pfState)
}

func GetTestSensorManagerWithDummyPF(ctx context.Context, t *testing.T) *TestSensorManager {
return getTestSensorManager(ctx, t, &dummyPF{})
func GetTestSensorManagerWithDummyPF(t *testing.T) *TestSensorManager {
return getTestSensorManager(t, &dummyPF{})
}

func getTestSensorManager(ctx context.Context, t *testing.T, pfState policyfilter.State) *TestSensorManager {
func getTestSensorManager(t *testing.T, pfState policyfilter.State) *TestSensorManager {
var mgr *sensors.Manager
var err error

Expand Down

0 comments on commit fdbff84

Please sign in to comment.