Skip to content

Commit

Permalink
Merge branch 'aseitz/binary-print-tests' into 'main'
Browse files Browse the repository at this point in the history
Use gtirb-pprinter for tests and some test code cleanup

See merge request rewriting/ddisasm!1183
  • Loading branch information
aeflores committed Mar 24, 2024
2 parents fb5423a + fb3adbd commit c008329
Show file tree
Hide file tree
Showing 34 changed files with 539 additions and 1,043 deletions.
2 changes: 1 addition & 1 deletion examples/asm_examples/ex_base_relative0/Makefile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ all:
ml64.exe ex.asm
@ ex > out.txt
clean:
del /F /Q *.exe *.obj out.txt check.txt mllink$$.lnk
del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk
del /F /Q ex.unstripped *.s *.old*
check:
@ ex > check.txt
Expand Down
2 changes: 1 addition & 1 deletion examples/asm_examples/ex_base_relative1/Makefile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ all:
ml64.exe ex.asm
@ ex > out.txt
clean:
del /F /Q *.exe *.obj out.txt check.txt mllink$$.lnk
del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk
del /F /Q ex.unstripped *.s *.old*
check:
@ ex > check.txt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ all:
ml64.exe ex.asm
@ ex > out.txt
clean:
del /F /Q *.exe *.obj out.txt check.txt mllink$$.lnk
del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk
del /F /Q ex.unstripped *.s *.old*
check:
@ ex > check.txt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ all:
ml64.exe ex.asm
@ ex > out.txt
clean:
del /F /Q *.exe *.obj out.txt check.txt mllink$$.lnk
del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk
del /F /Q ex.unstripped *.s *.old*
check:
@ ex > check.txt
Expand Down
2 changes: 1 addition & 1 deletion examples/asm_examples/ex_npad/Makefile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ all:
ml.exe ex.asm /link /opt:ref /entry:main /subsystem:console
@ ex > out.txt
clean:
del /F /Q *.exe *.obj *.lib out.txt check.txt mllink$$.lnk
del /F /Q *.exe *.obj *.lib out.txt check.txt mllink$$.lnk *.def *.lib
check:
@ ex > check.txt
@ FC out.txt check.txt && echo TEST OK
2 changes: 1 addition & 1 deletion examples/asm_examples/ex_switch_in_code4/Makefile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ all:
ml64.exe ex.asm
@ ex > out.txt
clean:
del /F /Q *.exe *.obj out.txt check.txt mllink$$.lnk
del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk
del /F /Q ex.unstripped *.s *.old*
check:
@ ex > check.txt
Expand Down
9 changes: 1 addition & 8 deletions examples/ex_static_lib_cfg/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,10 @@ libtest.a: $(LIB_OBJ) $(LIB_ASM_OBJ)
$(LIB_ASM_OBJ): $(LIB_ASM_SRC)
$(CC) -c -o $@ $^

reassemble_bar: bar.o.s
$(CC) -c bar.o.s -o bar.o -nostartfiles
$(AR) -rcs libtest.a $(LIB_ASM_OBJ) bar.o
$(CC) $(CFLAGS) -o ex ex.c libtest.a
@ $(EXEC) ./ex >/tmp/res.txt
@ diff out.txt /tmp/res.txt && echo TEST OK

clean:
rm -f ex out.txt libtest.a ex.o $(LIB_OBJ) $(LIB_ASM_OBJ_ALL)
rm -fr ex.unstripped libtest-tmp libtest.gtirb

check:
check: ex
@ $(EXEC) ./ex >/tmp/res.txt
@ diff out.txt /tmp/res.txt && echo TEST OK
75 changes: 28 additions & 47 deletions tests/arm_misc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_arm_invalid_ldr(self):
"""
Test ARM32 invalid load instructions are not disassembled as code.
"""
binary = "ex"
binary = Path("ex")
adder_dir = ex_arm_asm_dir / "ex_ldr"
with cd(adder_dir):
self.assertTrue(
Expand All @@ -31,8 +31,7 @@ def test_arm_invalid_ldr(self):
)

# collect the invalid symbols
self.assertTrue(disassemble(binary, format="--ir")[0])
ir_library = gtirb.IR.load_protobuf(binary + ".gtirb")
ir_library = disassemble(binary).ir()
m = ir_library.modules[0]
invalid_syms = [
sym.name
Expand All @@ -43,17 +42,13 @@ def test_arm_invalid_ldr(self):
for sym in invalid_syms:
extra_strip_flags.append("--keep-symbol={}".format(sym))

self.assertTrue(
disassemble(
binary,
strip_exe="arm-linux-gnueabihf-strip",
strip=True,
format="--ir",
extra_strip_flags=extra_strip_flags,
)[0]
)

ir_library = gtirb.IR.load_protobuf(binary + ".gtirb")
ir_library = disassemble(
binary,
Path("ex_stripped.gtirb"),
strip_exe="arm-linux-gnueabihf-strip",
strip=True,
extra_strip_flags=extra_strip_flags,
).ir()
m = ir_library.modules[0]

main_first_block = None
Expand All @@ -80,7 +75,7 @@ def test_thumb_at_section_start(self):
"""
Test that Thumb code is discovered at the start of a section
"""
binary = "ex"
binary = Path("ex")
with cd(ex_arm_asm_dir / "ex_thumb_at_section_start"):
self.assertTrue(
compile(
Expand All @@ -92,15 +87,11 @@ def test_thumb_at_section_start(self):
)
)

self.assertTrue(
disassemble(
binary,
format="--ir",
strip_exe="arm-linux-gnueabihf-strip",
strip=True,
)[0]
)
ir_library = gtirb.IR.load_protobuf(binary + ".gtirb")
ir_library = disassemble(
binary,
strip_exe="arm-linux-gnueabihf-strip",
strip=True,
).ir()

m = ir_library.modules[0]

Expand All @@ -115,7 +106,7 @@ def test_arm_ldcl(self):
Test that ldcl instructions, valid only on ARMv7 and earlier, decode
correctly.
"""
binary = "ex"
binary = Path("ex")
adder_dir = ex_arm_asm_dir / "ex_ldcl"
with cd(adder_dir):
self.assertTrue(
Expand All @@ -128,8 +119,7 @@ def test_arm_ldcl(self):
)
)

self.assertTrue(disassemble(binary, format="--ir")[0])
ir_library = gtirb.IR.load_protobuf(binary + ".gtirb")
ir_library = disassemble(binary).ir()
m = ir_library.modules[0]

for sym in m.symbols:
Expand Down Expand Up @@ -161,7 +151,7 @@ def test_arm_dead_code_after_literal_pool(self):
code that we did not detect.
"""

binary = "ex"
binary = Path("ex")
dir = ex_arm_asm_dir / "ex_code_after_literal_pool"
with cd(dir):
self.assertTrue(
Expand All @@ -174,16 +164,12 @@ def test_arm_dead_code_after_literal_pool(self):
)
)

self.assertTrue(
disassemble(
binary,
format="--ir",
strip_exe="arm-linux-gnueabihf-strip",
strip=True,
)[0]
)
ir_library = disassemble(
binary,
strip_exe="arm-linux-gnueabihf-strip",
strip=True,
).ir()

ir_library = gtirb.IR.load_protobuf(binary + ".gtirb")
module = ir_library.modules[0]

# ensure we have a block with the dead code:
Expand All @@ -209,7 +195,7 @@ def test_arm_known_block(self):
"""
Ensure $a and $t symbols create known_block on ARM.
"""
binary = "ex"
binary = Path("ex")
dir = ex_arm_asm_dir / "ex_bx_pc"
with cd(dir):
self.assertTrue(
Expand All @@ -222,15 +208,10 @@ def test_arm_known_block(self):
)
)

self.assertTrue(
disassemble(
binary,
format="--ir",
extra_args=["--with-souffle-relations"],
)[0]
)

ir_library = gtirb.IR.load_protobuf(binary + ".gtirb")
ir_library = disassemble(
binary,
extra_args=["--with-souffle-relations"],
).ir()
module = ir_library.modules[0]

known_blocks = parse_souffle_output(module, "known_block")
Expand Down
Loading

0 comments on commit c008329

Please sign in to comment.