(t *testing.T)
| 326 | } |
| 327 | |
| 328 | func TestBatchMapWithLock(t *testing.T) { |
| 329 | testutils.SkipOnOldKernel(t, "5.13", "MAP BATCH BPF_F_LOCK") |
| 330 | |
| 331 | spec, err := LoadCollectionSpec(testutils.NativeFile(t, "testdata/map_spin_lock-%s.elf")) |
| 332 | qt.Assert(t, qt.IsNil(err)) |
| 333 | |
| 334 | coll := mustNewCollection(t, spec, nil) |
| 335 | |
| 336 | type spinLockValue struct { |
| 337 | Cnt uint32 |
| 338 | Padding uint32 |
| 339 | } |
| 340 | |
| 341 | m, ok := coll.Maps["spin_lock_map"] |
| 342 | if !ok { |
| 343 | t.Fatal(err) |
| 344 | } |
| 345 | |
| 346 | keys := []uint32{0, 1} |
| 347 | values := []spinLockValue{{Cnt: 42}, {Cnt: 4242}} |
| 348 | count, err := m.BatchUpdate(keys, values, &BatchOptions{ElemFlags: uint64(UpdateLock)}) |
| 349 | testutils.SkipIfNotSupportedOnOS(t, err) |
| 350 | if err != nil { |
| 351 | t.Fatalf("BatchUpdate: %v", err) |
| 352 | } |
| 353 | if count != len(keys) { |
| 354 | t.Fatalf("BatchUpdate: expected count, %d, to be %d", count, len(keys)) |
| 355 | } |
| 356 | |
| 357 | var cursor MapBatchCursor |
| 358 | lookupKeys := make([]uint32, 2) |
| 359 | lookupValues := make([]spinLockValue, 2) |
| 360 | count, err = m.BatchLookup(&cursor, lookupKeys, lookupValues, &BatchOptions{ElemFlags: uint64(LookupLock)}) |
| 361 | if !errors.Is(err, ErrKeyNotExist) { |
| 362 | t.Fatalf("BatchLookup: %v", err) |
| 363 | } |
| 364 | if count != 2 { |
| 365 | t.Fatalf("BatchLookup: expected two keys, got %d", count) |
| 366 | } |
| 367 | |
| 368 | cursor = MapBatchCursor{} |
| 369 | deleteKeys := []uint32{0, 1} |
| 370 | deleteValues := make([]spinLockValue, 2) |
| 371 | count, err = m.BatchLookupAndDelete(&cursor, deleteKeys, deleteValues, nil) |
| 372 | if !errors.Is(err, ErrKeyNotExist) { |
| 373 | t.Fatalf("BatchLookupAndDelete: %v", err) |
| 374 | } |
| 375 | if count != 2 { |
| 376 | t.Fatalf("BatchLookupAndDelete: expected two keys, got %d", count) |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | func TestMapWithLock(t *testing.T) { |
| 381 | testutils.SkipOnOldKernel(t, "5.13", "MAP BPF_F_LOCK") |
nothing calls this directly
no test coverage detected
searching dependent graphs…