]> sigrok.org Git - libsigrokdecode.git/blobdiff - tests/pdtest
tests/pdtest: Small fix to make it work with Python 3.2.
[libsigrokdecode.git] / tests / pdtest
index ebfcb28895a5482c9e3196e41f7af0ace9578d3a..d0717a8b8124fe9aea2e47ad0915909cf9602ec4 100755 (executable)
@@ -20,6 +20,7 @@
 
 import os
 import sys
 
 import os
 import sys
+import re
 from getopt import getopt
 from tempfile import mkstemp
 from subprocess import Popen, PIPE
 from getopt import getopt
 from tempfile import mkstemp
 from subprocess import Popen, PIPE
@@ -110,7 +111,7 @@ def parse_testfile(path, pd, tc, op_type, op_class):
                     raise E_syntax
                 pd_spec = {
                     'name': f.pop(0),
                     raise E_syntax
                 pd_spec = {
                     'name': f.pop(0),
-                    'probes': [],
+                    'channels': [],
                     'options': [],
                 }
                 while len(f):
                     'options': [],
                 }
                 while len(f):
@@ -122,12 +123,12 @@ def parse_testfile(path, pd, tc, op_type, op_class):
                     if '=' not in b:
                         raise E_syntax
                     opt, val = b.split('=')
                     if '=' not in b:
                         raise E_syntax
                     opt, val = b.split('=')
-                    if a == 'probe':
+                    if a == 'channel':
                         try:
                             val = int(val)
                         except:
                             raise E_syntax
                         try:
                             val = int(val)
                         except:
                             raise E_syntax
-                        pd_spec['probes'].append([opt, val])
+                        pd_spec['channels'].append([opt, val])
                     elif a == 'option':
                         pd_spec['options'].append([opt, val])
                     else:
                     elif a == 'option':
                         pd_spec['options'].append([opt, val])
                     else:
@@ -308,14 +309,14 @@ def run_tests(tests, fix=False):
         pd_cvg = []
         for tclist in tests[pd]:
             for tc in tclist:
         pd_cvg = []
         for tclist in tests[pd]:
             for tc in tclist:
-                args = cmd.copy()
+                args = cmd[:]
                 if DEBUG > 1:
                     args.append('-d')
                 # Set up PD stack for this test.
                 for spd in tc['pdlist']:
                     args.extend(['-P', spd['name']])
                 if DEBUG > 1:
                     args.append('-d')
                 # Set up PD stack for this test.
                 for spd in tc['pdlist']:
                     args.extend(['-P', spd['name']])
-                    for label, probe in spd['probes']:
-                        args.extend(['-p', "%s=%d" % (label, probe)])
+                    for label, channel in spd['channels']:
+                        args.extend(['-p', "%s=%d" % (label, channel)])
                     for option, value in spd['options']:
                         args.extend(['-o', "%s=%s" % (option, value)])
                 args.extend(['-i', os.path.join(dumps_dir, tc['input'])])
                     for option, value in spd['options']:
                         args.extend(['-o', "%s=%s" % (option, value)])
                 args.extend(['-i', os.path.join(dumps_dir, tc['input'])])
@@ -376,6 +377,12 @@ def run_tests(tests, fix=False):
                         if coverage:
                             results[-1]['coverage_report'] = coverage
                         os.unlink(outfile)
                         if coverage:
                             results[-1]['coverage_report'] = coverage
                         os.unlink(outfile)
+                    if op['type'] == 'exception' and 'error' in results[-1]:
+                        # filter out the exception we were looking for
+                        reg = "^Error: srd: %s:" % op['match']
+                        if re.match(reg, results[-1]['error']):
+                            # found it, not an error
+                            results[-1].pop('error')
                     if VERBOSE:
                         if 'diff' in results[-1]:
                             INFO("Output mismatch")
                     if VERBOSE:
                         if 'diff' in results[-1]:
                             INFO("Output mismatch")
@@ -402,14 +409,29 @@ def run_tests(tests, fix=False):
                         for cvg in results[-1]['coverage']:
                             if cvg['scope'] == pd:
                                 pd_cvg.append(cvg)
                         for cvg in results[-1]['coverage']:
                             if cvg['scope'] == pd:
                                 pd_cvg.append(cvg)
-        if VERBOSE and opt_coverage and len(pd_cvg) > 1:
+        if opt_coverage and len(pd_cvg) > 1:
             # report total coverage of this PD, across all the tests
             # that were done on it.
             total_lines, missed_lines = coverage_sum(pd_cvg)
             pd_coverage = 100 - (float(len(missed_lines)) / total_lines * 100)
             if VERBOSE:
                 dots = '.' * (54 - len(pd) - 2)
             # report total coverage of this PD, across all the tests
             # that were done on it.
             total_lines, missed_lines = coverage_sum(pd_cvg)
             pd_coverage = 100 - (float(len(missed_lines)) / total_lines * 100)
             if VERBOSE:
                 dots = '.' * (54 - len(pd) - 2)
-            INFO("%s total %s %d%%" % (pd, dots, pd_coverage))
+                INFO("%s total %s %d%%" % (pd, dots, pd_coverage))
+            if report_dir:
+                # generate a missing lines list across all the files in
+                # the PD
+                files = {}
+                for entry in missed_lines:
+                    filename, line = entry.split(':')
+                    if filename not in files:
+                        files[filename] = []
+                    files[filename].append(line)
+                text = ''
+                for filename in sorted(files.keys()):
+                    line_list = ','.join(sorted(files[filename], key=int))
+                    text += "%s: %s\n" % (filename, line_list)
+                open(os.path.join(report_dir, pd + "_total"), 'w').write(text)
+
 
     return results, errors
 
 
     return results, errors
 
@@ -448,8 +470,8 @@ def show_tests(tests):
                 print("Testcase: %s/%s" % (tc['pd'], tc['name']))
                 for pd in tc['pdlist']:
                     print("  Protocol decoder: %s" % pd['name'])
                 print("Testcase: %s/%s" % (tc['pd'], tc['name']))
                 for pd in tc['pdlist']:
                     print("  Protocol decoder: %s" % pd['name'])
-                    for label, probe in pd['probes']:
-                        print("    Probe %s=%d" % (label, probe))
+                    for label, channel in pd['channels']:
+                        print("    Channel %s=%d" % (label, channel))
                     for option, value in pd['options']:
                         print("    Option %s=%d" % (option, value))
                 if 'stack' in tc:
                     for option, value in pd['options']:
                         print("    Option %s=%d" % (option, value))
                 if 'stack' in tc: