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

Function TestForwardFunctionDeclaration

linker_test.go:54–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

52}
53
54func TestForwardFunctionDeclaration(t *testing.T) {
55 file := testutils.NativeFile(t, "testdata/fwd_decl-%s.elf")
56 coll, err := LoadCollectionSpec(file)
57 if err != nil {
58 t.Fatal(err)
59 }
60
61 spec := coll.Programs["call_fwd"]
62
63 // This program calls an unimplemented forward function declaration.
64 _, err = newProgram(t, spec, nil)
65 if !errors.Is(err, asm.ErrUnsatisfiedProgramReference) {
66 t.Fatal("Expected an error wrapping ErrUnsatisfiedProgramReference, got:", err)
67 }
68
69 // Append the implementation of fwd().
70 spec.Instructions = append(spec.Instructions,
71 asm.Mov.Imm32(asm.R0, 23).WithSymbol("fwd"),
72 asm.Return(),
73 )
74
75 // The body of the subprog we appended does not come with BTF func_infos,
76 // so the verifier will reject it. Load without BTF.
77 for i, ins := range spec.Instructions {
78 if btf.FuncMetadata(&ins) != nil || ins.Source() != nil {
79 sym := ins.Symbol()
80 ref := ins.Reference()
81 ins.Metadata = asm.Metadata{}
82 spec.Instructions[i] = ins.WithSymbol(sym).WithReference(ref)
83 }
84 }
85
86 prog, err := newProgram(t, spec, nil)
87 testutils.SkipIfNotSupported(t, err)
88 qt.Assert(t, qt.IsNil(err))
89
90 ret := mustRun(t, prog, nil)
91
92 if ret != 23 {
93 t.Fatalf("Expected 23, got %d", ret)
94 }
95}
96
97func TestFlattenInstructionsAllocations(t *testing.T) {
98 name := "entrypoint"

Callers

nothing calls this directly

Calls 15

NativeFileFunction · 0.92
ReturnFunction · 0.92
FuncMetadataFunction · 0.92
SkipIfNotSupportedFunction · 0.92
LoadCollectionSpecFunction · 0.85
newProgramFunction · 0.85
WithSymbolMethod · 0.80
ReferenceMethod · 0.80
WithReferenceMethod · 0.80
IsNilMethod · 0.80
mustRunFunction · 0.70
IsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…