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

Function TestMapWithLock

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

Source from the content-addressed store, hash-verified

378}
379
380func TestMapWithLock(t *testing.T) {
381 testutils.SkipOnOldKernel(t, "5.13", "MAP BPF_F_LOCK")
382
383 spec, err := LoadCollectionSpec(testutils.NativeFile(t, "testdata/map_spin_lock-%s.elf"))
384 qt.Assert(t, qt.IsNil(err))
385
386 coll := mustNewCollection(t, spec, nil)
387
388 type spinLockValue struct {
389 Cnt uint32
390 Padding uint32
391 }
392
393 m, ok := coll.Maps["spin_lock_map"]
394 if !ok {
395 t.Fatal(err)
396 }
397
398 key := uint32(1)
399 value := spinLockValue{Cnt: 5}
400 err = m.Update(key, value, UpdateLock)
401 if platform.IsWindows && errors.Is(err, unix.EINVAL) {
402 t.Skip("Windows doesn't support UpdateLock")
403 }
404 if err != nil {
405 t.Fatal(err)
406 }
407
408 value.Cnt = 0
409 err = m.LookupWithFlags(&key, &value, LookupLock)
410 if err != nil {
411 t.Fatal(err)
412 }
413 if value.Cnt != 5 {
414 t.Fatalf("Want value 5, got %d", value.Cnt)
415 }
416
417 t.Run("LookupAndDelete", func(t *testing.T) {
418 testutils.SkipOnOldKernel(t, "5.14", "LOOKUP_AND_DELETE flags")
419
420 value.Cnt = 0
421 err = m.LookupAndDeleteWithFlags(&key, &value, LookupLock)
422 if err != nil {
423 t.Fatal(err)
424 }
425 if value.Cnt != 5 {
426 t.Fatalf("Want value 5, got %d", value.Cnt)
427 }
428
429 err = m.LookupWithFlags(&key, &value, LookupLock)
430 if err != nil && !errors.Is(err, ErrKeyNotExist) {
431 t.Fatal(err)
432 }
433 })
434}
435
436func TestMapCloneNil(t *testing.T) {
437 m, err := (*Map)(nil).Clone()

Callers

nothing calls this directly

Calls 10

SkipOnOldKernelFunction · 0.92
NativeFileFunction · 0.92
LoadCollectionSpecFunction · 0.85
mustNewCollectionFunction · 0.85
IsNilMethod · 0.80
LookupWithFlagsMethod · 0.80
UpdateMethod · 0.65
RunMethod · 0.65
IsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…