1 # Test class and utilities for functional tests
3 # Copyright (c) 2018 Red Hat, Inc.
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.
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():
28 Picks the path of a QEMU binary, starting either in the current working
29 directory or in the source tree root directory.
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
):
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
)
53 if self
.vm
is not None: