hw/arm/mps2-tz: Replace init_sysbus_child() with sysbus_init_child_obj()
[qemu.git] / tests / acceptance / avocado_qemu / __init__.py
blob1e54fd59329895ef41ccdc02765b3bab6cd43adf
1 # Test class and utilities for functional tests
3 # Copyright (c) 2018 Red Hat, Inc.
5 # Author:
6 # Cleber Rosa <crosa@redhat.com>
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.
11 import os
12 import sys
14 import avocado
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'))
20 from qemu import QEMUMachine
22 def is_readable_executable_file(path):
23 return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK)
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
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
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)
52 def tearDown(self):
53 if self.vm is not None:
54 self.vm.shutdown()