-
Notifications
You must be signed in to change notification settings - Fork 737
/
Copy pathworkarounds_test.go
81 lines (69 loc) · 1.46 KB
/
workarounds_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package btf
import (
"errors"
"fmt"
"testing"
"github.com/cilium/ebpf/internal"
"github.com/cilium/ebpf/internal/testutils"
"github.com/go-quicktest/qt"
)
func TestDatasecResolveWorkaround(t *testing.T) {
testutils.SkipOnOldKernel(t, "5.2", "BTF_KIND_DATASEC")
i := &Int{Size: 1}
for _, typ := range []Type{
&Typedef{"foo", i, nil},
&Volatile{i},
&Const{i},
&Restrict{i},
&TypeTag{i, "foo"},
} {
t.Run(fmt.Sprint(typ), func(t *testing.T) {
if _, ok := typ.(*TypeTag); ok {
testutils.SkipOnOldKernel(t, "5.17", "BTF_KIND_TYPE_TAG")
}
ds := &Datasec{
Name: "a",
Size: 2,
Vars: []VarSecinfo{
{
Size: 1,
Offset: 0,
// struct, union, pointer, array will trigger the bug.
Type: &Var{Name: "a", Type: &Pointer{i}},
},
{
Size: 1,
Offset: 1,
Type: &Var{
Name: "b",
Type: typ,
},
},
},
}
b, err := NewBuilder([]Type{ds})
if err != nil {
t.Fatal(err)
}
h, err := NewHandle(b)
testutils.SkipIfNotSupportedOnOS(t, err)
var ve *internal.VerifierError
if errors.As(err, &ve) {
t.Fatalf("%+v\n", ve)
}
if err != nil {
t.Fatal(err)
}
h.Close()
})
}
}
func TestEmptyBTFWithStringTableWorkaround(t *testing.T) {
var b Builder
_, err := b.addString("foo")
qt.Assert(t, qt.IsNil(err))
h, err := NewHandle(&b)
testutils.SkipIfNotSupported(t, err)
qt.Assert(t, qt.IsNil(err))
qt.Assert(t, qt.IsNil(h.Close()))
}