Skip to content

Commit 7bc44e8

Browse files
committed
testing: fix to skip sturct_ops test when bpf_testmod_ops is not loaded
Signed-off-by: shun159 <[email protected]>
1 parent 06c08a4 commit 7bc44e8

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

collection_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,19 @@ func TestStructOpsMapSpecSimpleLoadAndAssign(t *testing.T) {
809809
},
810810
}
811811

812+
s, err := btf.LoadKernelSpec()
813+
if err != nil {
814+
t.Fatal(err)
815+
}
816+
817+
_, _, _, err = doFindStructTypeByName(s, "bpf_testmod_ops")
818+
if errors.Is(err, btf.ErrNotFound) {
819+
t.Skip("bpf_testmod_ops not loaded")
820+
}
821+
if err != nil {
822+
t.Fatal(err)
823+
}
824+
812825
coll := mustNewCollection(t, spec, nil)
813826
for name := range spec.Maps {
814827
qt.Assert(t, qt.IsNotNil(coll.Maps[name]))

struct_ops_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ebpf
22

33
import (
4+
"errors"
45
"testing"
56

67
"github.com/cilium/ebpf/btf"
@@ -31,6 +32,19 @@ func TestCreateStructOpsMapSpecSimple(t *testing.T) {
3132
},
3233
}
3334

35+
s, err := btf.LoadKernelSpec()
36+
if err != nil {
37+
t.Fatal(err)
38+
}
39+
40+
_, _, _, err = doFindStructTypeByName(s, "bpf_testmod_ops")
41+
if errors.Is(err, btf.ErrNotFound) {
42+
t.Skip("bpf_testmod_ops not loaded")
43+
}
44+
if err != nil {
45+
t.Fatal(err)
46+
}
47+
3448
m, err := NewMap(ms)
3549
testutils.SkipIfNotSupported(t, err)
3650
if err != nil {

0 commit comments

Comments
 (0)