]> git.proxmox.com Git - mirror_qemu.git/blob - tests/acceptance/avocado_qemu/__init__.py
Merge remote-tracking branch 'remotes/kraxel/tags/input-20180618-pull-request' into...
[mirror_qemu.git] / tests / acceptance / avocado_qemu / __init__.py
1 # Test class and utilities for functional tests
2 #
3 # Copyright (c) 2018 Red Hat, Inc.
4 #
5 # Author:
6 # Cleber Rosa <crosa@redhat.com>
7 #
8 # This work is licensed under the terms of the GNU GPL, version 2 or
9 # later. See the COPYING file in the top-level directory.
10
11 import os
12 import sys
13
14 import avocado
15
16 SRC_ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
17 SRC_ROOT_DIR = os.path.abspath(os.path.dirname(SRC_ROOT_DIR))
18 sys.path.append(os.path.join(SRC_ROOT_DIR, 'scripts'))
19
20 from qemu import QEMUMachine
21
22 def is_readable_executable_file(path):
23 return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK)
24
25
26 def pick_default_qemu_bin():
27 """
28 Picks the path of a QEMU binary, starting either in the current working
29 directory or in the source tree root directory.
30 """
31 arch = os.uname()[4]
32 qemu_bin_relative_path = os.path.join("%s-softmmu" % arch,
33 "qemu-system-%s" % arch)
34 if is_readable_executable_file(qemu_bin_relative_path):
35 return qemu_bin_relative_path
36
37 qemu_bin_from_src_dir_path = os.path.join(SRC_ROOT_DIR,
38 qemu_bin_relative_path)
39 if is_readable_executable_file(qemu_bin_from_src_dir_path):
40 return qemu_bin_from_src_dir_path
41
42
43 class Test(avocado.Test):
44 def setUp(self):
45 self.vm = None
46 self.qemu_bin = self.params.get('qemu_bin',
47 default=pick_default_qemu_bin())
48 if self.qemu_bin is None:
49 self.cancel("No QEMU binary defined or found in the source tree")
50 self.vm = QEMUMachine(self.qemu_bin)
51
52 def tearDown(self):
53 if self.vm is not None:
54 self.vm.shutdown()