|
@@ -70,7 +70,7 @@ class Alarm(Exception):
|
|
|
"""Exception for signal.alarm events."""
|
|
|
pass
|
|
|
|
|
|
- def handler(*arg):
|
|
|
+ def handler(*args):
|
|
|
"""Notify that an alarm event occurred."""
|
|
|
raise Alarm
|
|
|
|
|
@@ -134,8 +134,8 @@ def __init__(self, test_id, seed, work_dir, run_log,
|
|
|
self.init_path = os.getcwd()
|
|
|
self.work_dir = work_dir
|
|
|
self.current_dir = os.path.join(work_dir, 'test-' + test_id)
|
|
|
- self.qemu_img = os.environ.get('QEMU_IMG', 'qemu-img')\
|
|
|
- .strip().split(' ')
|
|
|
+ self.qemu_img = \
|
|
|
+ os.environ.get('QEMU_IMG', 'qemu-img').strip().split(' ')
|
|
|
self.qemu_io = os.environ.get('QEMU_IO', 'qemu-io').strip().split(' ')
|
|
|
self.commands = [['qemu-img', 'check', '-f', 'qcow2', '$test_img'],
|
|
|
['qemu-img', 'info', '-f', 'qcow2', '$test_img'],
|
|
@@ -212,10 +212,8 @@ def execute(self, input_commands=None, fuzz_config=None):
|
|
|
|
|
|
os.chdir(self.current_dir)
|
|
|
backing_file_name, backing_file_fmt = self._create_backing_file()
|
|
|
- img_size = image_generator.create_image('test.img',
|
|
|
- backing_file_name,
|
|
|
- backing_file_fmt,
|
|
|
- fuzz_config)
|
|
|
+ img_size = image_generator.create_image(
|
|
|
+ 'test.img', backing_file_name, backing_file_fmt, fuzz_config)
|
|
|
for item in commands:
|
|
|
shutil.copy('test.img', 'copy.img')
|
|
|
# 'off' and 'len' are multiple of the sector size
|
|
@@ -228,7 +226,7 @@ def execute(self, input_commands=None, fuzz_config=None):
|
|
|
elif item[0] == 'qemu-io':
|
|
|
current_cmd = list(self.qemu_io)
|
|
|
else:
|
|
|
- multilog("Warning: test command '%s' is not defined.\n" \
|
|
|
+ multilog("Warning: test command '%s' is not defined.\n"
|
|
|
% item[0], sys.stderr, self.log, self.parent_log)
|
|
|
continue
|
|
|
# Replace all placeholders with their real values
|
|
@@ -244,29 +242,28 @@ def execute(self, input_commands=None, fuzz_config=None):
|
|
|
"Backing file: %s\n" \
|
|
|
% (self.seed, " ".join(current_cmd),
|
|
|
self.current_dir, backing_file_name)
|
|
|
-
|
|
|
temp_log = StringIO.StringIO()
|
|
|
try:
|
|
|
retcode = run_app(temp_log, current_cmd)
|
|
|
except OSError, e:
|
|
|
- multilog(test_summary + "Error: Start of '%s' failed. " \
|
|
|
- "Reason: %s\n\n" % (os.path.basename(
|
|
|
- current_cmd[0]), e[1]),
|
|
|
+ multilog("%sError: Start of '%s' failed. Reason: %s\n\n"
|
|
|
+ % (test_summary, os.path.basename(current_cmd[0]),
|
|
|
+ e[1]),
|
|
|
sys.stderr, self.log, self.parent_log)
|
|
|
raise TestException
|
|
|
|
|
|
if retcode < 0:
|
|
|
self.log.write(temp_log.getvalue())
|
|
|
- multilog(test_summary + "FAIL: Test terminated by signal " +
|
|
|
- "%s\n\n" % str_signal(-retcode), sys.stderr, self.log,
|
|
|
- self.parent_log)
|
|
|
+ multilog("%sFAIL: Test terminated by signal %s\n\n"
|
|
|
+ % (test_summary, str_signal(-retcode)),
|
|
|
+ sys.stderr, self.log, self.parent_log)
|
|
|
self.failed = True
|
|
|
else:
|
|
|
if self.log_all:
|
|
|
self.log.write(temp_log.getvalue())
|
|
|
- multilog(test_summary + "PASS: Application exited with" +
|
|
|
- " the code '%d'\n\n" % retcode, sys.stdout,
|
|
|
- self.log, self.parent_log)
|
|
|
+ multilog("%sPASS: Application exited with the code " \
|
|
|
+ "'%d'\n\n" % (test_summary, retcode),
|
|
|
+ sys.stdout, self.log, self.parent_log)
|
|
|
temp_log.close()
|
|
|
os.remove('copy.img')
|
|
|
|
|
@@ -286,8 +283,9 @@ def usage():
|
|
|
|
|
|
Set up test environment in TEST_DIR and run a test in it. A module for
|
|
|
test image generation should be specified via IMG_GENERATOR.
|
|
|
+
|
|
|
Example:
|
|
|
- runner.py -c '[["qemu-img", "info", "$test_img"]]' /tmp/test qcow2
|
|
|
+ runner.py -c '[["qemu-img", "info", "$test_img"]]' /tmp/test qcow2
|
|
|
|
|
|
Optional arguments:
|
|
|
-h, --help display this help and exit
|
|
@@ -305,20 +303,22 @@ def usage():
|
|
|
|
|
|
'--command' accepts a JSON array of commands. Each command presents
|
|
|
an application under test with all its paramaters as a list of strings,
|
|
|
- e.g.
|
|
|
- ["qemu-io", "$test_img", "-c", "write $off $len"]
|
|
|
+ e.g. ["qemu-io", "$test_img", "-c", "write $off $len"].
|
|
|
|
|
|
Supported application aliases: 'qemu-img' and 'qemu-io'.
|
|
|
+
|
|
|
Supported argument aliases: $test_img for the fuzzed image, $off
|
|
|
for an offset, $len for length.
|
|
|
|
|
|
Values for $off and $len will be generated based on the virtual disk
|
|
|
- size of the fuzzed image
|
|
|
+ size of the fuzzed image.
|
|
|
+
|
|
|
Paths to 'qemu-img' and 'qemu-io' are retrevied from 'QEMU_IMG' and
|
|
|
- 'QEMU_IO' environment variables
|
|
|
+ 'QEMU_IO' environment variables.
|
|
|
|
|
|
'--config' accepts a JSON array of fields to be fuzzed, e.g.
|
|
|
- '[["header"], ["header", "version"]]'
|
|
|
+ '[["header"], ["header", "version"]]'.
|
|
|
+
|
|
|
Each of the list elements can consist of a complex image element only
|
|
|
as ["header"] or ["feature_name_table"] or an exact field as
|
|
|
["header", "version"]. In the first case random portion of the element
|
|
@@ -368,7 +368,6 @@ def should_continue(duration, start_time):
|
|
|
seed = None
|
|
|
config = None
|
|
|
duration = None
|
|
|
-
|
|
|
for opt, arg in opts:
|
|
|
if opt in ('-h', '--help'):
|
|
|
usage()
|