from getopt import getopt
from tempfile import mkstemp
from subprocess import Popen, PIPE
-from difflib import Differ
+from difflib import unified_diff
from hashlib import md5
from shutil import copy
-l List test(s)
-s Show test(s)
-r Run test(s)
- -f Fix failed test(s)
+ -f Fix failed test(s) / create initial output for new test(s)
-c Report decoder code coverage
-R <directory> Save test reports to <directory>
<test> Protocol decoder name ("i2c") and optionally test name ("i2c/rtc")""")
'name': f.pop(0),
'channels': [],
'options': [],
+ 'initial_pins': [],
}
while len(f):
if len(f) == 1:
pd_spec['channels'].append([opt, val])
elif a == 'option':
pd_spec['options'].append([opt, val])
+ elif a == 'initial_pin':
+ try:
+ val = int(val)
+ except:
+ raise E_syntax
+ pd_spec['initial_pins'].append([opt, val])
else:
raise E_syntax
tclist[-1]['pdlist'].append(pd_spec)
def diff_text(f1, f2):
t1 = open(f1).readlines()
t2 = open(f2).readlines()
- diff = []
- d = Differ()
- for line in d.compare(t1, t2):
- if line[:2] in ('- ', '+ '):
- diff.append(line.strip())
-
+ diff = list(unified_diff(t1, t2))
+ diff = diff[2:] # Strip two from/to filename lines with "+++"/"---".
+ diff = [d.strip() for d in diff if d[0] in ('+', '-')]
return diff
args.extend(['-p', "%s=%d" % (label, channel)])
for option, value in spd['options']:
args.extend(['-o', "%s=%s" % (option, value)])
+ for label, initial_pin in spd['initial_pins']:
+ args.extend(['-N', "%s=%d" % (label, initial_pin)])
args.extend(['-i', os.path.join(dumps_dir, tc['input'])])
for op in tc['output']:
name = "%s/%s/%s" % (pd, tc['name'], op['type'])
for label, channel in pd['channels']:
print(" Channel %s=%d" % (label, channel))
for option, value in pd['options']:
- print(" Option %s=%d" % (option, value))
+ print(" Option %s=%s" % (option, value))
+ for label, initial_pin in pd['initial_pins']:
+ print(" Initial pin %s=%d" % (label, initial_pin))
if 'stack' in tc:
print(" Stack: %s" % ' '.join(tc['stack']))
print(" Input: %s" % tc['input'])
try:
if args:
testlist = get_tests(args)
- elif opt_all:
+ elif opt_all or opt_list:
testlist = get_tests(os.listdir(tests_dir))
else:
usage("Specify either -a or tests.")