MCPcopy
hub / github.com/cilium/ebpf / TestCollectionSpecNotModified

Function TestCollectionSpecNotModified

collection_test.go:26–69  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24}
25
26func TestCollectionSpecNotModified(t *testing.T) {
27 spec := &CollectionSpec{
28 Maps: map[string]*MapSpec{
29 "my-map": {
30 Type: Array,
31 KeySize: 4,
32 ValueSize: 4,
33 MaxEntries: 1,
34 },
35 ".rodata": {
36 Type: Array,
37 KeySize: 4,
38 ValueSize: 4,
39 MaxEntries: 1,
40 Flags: 0, // Loader sets BPF_F_MMAPABLE.
41 Contents: []MapKV{{uint32(0), uint32(1)}},
42 },
43 },
44 Programs: map[string]*ProgramSpec{
45 "test": {
46 Type: SocketFilter,
47 Instructions: asm.Instructions{
48 asm.LoadImm(asm.R1, 0, asm.DWord).WithReference(".rodata"),
49 asm.LoadImm(asm.R1, 0, asm.DWord).WithReference("my-map"),
50 asm.LoadImm(asm.R0, 0, asm.DWord),
51 asm.Return(),
52 },
53 License: "MIT",
54 },
55 },
56 }
57
58 orig := spec.Copy()
59 coll := mustNewCollection(t, spec, nil)
60 qt.Assert(t, qt.CmpEquals(orig, spec, csCmpOpts))
61
62 for name := range spec.Maps {
63 qt.Assert(t, qt.IsNotNil(coll.Maps[name]))
64 }
65
66 for name := range spec.Programs {
67 qt.Assert(t, qt.IsNotNil(coll.Programs[name]))
68 }
69}
70
71func TestCollectionSpecCopy(t *testing.T) {
72 ms := &MapSpec{

Callers

nothing calls this directly

Calls 5

CopyMethod · 0.95
LoadImmFunction · 0.92
ReturnFunction · 0.92
mustNewCollectionFunction · 0.85
WithReferenceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…