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

Function TestFindReferences

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

Source from the content-addressed store, hash-verified

12)
13
14func TestFindReferences(t *testing.T) {
15 progs := map[string]*ProgramSpec{
16 "entrypoint": {
17 Type: SocketFilter,
18 Instructions: asm.Instructions{
19 // Make sure the call doesn't happen at instruction 0
20 // to exercise the relative offset calculation.
21 asm.Mov.Reg(asm.R0, asm.R1),
22 asm.Call.Label("my_func"),
23 asm.Return(),
24 },
25 License: "MIT",
26 },
27 "my_other_func": {
28 Instructions: asm.Instructions{
29 asm.LoadImm(asm.R0, 1337, asm.DWord).WithSymbol("my_other_func"),
30 asm.Return(),
31 },
32 },
33 "my_func": {
34 Instructions: asm.Instructions{
35 asm.Call.Label("my_other_func").WithSymbol("my_func"),
36 asm.Return(),
37 },
38 },
39 }
40
41 flattenPrograms(progs, []string{"entrypoint"})
42
43 prog, err := newProgram(t, progs["entrypoint"], nil)
44 testutils.SkipIfNotSupported(t, err)
45 qt.Assert(t, qt.IsNil(err))
46
47 ret := mustRun(t, prog, nil)
48
49 if ret != 1337 {
50 t.Errorf("Expected return code 1337, got %d", ret)
51 }
52}
53
54func TestForwardFunctionDeclaration(t *testing.T) {
55 file := testutils.NativeFile(t, "testdata/fwd_decl-%s.elf")

Callers

nothing calls this directly

Calls 10

ReturnFunction · 0.92
LoadImmFunction · 0.92
SkipIfNotSupportedFunction · 0.92
flattenProgramsFunction · 0.85
newProgramFunction · 0.85
LabelMethod · 0.80
WithSymbolMethod · 0.80
IsNilMethod · 0.80
mustRunFunction · 0.70
RegMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…