Skip to content

Commit 2fba3a5

Browse files
committed
testing: remove struct_ops dummy helpers
Signed-off-by: shun159 <[email protected]>
1 parent 8abfdba commit 2fba3a5

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
@@ -774,12 +774,12 @@ func ExampleCollectionSpec_LoadAndAssign() {
774774
}
775775

776776
func TestStructOpsMapSpecSimpleLoadAndAssign(t *testing.T) {
777-
requireStructOpsDummy(t)
777+
requireTestmod(t)
778778

779779
spec := &CollectionSpec{
780780
Programs: map[string]*ProgramSpec{
781-
"dummy_test_1": {
782-
Name: "dummy_test_1",
781+
"test_func_1": {
782+
Name: "test_func_1",
783783
Type: StructOps,
784784
License: "GPL",
785785
Instructions: asm.Instructions{
@@ -789,9 +789,8 @@ func TestStructOpsMapSpecSimpleLoadAndAssign(t *testing.T) {
789789
},
790790
},
791791
Maps: map[string]*MapSpec{
792-
// TODO: we should use "bpf_testmod_ops" for this case (tentative test case)
793-
"dummy_ops": {
794-
Name: "dummy_ops",
792+
"testmod_ops": {
793+
Name: "testmod_ops",
795794
Type: StructOpsMap,
796795
Flags: sys.BPF_F_LINK,
797796
KeySize: 4,
@@ -802,7 +801,7 @@ func TestStructOpsMapSpecSimpleLoadAndAssign(t *testing.T) {
802801
{Key: uint32(0), Value: structOpsMeta{
803802
data: make([]byte, 448),
804803
funcs: []structOpsFunc{
805-
{"test_1", "dummy_test_1"},
804+
{"test_1", "test_func_1"},
806805
},
807806
}},
808807
},
@@ -811,8 +810,8 @@ func TestStructOpsMapSpecSimpleLoadAndAssign(t *testing.T) {
811810
}
812811

813812
var obj struct {
814-
DummyTest1 *Program `ebpf:"dummy_test_1"`
815-
DummyOps *Map `ebpf:"dummy_ops"`
813+
DummyTest1 *Program `ebpf:"test_func_1"`
814+
DummyOps *Map `ebpf:"testmod_ops"`
816815
}
817816

818817
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)