mirror of https://github.com/xemu-project/xemu.git
tests/avocado: Extract QemuBaseTest from Test
The Avocado Test::fetch_asset() is handy to download artifacts before running tests. The current class is named Test but only tests system emulation. As we want to test user emulation, refactor the common code as QemuBaseTest. Reviewed-by: Willian Rampazzo <willianr@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20211105143416.148332-2-f4bug@amsat.org>
This commit is contained in:
parent
bbbd9b6ec6
commit
3982feb476
|
@ -169,7 +169,7 @@ def exec_command_and_wait_for_pattern(test, command,
|
||||||
"""
|
"""
|
||||||
_console_interaction(test, success_message, failure_message, command + '\r')
|
_console_interaction(test, success_message, failure_message, command + '\r')
|
||||||
|
|
||||||
class Test(avocado.Test):
|
class QemuBaseTest(avocado.Test):
|
||||||
def _get_unique_tag_val(self, tag_name):
|
def _get_unique_tag_val(self, tag_name):
|
||||||
"""
|
"""
|
||||||
Gets a tag value, if unique for a key
|
Gets a tag value, if unique for a key
|
||||||
|
@ -179,6 +179,46 @@ class Test(avocado.Test):
|
||||||
return vals.pop()
|
return vals.pop()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.arch = self.params.get('arch',
|
||||||
|
default=self._get_unique_tag_val('arch'))
|
||||||
|
|
||||||
|
self.cpu = self.params.get('cpu',
|
||||||
|
default=self._get_unique_tag_val('cpu'))
|
||||||
|
|
||||||
|
default_qemu_bin = pick_default_qemu_bin(arch=self.arch)
|
||||||
|
self.qemu_bin = self.params.get('qemu_bin',
|
||||||
|
default=default_qemu_bin)
|
||||||
|
if self.qemu_bin is None:
|
||||||
|
self.cancel("No QEMU binary defined or found in the build tree")
|
||||||
|
|
||||||
|
def fetch_asset(self, name,
|
||||||
|
asset_hash=None, algorithm=None,
|
||||||
|
locations=None, expire=None,
|
||||||
|
find_only=False, cancel_on_missing=True):
|
||||||
|
return super().fetch_asset(name,
|
||||||
|
asset_hash=asset_hash,
|
||||||
|
algorithm=algorithm,
|
||||||
|
locations=locations,
|
||||||
|
expire=expire,
|
||||||
|
find_only=find_only,
|
||||||
|
cancel_on_missing=cancel_on_missing)
|
||||||
|
|
||||||
|
|
||||||
|
class Test(QemuBaseTest):
|
||||||
|
"""Facilitates system emulation tests.
|
||||||
|
|
||||||
|
TODO: Rename this class as `QemuSystemTest`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self._vms = {}
|
||||||
|
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
self.machine = self.params.get('machine',
|
||||||
|
default=self._get_unique_tag_val('machine'))
|
||||||
|
|
||||||
def require_accelerator(self, accelerator):
|
def require_accelerator(self, accelerator):
|
||||||
"""
|
"""
|
||||||
Requires an accelerator to be available for the test to continue
|
Requires an accelerator to be available for the test to continue
|
||||||
|
@ -201,24 +241,6 @@ class Test(avocado.Test):
|
||||||
self.cancel("%s accelerator does not seem to be "
|
self.cancel("%s accelerator does not seem to be "
|
||||||
"available" % accelerator)
|
"available" % accelerator)
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self._vms = {}
|
|
||||||
|
|
||||||
self.arch = self.params.get('arch',
|
|
||||||
default=self._get_unique_tag_val('arch'))
|
|
||||||
|
|
||||||
self.cpu = self.params.get('cpu',
|
|
||||||
default=self._get_unique_tag_val('cpu'))
|
|
||||||
|
|
||||||
self.machine = self.params.get('machine',
|
|
||||||
default=self._get_unique_tag_val('machine'))
|
|
||||||
|
|
||||||
default_qemu_bin = pick_default_qemu_bin(arch=self.arch)
|
|
||||||
self.qemu_bin = self.params.get('qemu_bin',
|
|
||||||
default=default_qemu_bin)
|
|
||||||
if self.qemu_bin is None:
|
|
||||||
self.cancel("No QEMU binary defined or found in the build tree")
|
|
||||||
|
|
||||||
def _new_vm(self, name, *args):
|
def _new_vm(self, name, *args):
|
||||||
self._sd = tempfile.TemporaryDirectory(prefix="avo_qemu_sock_")
|
self._sd = tempfile.TemporaryDirectory(prefix="avo_qemu_sock_")
|
||||||
vm = QEMUMachine(self.qemu_bin, base_temp_dir=self.workdir,
|
vm = QEMUMachine(self.qemu_bin, base_temp_dir=self.workdir,
|
||||||
|
@ -272,18 +294,6 @@ class Test(avocado.Test):
|
||||||
self._sd = None
|
self._sd = None
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
def fetch_asset(self, name,
|
|
||||||
asset_hash=None, algorithm=None,
|
|
||||||
locations=None, expire=None,
|
|
||||||
find_only=False, cancel_on_missing=True):
|
|
||||||
return super().fetch_asset(name,
|
|
||||||
asset_hash=asset_hash,
|
|
||||||
algorithm=algorithm,
|
|
||||||
locations=locations,
|
|
||||||
expire=expire,
|
|
||||||
find_only=find_only,
|
|
||||||
cancel_on_missing=cancel_on_missing)
|
|
||||||
|
|
||||||
|
|
||||||
class LinuxSSHMixIn:
|
class LinuxSSHMixIn:
|
||||||
"""Contains utility methods for interacting with a guest via SSH."""
|
"""Contains utility methods for interacting with a guest via SSH."""
|
||||||
|
|
Loading…
Reference in New Issue