Skip to content

Commit d0f70d2

Browse files
committed
testing: remove struct_ops dummy helpers
Signed-off-by: shun159 <[email protected]>
1 parent 93366b1 commit d0f70d2

File tree

3 files changed

+13
-45
lines changed

3 files changed

+13
-45
lines changed

collection_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -771,12 +771,12 @@ func ExampleCollectionSpec_LoadAndAssign() {
771771
}
772772

773773
func TestStructOpsMapSpecSimpleLoadAndAssign(t *testing.T) {
774-
requireStructOpsDummy(t)
774+
requireTestmod(t)
775775

776776
spec := &CollectionSpec{
777777
Programs: map[string]*ProgramSpec{
778-
"dummy_test_1": {
779-
Name: "dummy_test_1",
778+
"test_func_1": {
779+
Name: "test_func_1",
780780
Type: StructOps,
781781
License: "GPL",
782782
Instructions: asm.Instructions{
@@ -786,9 +786,8 @@ func TestStructOpsMapSpecSimpleLoadAndAssign(t *testing.T) {
786786
},
787787
},
788788
Maps: map[string]*MapSpec{
789-
// TODO: we should use "bpf_testmod_ops" for this case (tentative test case)
790-
"dummy_ops": {
791-
Name: "dummy_ops",
789+
"testmod_ops": {
790+
Name: "testmod_ops",
792791
Type: StructOpsMap,
793792
Flags: sys.BPF_F_LINK,
794793
KeySize: 4,
@@ -799,7 +798,7 @@ func TestStructOpsMapSpecSimpleLoadAndAssign(t *testing.T) {
799798
{Key: uint32(0), Value: structOpsMeta{
800799
data: make([]byte, 448),
801800
funcs: []structOpsFunc{
802-
{"test_1", "dummy_test_1"},
801+
{"test_1", "test_func_1"},
803802
},
804803
}},
805804
},
@@ -808,8 +807,8 @@ func TestStructOpsMapSpecSimpleLoadAndAssign(t *testing.T) {
808807
}
809808

810809
var obj struct {
811-
DummyTest1 *Program `ebpf:"dummy_test_1"`
812-
DummyOps *Map `ebpf:"dummy_ops"`
810+
DummyTest1 *Program `ebpf:"test_func_1"`
811+
DummyOps *Map `ebpf:"testmod_ops"`
813812
}
814813

815814
err := spec.LoadAndAssign(&obj, nil)

helpers_test.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,36 +44,6 @@ func requireTestmod(tb testing.TB) {
4444
}
4545
}
4646

47-
var haveStructOpsDummy = sync.OnceValues(func() (bool, error) {
48-
if platform.IsWindows {
49-
return false, nil
50-
}
51-
kspec, err := btf.LoadKernelSpec()
52-
if err != nil {
53-
return false, nil
54-
}
55-
_, err = kspec.AnyTypeByName("bpf_struct_ops_bpf_dummy_ops")
56-
if err == nil {
57-
return true, nil
58-
}
59-
if errors.Is(err, btf.ErrNotFound) {
60-
return false, nil
61-
}
62-
return false, err
63-
})
64-
65-
func requireStructOpsDummy(tb testing.TB) {
66-
tb.Helper()
67-
68-
ok, err := haveStructOpsDummy()
69-
if err != nil {
70-
tb.Fatal(err)
71-
}
72-
if !ok {
73-
tb.Skip("struct_ops dummy_ops wrapper type not present in vmlinux BTF")
74-
}
75-
}
76-
7747
func newMap(tb testing.TB, spec *MapSpec, opts *MapOptions) (*Map, error) {
7848
tb.Helper()
7949

struct_ops_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,22 @@ import (
99
)
1010

1111
func TestCreateStructOpsMapSpecSimple(t *testing.T) {
12-
requireStructOpsDummy(t)
12+
requireTestmod(t)
1313

14-
// TODO: we should use "bpf_testmod_ops" for this case (tentative test case)
1514
ms := &MapSpec{
16-
Name: "dummy_ops",
15+
Name: "testmod_ops",
1716
Type: StructOpsMap,
1817
Flags: sys.BPF_F_LINK,
1918
KeySize: 4,
20-
ValueSize: 128,
19+
ValueSize: 448,
2120
MaxEntries: 1,
2221
// we use `Value` to specify a user struct type as BTF
23-
Value: &btf.Struct{Name: "bpf_dummy_ops"},
22+
Value: &btf.Struct{Name: "bpf_testmod_ops"},
2423
Contents: []MapKV{
2524
{
2625
Key: uint32(0),
2726
Value: structOpsMeta{
28-
data: make([]byte, 128),
27+
data: make([]byte, 448),
2928
funcs: []structOpsFunc{},
3029
},
3130
},

0 commit comments

Comments
 (0)