@@ -967,21 +967,41 @@ func TestMapIteratorAllocations(t *testing.T) {
967
967
func TestMapBatchLookupAllocations (t * testing.T ) {
968
968
testutils .SkipIfNotSupported (t , haveBatchAPI ())
969
969
970
- arr := createMap (t , Array , 10 )
970
+ for _ , typ := range []MapType {Array , PerCPUArray } {
971
+ if typ == PerCPUArray {
972
+ // https://lore.kernel.org/bpf/[email protected] /
973
+ testutils .SkipOnOldKernel (t , "5.13" , "batched ops support for percpu array" )
974
+ }
971
975
972
- var cursor MapBatchCursor
973
- tmp := make ([]uint32 , 2 )
974
- input := any (tmp )
976
+ t .Run (typ .String (), func (t * testing.T ) {
977
+ m := mustNewMap (t , & MapSpec {
978
+ Name : "test" ,
979
+ Type : typ ,
980
+ KeySize : 4 ,
981
+ ValueSize : 8 , // PerCPU values must be 8 byte aligned.
982
+ MaxEntries : 10 ,
983
+ }, nil )
975
984
976
- // AllocsPerRun warms up the function for us.
977
- allocs := testing .AllocsPerRun (1 , func () {
978
- _ , err := arr .BatchLookup (& cursor , input , input , nil )
979
- if err != nil {
980
- t .Fatal (err )
981
- }
982
- })
985
+ possibleCPU := 1
986
+ if m .Type ().hasPerCPUValue () {
987
+ possibleCPU = MustPossibleCPU ()
988
+ }
989
+
990
+ var cursor MapBatchCursor
991
+ keys := any (make ([]uint32 , 2 ))
992
+ values := any (make ([]uint64 , 2 * possibleCPU ))
983
993
984
- qt .Assert (t , qt .Equals (allocs , 0 ))
994
+ // AllocsPerRun warms up the function for us.
995
+ allocs := testing .AllocsPerRun (1 , func () {
996
+ _ , err := m .BatchLookup (& cursor , keys , values , nil )
997
+ if err != nil {
998
+ t .Fatal (err )
999
+ }
1000
+ })
1001
+
1002
+ qt .Assert (t , qt .Equals (allocs , 0 ))
1003
+ })
1004
+ }
985
1005
}
986
1006
987
1007
type customTestUnmarshaler []uint8
0 commit comments