tps: implement --yes intrusively

This redefines raw_input to return 'y' always in case of
EOF, and closes stdin so that --yes forces this behaviour
when requested to do so.

This is mostly redundant: it has to be decided by the testers
what they really want.
parent 1c73034c
...@@ -27,17 +27,24 @@ default_log_name = 'tps_run_{runid}_{timestamp}_{board}_{serial}.txt' ...@@ -27,17 +27,24 @@ default_log_name = 'tps_run_{runid}_{timestamp}_{board}_{serial}.txt'
default_test_pattern = r'test[0-9][0-9]' default_test_pattern = r'test[0-9][0-9]'
default_test_syntax = r'(test)?(\d\d)' default_test_syntax = r'(test)?(\d\d)'
def run_test(testname, logname): def run_test(testname, logname, yes=False):
"""run test testname with output redirected to logname """run test testname with output redirected to logname
If yes is true, assume affirmative answers from the user
""" """
try: try:
tmpout = sys.stdout tmpout = sys.stdout
sys.stdout = open(logname, 'w') sys.stdout = open(logname, 'w')
if yes:
tmpin = sys.stdin
sys.stdin = open('/dev/null')
mod = __import__(testname, globals(), locals(), []) mod = __import__(testname, globals(), locals(), [])
mod.main(default_directory='./test/spec/python') mod.main(default_directory='./test/spec/python')
finally: finally:
sys.stdout.close() sys.stdout.close()
sys.stdout = tmpout sys.stdout = tmpout
if yes:
sys.stdin = tmpin
class Suite(object): class Suite(object):
def __init__(self, cfgfilename=default_config_file): def __init__(self, cfgfilename=default_config_file):
...@@ -190,7 +197,7 @@ class Suite(object): ...@@ -190,7 +197,7 @@ class Suite(object):
log.write('------------------------\n') log.write('------------------------\n')
log.write('running test {0} = {1}\n'.format(shortname, test)) log.write('running test {0} = {1}\n'.format(shortname, test))
print '.', print '.',
run_test(testname, logname) run_test(testname, logname, yes=self.yes)
except TpsCritical, e: except TpsCritical, e:
print 'test [%s]: critical error, aborting: [%s]' % (shortname, e) print 'test [%s]: critical error, aborting: [%s]' % (shortname, e)
log.write(' critical error in test {0}, exception [{1}]\n'.format(shortname, e)) log.write(' critical error in test {0}, exception [{1}]\n'.format(shortname, e))
......
...@@ -31,5 +31,12 @@ class TpsBadTestNo(TpsInvalid): ...@@ -31,5 +31,12 @@ class TpsBadTestNo(TpsInvalid):
"""reserved: a bad test number was given""" """reserved: a bad test number was given"""
pass pass
def raw_input(msg, default='y'):
try:
ret = __builtins__.raw_input(msg)
except EOFError:
return default
return ret
if __name__ == '__main__': if __name__ == '__main__':
pass pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment