Skip to content

Commit

Permalink
cilium#2972: Run test
Browse files Browse the repository at this point in the history
Signed-off-by: Trung-DV <[email protected]>
  • Loading branch information
Trung-DV committed Nov 13, 2024
1 parent b082183 commit e8c7fd1
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/vmtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- 'docs/**'
push:
branches:
- main
- '**'
paths-ignore:
- 'docs/**'

Expand Down
2 changes: 1 addition & 1 deletion pkg/eventcheckertests/yaml/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package yaml_test

import (
"bytes"
fmt "fmt"
"fmt"
"os"
"path/filepath"
"runtime"
Expand Down
16 changes: 5 additions & 11 deletions pkg/policyfilter/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ func (ts *testState) containersCgroupIDs(t *testing.T, podContainerMap map[strin
return ret
}

func TestNamespacePods(t *testing.T, st *state, ts *testState) {
t.Skip()
func testNamespacePods(t *testing.T, st *state, ts *testState) {
err := st.AddPolicy(PolicyID(1), "ns1", nil, nil)
require.NoError(t, err)
err = st.AddPolicy(PolicyID(2), "ns2", nil, nil)
Expand Down Expand Up @@ -398,8 +397,7 @@ func TestNamespacePods(t *testing.T, st *state, ts *testState) {
)
}

func TestPodLabelFilters(t *testing.T, st *state, ts *testState) {
t.Skip()
func testPodLabelFilters(t *testing.T, st *state, ts *testState) {
// create policies
matchesAllID := uint32(1)
matchesWebID := uint32(2)
Expand Down Expand Up @@ -489,8 +487,7 @@ func TestPodLabelFilters(t *testing.T, st *state, ts *testState) {
)
}

func TestContainerFieldFilters(t *testing.T, st *state, ts *testState) {
t.Skip()
func testContainerFieldFilters(t *testing.T, st *state, ts *testState) {
// create policies
matchesAllContainers := uint32(1)
matchesWebContainers := uint32(2)
Expand Down Expand Up @@ -618,8 +615,7 @@ func TestContainerFieldFilters(t *testing.T, st *state, ts *testState) {
)
}

func TestPreExistingPods(t *testing.T, st *state, ts *testState) {
t.Skip()
func testPreExistingPods(t *testing.T, st *state, ts *testState) {
// create pods
ts.createPod(t, "web", "default", labels.Labels{"app": "web"}, "web-c1", "web-c2")
ts.createPod(t, "db", "default", labels.Labels{"app": "db"}, "db-c1")
Expand Down Expand Up @@ -653,8 +649,7 @@ func TestPreExistingPods(t *testing.T, st *state, ts *testState) {
)
}

func TestContainersChange(t *testing.T, st *state, ts *testState) {
t.Skip()
func testContainersChange(t *testing.T, st *state, ts *testState) {
ts.createPod(t, "web", "default", nil, "web-c1", "web-c2")
ts.createPod(t, "db", "default", nil, "db-c1")
ts.createPod(t, "log", "default", nil, "log-c1")
Expand Down Expand Up @@ -706,7 +701,6 @@ func TestContainersChange(t *testing.T, st *state, ts *testState) {

// example taken from https://github.com/kubernetes/client-go/blob/04ef61f72b7bc5ae6efef4e4dc0001746637fdb3/examples/fake-client/main_test.go
func TestK8s(t *testing.T) {
t.Skip()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down
27 changes: 11 additions & 16 deletions pkg/sensors/exec/cgroups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,10 +804,9 @@ func TestCgroupEventMkdirRmdir(t *testing.T) {
assert.Error(t, err)
}

func TestCgroupv2HierarchyInHybrid(ctx context.Context, t *testing.T,
t.Skip()
cgroupRoot string, cgroupHierarchy []cgroupHierarchy, trackingCgrpLevel uint32,
triggers []func () ) {
func testCgroupv2HierarchyInHybrid(ctx context.Context, t *testing.T,
cgroupRoot string, cgroupHierarchy []cgroupHierarchy, trackingCgrpLevel uint32,
triggers []func()) {

t.Logf("Test %s running in %s", t.Name(), cgroups.CgroupModeCode(cgroups.CGROUP_HYBRID).String())
unifiedCgroup := "unified" // in Hybrid setup the unified cgroup is the cgroupv2 instance
Expand All @@ -830,10 +829,9 @@ triggers []func () ) {
}
}

func TestCgroupv1HierarchyInHybrid(ctx context.Context, t *testing.T,
t.Skip()
cgroupRoot string, usedController string, cgroupHierarchiesMap map[string][]cgroupHierarchy, trackingCgrpLevel uint32,
triggers []func () ) {
func testCgroupv1HierarchyInHybrid(ctx context.Context, t *testing.T,
cgroupRoot string, usedController string, cgroupHierarchiesMap map[string][]cgroupHierarchy, trackingCgrpLevel uint32,
triggers []func()) {

t.Logf("Test %s running in %s", t.Name(), cgroups.CgroupModeCode(cgroups.CGROUP_HYBRID).String())

Expand All @@ -859,10 +857,9 @@ triggers []func () ) {
}

// Test Cgroupv2 tries to emulate k8s hierarchy without exec context
func TestCgroupv2HierarchyInUnified(ctx context.Context, t *testing.T,
t.Skip()
cgroupRoot string, cgroupHierarchy []cgroupHierarchy, trackingCgrpLevel uint32,
triggers []func () ) {
func testCgroupv2HierarchyInUnified(ctx context.Context, t *testing.T,
cgroupRoot string, cgroupHierarchy []cgroupHierarchy, trackingCgrpLevel uint32,
triggers []func()) {

t.Logf("Test %s running in %s", t.Name(), cgroups.CgroupModeCode(cgroups.CGROUP_UNIFIED).String())
t.Logf("Test %s cgroup mount point: %s -> %s", t.Name(), cgroups.GetCgroupFSPath(), cgroupRoot)
Expand All @@ -886,8 +883,7 @@ triggers []func () ) {

// 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) {
t.Skip()
func testCgroupv2K8sHierarchy(ctx context.Context, t *testing.T, mode cgroups.CgroupModeCode, withExec bool) {
testManager := setupObserver(t)

testManager.AddAndEnableSensors(ctx, t, getLoadedSensors())
Expand Down Expand Up @@ -1094,8 +1090,7 @@ func TestCgroupv2K8sHierarchyInHybrid(t *testing.T) {
testCgroupv2K8sHierarchy(ctx, t, cgroups.CGROUP_HYBRID, false)
}

func TestCgroupv1K8sHierarchyInHybrid(t *testing.T, withExec bool, selectedController string) {
t.Skip()
func testCgroupv1K8sHierarchyInHybrid(t *testing.T, withExec bool, selectedController string) {
testutils.CaptureLog(t, logger.GetLogger().(*logrus.Logger))
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
defer cancel()
Expand Down
57 changes: 27 additions & 30 deletions pkg/sensors/tracing/enforcer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,37 +57,36 @@ func newCmdChecker(cmd string, checkFn func(t *testing.T, err error, rc int)) cm
}
}

func TestEnforcer(t *testing.T, configHook string,
t.Skip()
checker *eventchecker.UnorderedEventChecker,
cmds ...cmdChecker) {
func testEnforcer(t *testing.T, configHook string,
checker *eventchecker.UnorderedEventChecker,
cmds ...cmdChecker) {

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

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

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

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()
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()

for _, cc := range cmds {
cmd := exec.Command(cc.cmd)
err = cmd.Run()
cc.checkFn(t, err, cmd.ProcessState.ExitCode())
}
for _, cc := range cmds {
cmd := exec.Command(cc.cmd)
err = cmd.Run()
cc.checkFn(t, err, cmd.ProcessState.ExitCode())
}

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

func TestEnforcerOverride(t *testing.T) {
Expand Down Expand Up @@ -233,7 +232,7 @@ func TestEnforcerSignal(t *testing.T) {
WithSyscallList("sys_prctl").
WithMatchBinaries(test).
WithOverrideValue(-17). // EEXIST
WithKill(9) // SigKill
WithKill(9) // SigKill
}

t.Run("multi kprobe", func(t *testing.T) {
Expand Down Expand Up @@ -266,8 +265,7 @@ func TestEnforcerMultiNotSupported(t *testing.T) {
assert.Error(t, err)
}

func TestSecurity(t *testing.T, tracingPolicy, tempFile string) {
t.Skip()
func testSecurity(t *testing.T, tracingPolicy, tempFile string) {
var doneWG, readyWG sync.WaitGroup
defer doneWG.Wait()

Expand Down Expand Up @@ -716,8 +714,7 @@ spec:
}
}

func TestEnforcerPersistent(t *testing.T, builder func() *EnforcerSpecBuilder, expected, test string) {
t.Skip()
func testEnforcerPersistent(t *testing.T, builder func() *EnforcerSpecBuilder, expected, test string) {
testEnforcerCheckSkip(t)

if !bpf.HasLinkPin() {
Expand Down
Loading

0 comments on commit e8c7fd1

Please sign in to comment.