mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-23 19:49:43 +00:00
image-fuzzer: Trivial readability and formatting improvements
Signed-off-by: Maria Kustova <maria.k@catit.be> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
5b0ed2be88
commit
407ba0844d
@ -332,9 +332,8 @@ def l1_entry(current):
|
||||
constraints = UINT64_V
|
||||
# Reserved bits are ignored
|
||||
# Added a possibility when only flags are fuzzed
|
||||
offset = 0x7fffffffffffffff & random.choice([selector(current,
|
||||
constraints),
|
||||
current])
|
||||
offset = 0x7fffffffffffffff & \
|
||||
random.choice([selector(current, constraints), current])
|
||||
is_cow = random.randint(0, 1)
|
||||
return offset + (is_cow << UINT64_M)
|
||||
|
||||
@ -344,9 +343,8 @@ def l2_entry(current):
|
||||
constraints = UINT64_V
|
||||
# Reserved bits are ignored
|
||||
# Add a possibility when only flags are fuzzed
|
||||
offset = 0x3ffffffffffffffe & random.choice([selector(current,
|
||||
constraints),
|
||||
current])
|
||||
offset = 0x3ffffffffffffffe & \
|
||||
random.choice([selector(current, constraints), current])
|
||||
is_compressed = random.randint(0, 1)
|
||||
is_cow = random.randint(0, 1)
|
||||
is_zero = random.randint(0, 1)
|
||||
|
@ -70,7 +70,7 @@ def run_app(fd, q_args):
|
||||
"""Exception for signal.alarm events."""
|
||||
pass
|
||||
|
||||
def handler(*arg):
|
||||
def handler(*args):
|
||||
"""Notify that an alarm event occurred."""
|
||||
raise Alarm
|
||||
|
||||
@ -134,8 +134,8 @@ class TestEnv(object):
|
||||
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 @@ class TestEnv(object):
|
||||
|
||||
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 @@ class TestEnv(object):
|
||||
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 @@ class TestEnv(object):
|
||||
"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 @@ if __name__ == '__main__':
|
||||
|
||||
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 @@ if __name__ == '__main__':
|
||||
|
||||
'--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 @@ if __name__ == '__main__':
|
||||
seed = None
|
||||
config = None
|
||||
duration = None
|
||||
|
||||
for opt, arg in opts:
|
||||
if opt in ('-h', '--help'):
|
||||
usage()
|
||||
|
Loading…
Reference in New Issue
Block a user