Skip to content

Commit 6db2f6e

Browse files
authored
SymQEMU tests: on test error, print differences of generated test case (#60)
* add colored hexdump diff of different test cases generated * add new package dependencies to docker
1 parent 40f0b4c commit 6db2f6e

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ RUN apt update && apt install -y \
1616
z3 \
1717
libz3-dev \
1818
libz3-dev \
19-
libzstd-dev
19+
libzstd-dev \
20+
colordiff \
21+
xxd \
22+
wdiff
2023

2124
RUN pip install --user meson
2225

tests/symqemu/test.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import pathlib
33
import shutil
44
import unittest
5+
import tempfile
6+
import subprocess
57

68
import util
79

@@ -16,13 +18,33 @@ def tearDown(self):
1618
shutil.rmtree(self.SYMQEMU_OUTPUT_DIR)
1719

1820
def run_symqemu_and_assert_correct_result(self, binary_name):
21+
symqemu_ref_output_dir = util.BINARIES_DIR / binary_name / 'expected_outputs'
1922

2023
util.run_symqemu_on_test_binary(binary_name=binary_name, generated_test_cases_output_dir=self.SYMQEMU_OUTPUT_DIR)
2124

2225
# `filecmp.dircmp` does a "shallow" comparison, but this is not a problem here because
2326
# the timestamps should always be different, so the actual content of the files will be compared.
2427
# See https://docs.python.org/3/library/filecmp.html#filecmp.dircmp
25-
expected_vs_actual_output_comparison = filecmp.dircmp(self.SYMQEMU_OUTPUT_DIR, util.BINARIES_DIR / binary_name / 'expected_outputs')
28+
expected_vs_actual_output_comparison = filecmp.dircmp(self.SYMQEMU_OUTPUT_DIR, symqemu_ref_output_dir)
29+
30+
for diff_file in expected_vs_actual_output_comparison.diff_files:
31+
ref_file = symqemu_ref_output_dir / diff_file
32+
gen_file = self.SYMQEMU_OUTPUT_DIR / diff_file
33+
34+
tmp_ref = tempfile.NamedTemporaryFile("w+")
35+
subprocess.run(["xxd", f"{ref_file}"], stdout=tmp_ref, check=True)
36+
37+
tmp_gen = tempfile.NamedTemporaryFile("w+")
38+
subprocess.run(["xxd", f"{gen_file}"], stdout=tmp_gen, check=True)
39+
40+
wdiff = subprocess.run(["wdiff", f"{tmp_ref.name}", f"{tmp_gen.name}"], capture_output=True)
41+
colordiff = subprocess.run(["colordiff"], input=wdiff.stdout, capture_output=True)
42+
43+
print(f"===== Diff found in {diff_file} ======")
44+
print(f"{colordiff.stdout.decode('utf-8').strip()}")
45+
print(f"=================================")
46+
print()
47+
2648
self.assertEqual(expected_vs_actual_output_comparison.diff_files, [])
2749
self.assertEqual(expected_vs_actual_output_comparison.left_only, [])
2850
self.assertEqual(expected_vs_actual_output_comparison.right_only, [])

0 commit comments

Comments
 (0)