TestFunctionAssembly tests the FunctionAssembly routine by using a fake objdump script.
(t *testing.T)
| 102 | // TestFunctionAssembly tests the FunctionAssembly routine by using a |
| 103 | // fake objdump script. |
| 104 | func TestFunctionAssembly(t *testing.T) { |
| 105 | type testcase struct { |
| 106 | s plugin.Sym |
| 107 | asm string |
| 108 | want []plugin.Inst |
| 109 | } |
| 110 | testcases := []testcase{ |
| 111 | { |
| 112 | plugin.Sym{Name: []string{"symbol1"}, Start: 0x1000, End: 0x1FFF}, |
| 113 | " 1000: instruction one\n 1001: instruction two\n 1002: instruction three\n 1003: instruction four", |
| 114 | []plugin.Inst{ |
| 115 | {Addr: 0x1000, Text: "instruction one"}, |
| 116 | {Addr: 0x1001, Text: "instruction two"}, |
| 117 | {Addr: 0x1002, Text: "instruction three"}, |
| 118 | {Addr: 0x1003, Text: "instruction four"}, |
| 119 | }, |
| 120 | }, |
| 121 | { |
| 122 | plugin.Sym{Name: []string{"symbol2"}, Start: 0x2000, End: 0x2FFF}, |
| 123 | " 2000: instruction one\n 2001: instruction two", |
| 124 | []plugin.Inst{ |
| 125 | {Addr: 0x2000, Text: "instruction one"}, |
| 126 | {Addr: 0x2001, Text: "instruction two"}, |
| 127 | }, |
| 128 | }, |
| 129 | { |
| 130 | plugin.Sym{Name: []string{"_main"}, Start: 0x30000, End: 0x3FFF}, |
| 131 | "_main:\n; /tmp/hello.c:3\n30001: push %rbp", |
| 132 | []plugin.Inst{ |
| 133 | {Addr: 0x30001, Text: "push %rbp", Function: "_main", File: "/tmp/hello.c", Line: 3}, |
| 134 | }, |
| 135 | }, |
| 136 | { |
| 137 | plugin.Sym{Name: []string{"main"}, Start: 0x4000, End: 0x4FFF}, |
| 138 | "000000000040052d <main>:\nmain():\n/tmp/hello.c:3\n40001: push %rbp", |
| 139 | []plugin.Inst{ |
| 140 | {Addr: 0x40001, Text: "push %rbp", Function: "main", File: "/tmp/hello.c", Line: 3}, |
| 141 | }, |
| 142 | }, |
| 143 | } |
| 144 | |
| 145 | for _, tc := range testcases { |
| 146 | insts, err := disassemble([]byte(tc.asm)) |
| 147 | if err != nil { |
| 148 | t.Fatalf("FunctionAssembly: %v", err) |
| 149 | } |
| 150 | |
| 151 | if len(insts) != len(tc.want) { |
| 152 | t.Errorf("Unexpected number of assembly instructions %d (want %d)\n", len(insts), len(tc.want)) |
| 153 | } |
| 154 | for i := range insts { |
| 155 | if insts[i] != tc.want[i] { |
| 156 | t.Errorf("Expected symbol %v, got %v\n", tc.want[i], insts[i]) |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…