From 51fe84f9d5b997aca311aa84c36a33484c2594fb Mon Sep 17 00:00:00 2001 From: Jacob Trimble Date: Mon, 8 Jun 2020 15:53:45 -0700 Subject: [PATCH] Provide better diffs for MP4 failures. If the user has the GPAC MP4 tools installed, this will use that to provide a better, text-based diff of the MP4 files. This makes looking at test failures much better than just "binary files differ". Change-Id: Ifdca54c02226a9f0fe9ddcf9c6b28e960e568111 --- packager/app/test/packager_test.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packager/app/test/packager_test.py b/packager/app/test/packager_test.py index 5f6c66b2d0..8bbddacdb3 100755 --- a/packager/app/test/packager_test.py +++ b/packager/app/test/packager_test.py @@ -133,6 +133,15 @@ class DiffFilesPolicy(object): output, error = self._GitDiff(expected_file, actual_file) + # If this is an MP4 file, get a better looking diff. + if ((output or error) and + os.path.splitext(actual_file)[1] in {'.mp4', '.m4s'}): + new_output, new_error = self._Mp4Diff( + out_dir, expected_file, actual_file) + + output = new_output or output + error = new_error or error + if output: failure_messages += [output.decode('utf8')] @@ -160,6 +169,23 @@ class DiffFilesPolicy(object): p = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE) return p.communicate() + def _Mp4Diff(self, out_dir, file_a, file_b): + dump_a = os.path.join(out_dir, os.path.basename(file_a) + '.dump.expected') + dump_b = os.path.join(out_dir, os.path.basename(file_b) + '.dump.actual') + try: + cmd = ['mp4dump', '--verbosity', '2', file_a] + with open(dump_a, 'w') as f: + subprocess.check_call(cmd, stdout=f) + cmd = ['mp4dump', '--verbosity', '2', file_b] + with open(dump_b, 'w') as f: + subprocess.check_call(cmd, stdout=f) + except (OSError, subprocess.CalledProcessError): + # If the program isn't available or returns an error, just ignore it and + # use the normal diff. + return None, None + + return self._GitDiff(dump_a, dump_b) + def _UpdateGold(self, out_dir, gold_dir): if os.path.exists(gold_dir): shutil.rmtree(gold_dir)