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

Function TestMapInMap

map_test.go:784–828  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

782}
783
784func TestMapInMap(t *testing.T) {
785 for _, typ := range []MapType{ArrayOfMaps, HashOfMaps} {
786 t.Run(typ.String(), func(t *testing.T) {
787 inner := createMap(t, Array, 2)
788 if err := inner.Put(uint32(1), uint32(4242)); err != nil {
789 t.Fatal(err)
790 }
791
792 outer := createMapInMap(t, typ, Array)
793 if err := outer.Put(uint32(0), inner); err != nil {
794 t.Fatal("Can't put inner map:", err)
795 }
796
797 if err := outer.Put(uint32(0), (*Map)(nil)); err == nil {
798 t.Fatal("Put accepted a nil Map")
799 }
800
801 var inner2 *Map
802 if err := outer.Lookup(uint32(0), &inner2); err != nil {
803 t.Fatal("Can't lookup 0:", err)
804 }
805 defer inner2.Close()
806
807 var v uint32
808 if err := inner2.Lookup(uint32(1), &v); err != nil {
809 t.Fatal("Can't lookup 1 in inner2:", err)
810 }
811
812 if v != 4242 {
813 t.Error("Expected value 4242, got", v)
814 }
815
816 inner2.Close()
817
818 // Make sure we can still access the original map
819 if err := inner.Lookup(uint32(1), &v); err != nil {
820 t.Fatal("Can't lookup 1 in inner:", err)
821 }
822
823 if v != 4242 {
824 t.Error("Expected value 4242, got", v)
825 }
826 })
827 }
828}
829
830func TestNewMapInMapFromFD(t *testing.T) {
831 nested := createMapInMap(t, ArrayOfMaps, Array)

Callers

nothing calls this directly

Calls 8

LookupMethod · 0.95
CloseMethod · 0.95
createMapInMapFunction · 0.85
PutMethod · 0.80
createMapFunction · 0.70
RunMethod · 0.65
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…