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

Function TestCollectionSpecMapReplacements

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

Source from the content-addressed store, hash-verified

126}
127
128func TestCollectionSpecMapReplacements(t *testing.T) {
129 cs := &CollectionSpec{
130 Maps: map[string]*MapSpec{
131 "test-map": {
132 Type: Array,
133 KeySize: 4,
134 ValueSize: 4,
135 MaxEntries: 1,
136 },
137 },
138 Programs: map[string]*ProgramSpec{
139 "test-prog": loadKeyFromMapProgramSpec.Copy(),
140 },
141 }
142
143 // Replace the map with another one
144 newMap := mustNewMap(t, cs.Maps["test-map"], nil)
145
146 err := newMap.Put(uint32(0), uint32(2))
147 if err != nil {
148 t.Fatal(err)
149 }
150
151 coll := mustNewCollection(t, cs, &CollectionOptions{
152 MapReplacements: map[string]*Map{
153 "test-map": newMap,
154 },
155 })
156
157 ret := mustRun(t, coll.Programs["test-prog"], nil)
158
159 if ret != 2 {
160 t.Fatal("new / override map not used")
161 }
162
163 // Check that newMap isn't closed when the collection is closed
164 coll.Close()
165 err = newMap.Put(uint32(0), uint32(3))
166 if err != nil {
167 t.Fatalf("failed to update replaced map: %s", err)
168 }
169}
170
171func TestCollectionSpecMapReplacements_NonExistingMap(t *testing.T) {
172 cs := &CollectionSpec{

Callers

nothing calls this directly

Calls 6

mustNewMapFunction · 0.85
mustNewCollectionFunction · 0.85
PutMethod · 0.80
mustRunFunction · 0.70
CloseMethod · 0.65
CopyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…