(t *testing.T)
| 520 | } |
| 521 | |
| 522 | func TestStringSection(t *testing.T) { |
| 523 | file := testutils.NativeFile(t, "testdata/strings-%s.elf") |
| 524 | spec, err := LoadCollectionSpec(file) |
| 525 | if err != nil { |
| 526 | t.Fatalf("load collection spec: %s", err) |
| 527 | } |
| 528 | |
| 529 | for name := range spec.Maps { |
| 530 | t.Log(name) |
| 531 | } |
| 532 | |
| 533 | strMap := spec.Maps[".rodata.str1.1"] |
| 534 | if strMap == nil { |
| 535 | t.Fatal("Unable to find map '.rodata.str1.1' in loaded collection") |
| 536 | } |
| 537 | |
| 538 | if !strMap.readOnly() { |
| 539 | t.Fatal("Read only data maps should be frozen") |
| 540 | } |
| 541 | |
| 542 | if strMap.Flags != sys.BPF_F_RDONLY_PROG { |
| 543 | t.Fatal("Read only data maps should have the prog-read-only flag set") |
| 544 | } |
| 545 | |
| 546 | coll, err := newCollection(t, spec, nil) |
| 547 | testutils.SkipIfNotSupported(t, err) |
| 548 | if err != nil { |
| 549 | t.Fatalf("new collection: %s", err) |
| 550 | } |
| 551 | |
| 552 | prog := coll.Programs["filter"] |
| 553 | if prog == nil { |
| 554 | t.Fatal("program not found") |
| 555 | } |
| 556 | |
| 557 | testMap := coll.Maps["my_map"] |
| 558 | if testMap == nil { |
| 559 | t.Fatal("test map not found") |
| 560 | } |
| 561 | |
| 562 | _, err = prog.Run(&RunOptions{ |
| 563 | Data: internal.EmptyBPFContext, // Min size for XDP programs |
| 564 | }) |
| 565 | if err != nil { |
| 566 | t.Fatalf("prog run: %s", err) |
| 567 | } |
| 568 | |
| 569 | key := []byte("This string is allocated in the string section\n\x00") |
| 570 | var value uint32 |
| 571 | if err = testMap.Lookup(&key, &value); err != nil { |
| 572 | t.Fatalf("test map lookup: %s", err) |
| 573 | } |
| 574 | |
| 575 | if value != 1 { |
| 576 | t.Fatal("Test map value not 1!") |
| 577 | } |
| 578 | } |
| 579 |
nothing calls this directly
no test coverage detected
searching dependent graphs…