Skip to content

Commit

Permalink
new(pkg,tests): port falco driver loader tests to use falcoctl.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP authored and poiana committed Dec 6, 2023
1 parent 3e2d5e2 commit b92b6fa
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 201 deletions.
91 changes: 0 additions & 91 deletions pkg/falcodriverloader/tester.go

This file was deleted.

24 changes: 0 additions & 24 deletions pkg/falcodriverloader/tester_options.go

This file was deleted.

62 changes: 0 additions & 62 deletions pkg/falcodriverloader/tester_output.go

This file was deleted.

40 changes: 29 additions & 11 deletions tests/falcodriverloader/drivers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ limitations under the License.
package testfalcodriverloader

import (
"github.com/falcosecurity/testing/pkg/falcoctl"
"testing"
"time"

"github.com/falcosecurity/testing/pkg/falco"
"github.com/falcosecurity/testing/pkg/falcodriverloader"
"github.com/falcosecurity/testing/tests"
"github.com/stretchr/testify/assert"
)
Expand All @@ -40,20 +40,29 @@ import (
//
// We need to use the `--compile` flag because we test against dev versions
func TestFalcoLegacyBPF(t *testing.T) {
loaderRes := falcodriverloader.Test(
tests.NewFalcoDriverLoaderExecutableRunner(t),
falcodriverloader.WithArgs("bpf", "--compile"),
// First, configure falcoctl driver
configRes := falcoctl.Test(
tests.NewFalcoctlExecutableRunner(t),
falcoctl.WithArgs("driver", "config", "--type", "ebpf"),
)
assert.NoError(t, configRes.Err(), "%s", configRes.Stderr())
assert.Equal(t, 0, configRes.ExitCode())

loaderRes := falcoctl.Test(
tests.NewFalcoctlExecutableRunner(t),
falcoctl.WithArgs("driver", "install", "--download=false"),
)
assert.NoError(t, loaderRes.Err(), "%s", loaderRes.Stderr())
assert.Equal(t, 0, loaderRes.ExitCode())
// We expect the probe to be symlinked in '/root/.falco/falco-bpf.o'
assert.Regexp(t, `Success: eBPF probe symlinked`, loaderRes.Stdout())
// We expect the probe to be succesfully built and copied to /root/.falco/falco-bpf.o
assert.Regexp(t, `Probe successfully built.`, loaderRes.Stdout())

// Now running Falco with `FALCO_BPF_PROBE=/root/.falco/falco-bpf.o` we should be able to run the bpf driver
falcoRes := falco.Test(
tests.NewFalcoExecutableRunner(t),
falco.WithStopAfter(3*time.Second),
falco.WithEnvVars(map[string]string{"FALCO_BPF_PROBE": "/root/.falco/falco-bpf.o"}),
falco.WithArgs("-o", "engine.kind=ebpf"),
falco.WithArgs("-o", "engine.ebpf.probe=/root/.falco/falco-bpf.o"),
)
assert.NoError(t, falcoRes.Err(), "%s", falcoRes.Stderr())
assert.Equal(t, 0, falcoRes.ExitCode())
Expand All @@ -75,19 +84,28 @@ func TestFalcoLegacyBPF(t *testing.T) {
//
// We need to use the `--compile` flag because we test against dev versions
func TestFalcoKmod(t *testing.T) {
loaderRes := falcodriverloader.Test(
tests.NewFalcoDriverLoaderExecutableRunner(t),
falcodriverloader.WithArgs("module", "--compile"),
// First, configure falcoctl driver
configRes := falcoctl.Test(
tests.NewFalcoctlExecutableRunner(t),
falcoctl.WithArgs("driver", "config", "--type", "kmod"),
)
assert.NoError(t, configRes.Err(), "%s", configRes.Stderr())
assert.Equal(t, 0, configRes.ExitCode())

loaderRes := falcoctl.Test(
tests.NewFalcoctlExecutableRunner(t),
falcoctl.WithArgs("driver", "install", "--download=false"),
)
assert.NoError(t, loaderRes.Err(), "%s", loaderRes.Stderr())
assert.Equal(t, 0, loaderRes.ExitCode())
// We expect the module to be loaded in dkms
assert.Regexp(t, `Success: falco module found and loaded in dkms`, loaderRes.Stdout())
assert.Regexp(t, `Module installed in dkms.`, loaderRes.Stdout())

// Now running Falco we should be able to run the kernel module
falcoRes := falco.Test(
tests.NewFalcoExecutableRunner(t),
falco.WithStopAfter(3*time.Second),
falco.WithArgs("-o", "engine.kind=kmod"),
)
assert.NoError(t, falcoRes.Err(), "%s", falcoRes.Stderr())
assert.Equal(t, 0, falcoRes.ExitCode())
Expand Down
18 changes: 5 additions & 13 deletions tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,21 @@ import (

"github.com/falcosecurity/testing/pkg/falco"
"github.com/falcosecurity/testing/pkg/falcoctl"
"github.com/falcosecurity/testing/pkg/falcodriverloader"
"github.com/falcosecurity/testing/pkg/run"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
)

var falcoStatic = false
var falcoBinary = falco.DefaultExecutable
var falcoctlBinary = falcoctl.DefaultLocalExecutable
var falcoDriverLoaderBinary = falcodriverloader.DefaultExecutable
var (
falcoStatic = false
falcoBinary = falco.DefaultExecutable
falcoctlBinary = falcoctl.DefaultLocalExecutable
)

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

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

// NewFalcoExecutableRunner returns an executable runner for falco-driver-loader.
func NewFalcoDriverLoaderExecutableRunner(t *testing.T) run.Runner {
runner, err := run.NewExecutableRunner(falcoDriverLoaderBinary)
require.Nil(t, err)
return runner
}

// NewFalcoctlExecutableRunner returns an executable runner for falcoctl.
func NewFalcoctlExecutableRunner(t *testing.T) run.Runner {
if _, err := os.Stat(falcoctlBinary); err == nil {
Expand Down

0 comments on commit b92b6fa

Please sign in to comment.