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.
17 SRC_ROOT_DIR
= os
.path
.join(os
.path
.dirname(__file__
), '..', '..', '..')
18 sys
.path
.append(os
.path
.join(SRC_ROOT_DIR
, 'python'))
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")
51 def _new_vm(self
, *args
):
52 vm
= QEMUMachine(self
.qemu_bin
)
59 return self
.get_vm(name
='default')
61 def get_vm(self
, *args
, name
=None):
63 name
= str(uuid
.uuid4())
64 if self
._vms
.get(name
) is None:
65 self
._vms
[name
] = self
._new
_vm
(*args
)
66 return self
._vms
[name
]
69 for vm
in self
._vms
.values():