Skip to content

Commit

Permalink
internal/tracefs: skip some tests on non-Linux platforms
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
  • Loading branch information
lmb authored and ti-mo committed Jan 27, 2025
1 parent 55d4f2f commit ff8468e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/tracefs/kprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func sanitizeTracefsPath(path ...string) (string, error) {
// but may be also be available at /sys/kernel/debug/tracing if debugfs is mounted.
// The available tracefs paths will depends on distribution choices.
var getTracefsPath = sync.OnceValues(func() (string, error) {
if runtime.GOOS != "linux" {
return "", fmt.Errorf("tracefs: %w", internal.ErrNotSupportedOnOS)
}

for _, p := range []struct {
path string
fsType int64
Expand Down
3 changes: 3 additions & 0 deletions internal/tracefs/kprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"testing"

"github.com/go-quicktest/qt"

"github.com/cilium/ebpf/internal/testutils"
)

// Global symbol, present on all tested kernels.
Expand Down Expand Up @@ -63,6 +65,7 @@ func TestNewEvent(t *testing.T) {
args.Group, _ = RandomGroup("ebpftest")

evt, err := NewEvent(args)
testutils.SkipIfNotSupportedOnOS(t, err)
qt.Assert(t, qt.IsNil(err))
defer evt.Close()

Expand Down
11 changes: 9 additions & 2 deletions internal/tracefs/perf_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ package tracefs
import (
"errors"
"fmt"
"os"
"testing"

"github.com/go-quicktest/qt"

"github.com/cilium/ebpf/internal/testutils"
)

func TestEventID(t *testing.T) {

eid, err := EventID("syscalls", "sys_enter_mmap")
testutils.SkipIfNotSupportedOnOS(t, err)
qt.Assert(t, qt.IsNil(err))
qt.Assert(t, qt.Not(qt.Equals(eid, 0)))
}

func TestSanitizePath(t *testing.T) {
_, err := sanitizeTracefsPath("../escaped")
testutils.SkipIfNotSupportedOnOS(t, err)
if !errors.Is(err, ErrInvalidInput) {
t.Errorf("expected error %s, got: %s", ErrInvalidInput, err)
}
Expand Down Expand Up @@ -80,6 +84,9 @@ func TestSanitizeIdentifier(t *testing.T) {
}

func TestGetTracefsPath(t *testing.T) {
_, err := getTracefsPath()
path, err := getTracefsPath()
testutils.SkipIfNotSupportedOnOS(t, err)
qt.Assert(t, qt.IsNil(err))
_, err = os.Stat(path)
qt.Assert(t, qt.IsNil(err))
}

0 comments on commit ff8468e

Please sign in to comment.