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

Function TestCollectionAssignFail

collection_test.go:488–523  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

486}
487
488func TestCollectionAssignFail(t *testing.T) {
489 // `map2` does not exist
490 var objs struct {
491 Program *Program `ebpf:"prog1"`
492 Map *Map `ebpf:"map2"`
493 }
494
495 cs := &CollectionSpec{
496 Maps: map[string]*MapSpec{
497 "map1": {
498 Type: Array,
499 KeySize: 4,
500 ValueSize: 4,
501 MaxEntries: 1,
502 },
503 },
504 Programs: map[string]*ProgramSpec{
505 "prog1": {
506 Type: SocketFilter,
507 Instructions: asm.Instructions{
508 asm.LoadImm(asm.R0, 0, asm.DWord),
509 asm.Return(),
510 },
511 License: "MIT",
512 },
513 },
514 }
515
516 coll := mustNewCollection(t, cs, nil)
517
518 qt.Assert(t, qt.IsNotNil(coll.Assign(&objs)))
519
520 // Check that the collection has retained ownership
521 qt.Assert(t, qt.IsNotNil(coll.Programs["prog1"]))
522 qt.Assert(t, qt.IsNotNil(coll.Maps["map1"]))
523}
524
525func TestIncompleteLoadAndAssign(t *testing.T) {
526 spec := &CollectionSpec{

Callers

nothing calls this directly

Calls 4

LoadImmFunction · 0.92
ReturnFunction · 0.92
mustNewCollectionFunction · 0.85
AssignMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…