22import pathlib
33import shutil
44import unittest
5+ import tempfile
6+ import subprocess
57
68import 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