runner: Add an argument for test duration

After the specified duration the runner stops executing new tests, but it
doesn't interrupt running ones.

Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Maria Kustova <maria.k@catit.be>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Maria Kustova 2014-08-19 00:02:34 +04:00 committed by Kevin Wolf
parent d4df3dbc02
commit 9d256ca616
1 changed files with 17 additions and 4 deletions

View File

@ -25,6 +25,7 @@ import subprocess
import random import random
import shutil import shutil
from itertools import count from itertools import count
import time
import getopt import getopt
import StringIO import StringIO
import resource import resource
@ -269,6 +270,7 @@ if __name__ == '__main__':
Optional arguments: Optional arguments:
-h, --help display this help and exit -h, --help display this help and exit
-d, --duration=NUMBER finish tests after NUMBER of seconds
-c, --command=JSON run tests for all commands specified in -c, --command=JSON run tests for all commands specified in
the JSON array the JSON array
-s, --seed=STRING seed for a test image generation, -s, --seed=STRING seed for a test image generation,
@ -325,10 +327,15 @@ if __name__ == '__main__':
finally: finally:
test.finish() test.finish()
def should_continue(duration, start_time):
"""Return True if a new test can be started and False otherwise."""
current_time = int(time.time())
return (duration is None) or (current_time - start_time < duration)
try: try:
opts, args = getopt.gnu_getopt(sys.argv[1:], 'c:hs:kv', opts, args = getopt.gnu_getopt(sys.argv[1:], 'c:hs:kvd:',
['command=', 'help', 'seed=', 'config=', ['command=', 'help', 'seed=', 'config=',
'keep_passed', 'verbose']) 'keep_passed', 'verbose', 'duration='])
except getopt.error, e: except getopt.error, e:
print >>sys.stderr, \ print >>sys.stderr, \
"Error: %s\n\nTry 'runner.py --help' for more information" % e "Error: %s\n\nTry 'runner.py --help' for more information" % e
@ -339,6 +346,8 @@ if __name__ == '__main__':
log_all = False log_all = False
seed = None seed = None
config = None config = None
duration = None
for opt, arg in opts: for opt, arg in opts:
if opt in ('-h', '--help'): if opt in ('-h', '--help'):
usage() usage()
@ -357,6 +366,8 @@ if __name__ == '__main__':
log_all = True log_all = True
elif opt in ('-s', '--seed'): elif opt in ('-s', '--seed'):
seed = arg seed = arg
elif opt in ('-d', '--duration'):
duration = int(arg)
elif opt == '--config': elif opt == '--config':
try: try:
config = json.loads(arg) config = json.loads(arg)
@ -394,9 +405,11 @@ if __name__ == '__main__':
resource.setrlimit(resource.RLIMIT_CORE, (-1, -1)) resource.setrlimit(resource.RLIMIT_CORE, (-1, -1))
# If a seed is specified, only one test will be executed. # If a seed is specified, only one test will be executed.
# Otherwise runner will terminate after a keyboard interruption # Otherwise runner will terminate after a keyboard interruption
for test_id in count(1): start_time = int(time.time())
test_id = count(1)
while should_continue(duration, start_time):
try: try:
run_test(str(test_id), seed, work_dir, run_log, cleanup, run_test(str(test_id.next()), seed, work_dir, run_log, cleanup,
log_all, command, config) log_all, command, config)
except (KeyboardInterrupt, SystemExit): except (KeyboardInterrupt, SystemExit):
sys.exit(1) sys.exit(1)