| 1 |
|
| 2 |
|
| 3 |
package gen |
| 4 |
|
| 5 |
import ( |
| 6 |
"testing" |
| 7 |
|
| 8 |
"github.com/cilium/ebpf" |
| 9 |
"github.com/cilium/ebpf/btf" |
| 10 |
"github.com/cilium/ebpf/internal/testutils" |
| 11 |
|
| 12 |
"github.com/go-quicktest/qt" |
| 13 |
"github.com/google/go-cmp/cmp" |
| 14 |
) |
| 15 |
|
| 16 |
func mustAnyTypeByName(t *testing.T, spec *ebpf.CollectionSpec, name string) btf.Type { |
| 17 |
t.Helper() |
| 18 |
|
| 19 |
typ, err := spec.Types.AnyTypeByName(name) |
| 20 |
qt.Assert(t, qt.IsNil(err)) |
| 21 |
return typ |
| 22 |
} |
| 23 |
|
| 24 |
func TestCollectGlobalTypes(t *testing.T) { |
| 25 |
spec, err := ebpf.LoadCollectionSpec(testutils.NativeFile(t, "../testdata/minimal-%s.elf")) |
| 26 |
if err != nil { |
| 27 |
t.Fatal(err) |
| 28 |
} |
| 29 |
|
| 30 |
bar := mustAnyTypeByName(t, spec, "bar") |
| 31 |
barfoo := mustAnyTypeByName(t, spec, "barfoo") |
| 32 |
baz := mustAnyTypeByName(t, spec, "baz") |
| 33 |
e := mustAnyTypeByName(t, spec, "e") |
| 34 |
ubar := mustAnyTypeByName(t, spec, "ubar") |
| 35 |
|
| 36 |
got := CollectGlobalTypes(spec) |
| 37 |
qt.Assert(t, qt.IsNil(err)) |
| 38 |
|
| 39 |
want := []btf.Type{bar, barfoo, baz, e, ubar} |
| 40 |
qt.Assert(t, qt.CmpEquals(got, want, cmp.Comparer(func(a, b btf.Type) bool { |
| 41 |
return a.TypeName() == b.TypeName() |
| 42 |
}))) |
| 43 |
} |