-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip Signed-off-by: Jiri Olsa <jolsa@kernel.org>
- Loading branch information
Showing
1 changed file
with
125 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Tetragon | ||
|
||
package tracing | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/cilium/ebpf" | ||
"github.com/cilium/tetragon/pkg/observer/observertesthelper" | ||
"github.com/cilium/tetragon/pkg/sensors" | ||
tus "github.com/cilium/tetragon/pkg/testutils/sensors" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func runConfig(t *testing.T, config string, fn func(string, int)) { | ||
|
||
var err error | ||
err = os.WriteFile(testConfigFile, []byte(config), 0644) | ||
if err != nil { | ||
t.Fatalf("writeFile(%s): err %s", testConfigFile, err) | ||
} | ||
sens, err := observertesthelper.GetDefaultSensorsWithFile(t, testConfigFile, | ||
tus.Conf().TetragonLib) | ||
if err != nil { | ||
t.Fatalf("GetDefaultObserverWithFile error: %s", err) | ||
} | ||
|
||
for _, sensor := range sens { | ||
for _, load := range sensor.Progs { | ||
c := load.LC | ||
for _, p := range c.Programs { | ||
for _, id := range p.MapIDs { | ||
m, err := ebpf.NewMapFromID(id) | ||
if err != nil { | ||
t.Fatalf("can't open map id %d: %s\n", id, err) | ||
} | ||
info, err := m.Info() | ||
if err != nil { | ||
t.Fatalf("can't get map info: %s\n", err) | ||
} | ||
fn(info.Name, int(info.MaxEntries)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
sensi := make([]sensors.SensorIface, 0, len(sens)) | ||
for _, s := range sens { | ||
sensi = append(sensi, s) | ||
} | ||
sensors.UnloadSensors(sensi) | ||
} | ||
|
||
func TestMaxEntries(t *testing.T) { | ||
|
||
t.Run("fdinstall_1", func(t *testing.T) { | ||
config := ` | ||
apiVersion: cilium.io/v1alpha1 | ||
kind: TracingPolicy | ||
metadata: | ||
name: "sys-read" | ||
spec: | ||
kprobes: | ||
- call: "sys_read" | ||
syscall: true | ||
return: true | ||
args: | ||
- index: 0 | ||
type: "int" | ||
- index: 1 | ||
type: "char_buf" | ||
returnCopy: true | ||
- index: 2 | ||
type: "size_t" | ||
returnArg: | ||
type: "size_t" | ||
` | ||
|
||
runConfig(t, config, func(name string, entries int) { | ||
if name == "fdinstall_map" { | ||
assert.Equal(t, 1, entries) | ||
} | ||
}) | ||
}) | ||
|
||
t.Run("fdinstall_32000", func(t *testing.T) { | ||
config := ` | ||
apiVersion: cilium.io/v1alpha1 | ||
kind: TracingPolicy | ||
metadata: | ||
name: "syswritefollowfdpsswd" | ||
spec: | ||
kprobes: | ||
- call: "fd_install" | ||
syscall: false | ||
args: | ||
- index: 0 | ||
type: int | ||
- index: 1 | ||
type: "file" | ||
selectors: | ||
- matchArgs: | ||
- index: 1 | ||
operator: "Equal" | ||
values: | ||
- "/tmp/test" | ||
matchBinaries: | ||
- operator: "In" | ||
values: | ||
- "/usr/bin/vim" | ||
matchActions: | ||
- action: FollowFD | ||
argFd: 0 | ||
argName: 1 | ||
` | ||
|
||
runConfig(t, config, func(name string, entries int) { | ||
if name == "fdinstall_map" { | ||
assert.Equal(t, 32000, entries) | ||
} | ||
}) | ||
}) | ||
} |