(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func 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 | |
| 54 | func TestForwardFunctionDeclaration(t *testing.T) { |
| 55 | file := testutils.NativeFile(t, "testdata/fwd_decl-%s.elf") |
nothing calls this directly
no test coverage detected
searching dependent graphs…