File: types_test.go

package info (click to toggle)
golang-github-cilium-ebpf 0.17.3%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,684 kB
  • sloc: ansic: 1,259; makefile: 127; python: 113; awk: 29; sh: 24
file content (43 lines) | stat: -rw-r--r-- 1,033 bytes parent folder | download
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
//go:build !windows

package gen

import (
	"testing"

	"github.com/cilium/ebpf"
	"github.com/cilium/ebpf/btf"
	"github.com/cilium/ebpf/internal/testutils"

	"github.com/go-quicktest/qt"
	"github.com/google/go-cmp/cmp"
)

func mustAnyTypeByName(t *testing.T, spec *ebpf.CollectionSpec, name string) btf.Type {
	t.Helper()

	typ, err := spec.Types.AnyTypeByName(name)
	qt.Assert(t, qt.IsNil(err))
	return typ
}

func TestCollectGlobalTypes(t *testing.T) {
	spec, err := ebpf.LoadCollectionSpec(testutils.NativeFile(t, "../testdata/minimal-%s.elf"))
	if err != nil {
		t.Fatal(err)
	}

	bar := mustAnyTypeByName(t, spec, "bar")
	barfoo := mustAnyTypeByName(t, spec, "barfoo")
	baz := mustAnyTypeByName(t, spec, "baz")
	e := mustAnyTypeByName(t, spec, "e")
	ubar := mustAnyTypeByName(t, spec, "ubar")

	got := CollectGlobalTypes(spec)
	qt.Assert(t, qt.IsNil(err))

	want := []btf.Type{bar, barfoo, baz, e, ubar}
	qt.Assert(t, qt.CmpEquals(got, want, cmp.Comparer(func(a, b btf.Type) bool {
		return a.TypeName() == b.TypeName()
	})))
}