Skip to content

Commit

Permalink
internal/kallsyms: 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 committed Jan 21, 2025
1 parent 25f028f commit abb8387
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions internal/kallsyms/kallsyms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package kallsyms

import (
"bytes"
"errors"
"os"
"runtime"
"testing"

"github.com/go-quicktest/qt"
Expand Down Expand Up @@ -38,6 +40,9 @@ func TestParseSyms(t *testing.T) {

func TestParseProcKallsyms(t *testing.T) {
f, err := os.Open("/proc/kallsyms")
if runtime.GOOS != "linux" && errors.Is(err, os.ErrNotExist) {
t.Skip("/proc/kallsyms doesn't exist")
}
qt.Assert(t, qt.IsNil(err))
defer f.Close()

Expand All @@ -53,12 +58,16 @@ func TestParseProcKallsyms(t *testing.T) {
}

func TestAssignModulesCaching(t *testing.T) {
qt.Assert(t, qt.IsNil(AssignModules(
err := AssignModules(
map[string]string{
"bpf_perf_event_output": "",
"foo": "",
},
)))
)
if runtime.GOOS != "linux" && errors.Is(err, os.ErrNotExist) {
t.Skip("File doesn't exist:", err)
}
qt.Assert(t, qt.IsNil(err))

// Can't assume any kernel modules are loaded, but this symbol should at least
// exist in the kernel. There is no semantic difference between a missing
Expand Down Expand Up @@ -92,12 +101,16 @@ func TestAssignModules(t *testing.T) {
}

func TestAssignAddressesCaching(t *testing.T) {
qt.Assert(t, qt.IsNil(AssignAddresses(
err := AssignAddresses(
map[string]uint64{
"bpf_perf_event_output": 0,
"foo": 0,
},
)))
)
if runtime.GOOS != "linux" && errors.Is(err, os.ErrNotExist) {
t.Skip("File doesn't exist:", err)
}
qt.Assert(t, qt.IsNil(err))

v, ok := symAddrs.Load("bpf_perf_event_output")
qt.Assert(t, qt.IsTrue(ok))
Expand Down

0 comments on commit abb8387

Please sign in to comment.