]> sigrok.org Git - libsigrokdecode.git/blobdiff - tests/pdtest
tests/pdtest: Fix shebang line.
[libsigrokdecode.git] / tests / pdtest
index 608cd8a464012f3e6bfded10c6c1601f60ad0ca8..2ed0d9f4ec72b6aa0b94a442e40b236f178acd04 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env /usr/bin/python3
+#!/usr/bin/env python3
 
 import os
 import sys
@@ -6,6 +6,8 @@ from getopt import getopt
 from tempfile import mkstemp
 from subprocess import Popen, PIPE
 from difflib import Differ
+from hashlib import md5
+from shutil import copy
 
 DEBUG = 0
 VERBOSE = False
@@ -203,7 +205,7 @@ def get_tests(testnames):
     return tests
 
 
-def diff_files(f1, f2):
+def diff_text(f1, f2):
     t1 = open(f1).readlines()
     t2 = open(f2).readlines()
     diff = []
@@ -215,6 +217,19 @@ def diff_files(f1, f2):
     return diff
 
 
+def compare_binary(f1, f2):
+    h1 = md5()
+    h1.update(open(f1, 'rb').read())
+    h2 = md5()
+    h2.update(open(f2, 'rb').read())
+    if h1.digest() == h2.digest():
+        result = None
+    else:
+        result = ["Binary output does not match."]
+
+    return result
+
+
 def run_tests(tests, fix=False):
     errors = 0
     results = []
@@ -263,8 +278,10 @@ def run_tests(tests, fix=False):
                         match = os.path.join(decoders_dir, op['pd'], 'test', op['match'])
                         try:
                             diff = diff_error = None
-                            if op['type'] == 'annotation':
-                                diff = diff_textfiles(match, outfile)
+                            if op['type'] in ('annotation', 'python'):
+                                diff = diff_text(match, outfile)
+                            elif op['type'] == 'binary':
+                                diff = compare_binary(match, outfile)
                             else:
                                 diff = ["Unsupported output type '%s'." % op['type']]
                         except Exception as e: