Skip to content

Commit

Permalink
Merge pull request #1128 from ypu/bugfix
Browse files Browse the repository at this point in the history
Some small bug fixes for qemu tests (floppy, ksm_base, seabios).
  • Loading branch information
ruda committed Dec 2, 2013
2 parents a1e3e21 + 0610bab commit 514ab22
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
1 change: 0 additions & 1 deletion qemu/tests/cfg/floppy_test.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
- floppy_test: install setup image_copy unattended_install.cdrom
only Linux
type = floppy
start_vm = no
floppies = "fl"
Expand Down
2 changes: 1 addition & 1 deletion qemu/tests/floppy.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test(self):
vm.verify_alive()
self.session = vm.wait_for_login(timeout=login_timeout)

self.dest_dir = params["mount_dir"]
self.dest_dir = params.get("mount_dir")
# If mount_dir specified, treat guest as a Linux OS
# Some Linux distribution does not load floppy at boot and Windows
# needs time to load and init floppy driver
Expand Down
10 changes: 8 additions & 2 deletions qemu/tests/ksm_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from virttest import aexpect, utils_test, utils_misc, data_dir


TMPFS_OVERHEAD = 0.0022


@error.context_aware
def run_ksm_base(test, params, env):
"""
Expand Down Expand Up @@ -64,6 +67,7 @@ def _execute_allocator(command, vm, session, timeout):
return (match, data)

timeout = float(params.get("login_timeout", 240))
guest_script_overhead = int(params.get("guest_script_overhead", 5))
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
session = vm.wait_for_login(timeout=timeout)
Expand All @@ -79,9 +83,11 @@ def _execute_allocator(command, vm, session, timeout):
get_free_mem_cmd = params.get("get_free_mem_cmd",
"grep MemFree /proc/meminfo")
free_mem = vm.get_memory_size(get_free_mem_cmd)
max_mem = int(free_mem / (1 + TMPFS_OVERHEAD) - guest_script_overhead)

# Keep test from OOM killer
if free_mem < shared_mem:
shared_mem = free_mem
if max_mem < shared_mem:
shared_mem = max_mem
fill_timeout = int(shared_mem) / 10
query_cmd = params.get("query_cmd")
query_regex = params.get("query_regex")
Expand Down
24 changes: 15 additions & 9 deletions qemu/tests/seabios.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def run_seabios(test, params, env):
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment.
"""
def get_output(session_obj):
"""
Use the function to short the lines in the scripts
"""
return session_obj.get_stripped_output()

error.context("Start guest with sga bios")
vm = env.get_vm(params["main_vm"])
# Since the seabios is displayed in the beginning of guest boot,
Expand All @@ -40,41 +46,41 @@ def run_seabios(test, params, env):
error.context("Display and check the SGABIOS info", logging.info)
info_check = lambda: (len(info_list) ==
len([x for x in info_list
if x in vm.serial_console.get_output()]))
if x in get_output(vm.serial_console)]))

if not utils_misc.wait_for(info_check, timeout, 1):
raise error.TestFail("Cound not get sgabios message. The output"
" is %s" % vm.serial_console.get_output())
err_msg = "Cound not get sgabios message. The output"
err_msg += " is %s" % get_output(vm.serial_console)
raise error.TestFail(err_msg)

if restart_key:
error.context("Restart vm and check it's ok", logging.info)
boot_menu = lambda: re.search(boot_menu_hint,
seabios_session.get_output())
get_output(seabios_session))
if not (boot_menu_hint and utils_misc.wait_for(boot_menu, timeout, 1)):
raise error.TestFail("Could not get boot menu message.")

seabios_text = seabios_session.get_output()
seabios_text = get_output(seabios_session)
headline = seabios_text.split("\n")[0] + "\n"
headline_count = seabios_text.count(headline)

vm.send_key(restart_key)
reboot_check = lambda: (seabios_session.get_output().count(headline)
reboot_check = lambda: (get_output(seabios_session).count(headline)
> headline_count)

if not utils_misc.wait_for(reboot_check, timeout, 1):
raise error.TestFail("Could not restart the vm")

error.context("Display and check the boot menu order", logging.info)
boot_menu = lambda: re.search(boot_menu_hint,
seabios_session.get_output())
boot_menu = lambda: re.search(boot_menu_hint, get_output(seabios_session))
if not (boot_menu_hint and utils_misc.wait_for(boot_menu, timeout, 1)):
raise error.TestFail("Could not get boot menu message.")

# Send boot menu key in monitor.
vm.send_key(boot_menu_key)

get_list = lambda: re.findall("^\d+\. (.*)\s",
seabios_session.get_output(), re.M)
get_output(seabios_session), re.M)
boot_list = utils_misc.wait_for(get_list, timeout, 1)

if not boot_list:
Expand Down
16 changes: 7 additions & 9 deletions virttest/qemu_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,18 +337,13 @@ def support_cmd(self, cmd):

return supports_cmd

def compare_images(self, image1, image2):
def compare_images(self, image1, image2, verbose=True):
"""
Compare 2 images using the appropriate tools for each virt backend.
:param params: Dictionary containing the test parameters.
:param root_dir: Base directory for relative filenames.
:note: params should contain:
image_name -- the name of the image file, without extension
image_format -- the format of the image (qcow2, raw etc)
:raise VMImageCheckError: In case qemu-img check fails on the image.
:param image1: image path of first image
:param image2: image path of second image
:param verbose: Record output in debug file or not
"""
compare_images = self.support_cmd("compare")
if not compare_images:
Expand All @@ -359,6 +354,9 @@ def compare_images(self, image1, image2):
compare_cmd = "%s compare %s %s" % (self.image_cmd, image1, image2)
rv = utils.run(compare_cmd, ignore_status=True)

if verbose:
logging.debug("Output from command: %s" % rv.stdout)

if rv.exit_status == 0:
logging.info("Compared images are equal")
elif rv.exit_status == 1:
Expand Down

0 comments on commit 514ab22

Please sign in to comment.