Skip to content

Commit b92b6fa

Browse files
FedeDPpoiana
authored andcommitted
new(pkg,tests): port falco driver loader tests to use falcoctl.
Signed-off-by: Federico Di Pierro <[email protected]>
1 parent 3e2d5e2 commit b92b6fa

File tree

5 files changed

+34
-201
lines changed

5 files changed

+34
-201
lines changed

pkg/falcodriverloader/tester.go

Lines changed: 0 additions & 91 deletions
This file was deleted.

pkg/falcodriverloader/tester_options.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

pkg/falcodriverloader/tester_output.go

Lines changed: 0 additions & 62 deletions
This file was deleted.

tests/falcodriverloader/drivers_test.go

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ limitations under the License.
1919
package testfalcodriverloader
2020

2121
import (
22+
"github.com/falcosecurity/testing/pkg/falcoctl"
2223
"testing"
2324
"time"
2425

2526
"github.com/falcosecurity/testing/pkg/falco"
26-
"github.com/falcosecurity/testing/pkg/falcodriverloader"
2727
"github.com/falcosecurity/testing/tests"
2828
"github.com/stretchr/testify/assert"
2929
)
@@ -40,20 +40,29 @@ import (
4040
//
4141
// We need to use the `--compile` flag because we test against dev versions
4242
func TestFalcoLegacyBPF(t *testing.T) {
43-
loaderRes := falcodriverloader.Test(
44-
tests.NewFalcoDriverLoaderExecutableRunner(t),
45-
falcodriverloader.WithArgs("bpf", "--compile"),
43+
// First, configure falcoctl driver
44+
configRes := falcoctl.Test(
45+
tests.NewFalcoctlExecutableRunner(t),
46+
falcoctl.WithArgs("driver", "config", "--type", "ebpf"),
47+
)
48+
assert.NoError(t, configRes.Err(), "%s", configRes.Stderr())
49+
assert.Equal(t, 0, configRes.ExitCode())
50+
51+
loaderRes := falcoctl.Test(
52+
tests.NewFalcoctlExecutableRunner(t),
53+
falcoctl.WithArgs("driver", "install", "--download=false"),
4654
)
4755
assert.NoError(t, loaderRes.Err(), "%s", loaderRes.Stderr())
4856
assert.Equal(t, 0, loaderRes.ExitCode())
49-
// We expect the probe to be symlinked in '/root/.falco/falco-bpf.o'
50-
assert.Regexp(t, `Success: eBPF probe symlinked`, loaderRes.Stdout())
57+
// We expect the probe to be succesfully built and copied to /root/.falco/falco-bpf.o
58+
assert.Regexp(t, `Probe successfully built.`, loaderRes.Stdout())
5159

5260
// Now running Falco with `FALCO_BPF_PROBE=/root/.falco/falco-bpf.o` we should be able to run the bpf driver
5361
falcoRes := falco.Test(
5462
tests.NewFalcoExecutableRunner(t),
5563
falco.WithStopAfter(3*time.Second),
56-
falco.WithEnvVars(map[string]string{"FALCO_BPF_PROBE": "/root/.falco/falco-bpf.o"}),
64+
falco.WithArgs("-o", "engine.kind=ebpf"),
65+
falco.WithArgs("-o", "engine.ebpf.probe=/root/.falco/falco-bpf.o"),
5766
)
5867
assert.NoError(t, falcoRes.Err(), "%s", falcoRes.Stderr())
5968
assert.Equal(t, 0, falcoRes.ExitCode())
@@ -75,19 +84,28 @@ func TestFalcoLegacyBPF(t *testing.T) {
7584
//
7685
// We need to use the `--compile` flag because we test against dev versions
7786
func TestFalcoKmod(t *testing.T) {
78-
loaderRes := falcodriverloader.Test(
79-
tests.NewFalcoDriverLoaderExecutableRunner(t),
80-
falcodriverloader.WithArgs("module", "--compile"),
87+
// First, configure falcoctl driver
88+
configRes := falcoctl.Test(
89+
tests.NewFalcoctlExecutableRunner(t),
90+
falcoctl.WithArgs("driver", "config", "--type", "kmod"),
91+
)
92+
assert.NoError(t, configRes.Err(), "%s", configRes.Stderr())
93+
assert.Equal(t, 0, configRes.ExitCode())
94+
95+
loaderRes := falcoctl.Test(
96+
tests.NewFalcoctlExecutableRunner(t),
97+
falcoctl.WithArgs("driver", "install", "--download=false"),
8198
)
8299
assert.NoError(t, loaderRes.Err(), "%s", loaderRes.Stderr())
83100
assert.Equal(t, 0, loaderRes.ExitCode())
84101
// We expect the module to be loaded in dkms
85-
assert.Regexp(t, `Success: falco module found and loaded in dkms`, loaderRes.Stdout())
102+
assert.Regexp(t, `Module installed in dkms.`, loaderRes.Stdout())
86103

87104
// Now running Falco we should be able to run the kernel module
88105
falcoRes := falco.Test(
89106
tests.NewFalcoExecutableRunner(t),
90107
falco.WithStopAfter(3*time.Second),
108+
falco.WithArgs("-o", "engine.kind=kmod"),
91109
)
92110
assert.NoError(t, falcoRes.Err(), "%s", falcoRes.Stderr())
93111
assert.Equal(t, 0, falcoRes.ExitCode())

tests/tests.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,21 @@ import (
2626

2727
"github.com/falcosecurity/testing/pkg/falco"
2828
"github.com/falcosecurity/testing/pkg/falcoctl"
29-
"github.com/falcosecurity/testing/pkg/falcodriverloader"
3029
"github.com/falcosecurity/testing/pkg/run"
3130
"github.com/sirupsen/logrus"
3231
"github.com/stretchr/testify/require"
3332
)
3433

35-
var falcoStatic = false
36-
var falcoBinary = falco.DefaultExecutable
37-
var falcoctlBinary = falcoctl.DefaultLocalExecutable
38-
var falcoDriverLoaderBinary = falcodriverloader.DefaultExecutable
34+
var (
35+
falcoStatic = false
36+
falcoBinary = falco.DefaultExecutable
37+
falcoctlBinary = falcoctl.DefaultLocalExecutable
38+
)
3939

4040
func init() {
4141
flag.BoolVar(&falcoStatic, "falco-static", falcoStatic, "True if the Falco executable is from a static build")
4242
flag.StringVar(&falcoBinary, "falco-binary", falcoBinary, "Falco executable binary path")
4343
flag.StringVar(&falcoctlBinary, "falcoctl-binary", falcoctlBinary, "falcoctl executable binary path")
44-
flag.StringVar(&falcoDriverLoaderBinary, "falco-driver-loader-binary", falcoDriverLoaderBinary, "falco-driver-loader executable binary path")
4544

4645
logrus.SetLevel(logrus.DebugLevel)
4746
logrus.SetFormatter(&logrus.JSONFormatter{})
@@ -54,13 +53,6 @@ func NewFalcoExecutableRunner(t *testing.T) run.Runner {
5453
return runner
5554
}
5655

57-
// NewFalcoExecutableRunner returns an executable runner for falco-driver-loader.
58-
func NewFalcoDriverLoaderExecutableRunner(t *testing.T) run.Runner {
59-
runner, err := run.NewExecutableRunner(falcoDriverLoaderBinary)
60-
require.Nil(t, err)
61-
return runner
62-
}
63-
6456
// NewFalcoctlExecutableRunner returns an executable runner for falcoctl.
6557
func NewFalcoctlExecutableRunner(t *testing.T) run.Runner {
6658
if _, err := os.Stat(falcoctlBinary); err == nil {

0 commit comments

Comments
 (0)