]> sigrok.org Git - libsigrokdecode.git/blobdiff - tests/pdtest
pdtest/runtc: Support for output type 'exception'.
[libsigrokdecode.git] / tests / pdtest
index ebfcb28895a5482c9e3196e41f7af0ace9578d3a..088ad91cdf2b387ec8d0127da66f83fc9a1ae2a3 100755 (executable)
@@ -20,6 +20,7 @@
 
 import os
 import sys
+import re
 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),
-                    'probes': [],
+                    'channels': [],
                     '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 a == 'probe':
+                    if a == 'channel':
                         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:
@@ -314,8 +315,8 @@ def run_tests(tests, fix=False):
                 # 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'])])
@@ -376,6 +377,12 @@ def run_tests(tests, fix=False):
                         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: Protocol decoder instance %s: %s:" % (op['pd'], 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")
@@ -448,8 +455,8 @@ def show_tests(tests):
                 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: