Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
scripts/qemu.py: Add arch parameter and automatic arch guessing
The binary parameter is mandatory, and central to QEMUMachine usage. Some information, such as the intended architecture, can either be given explicitly, or can be extracted from the binary itself. This change provides a generic function, qmp_execute(), that executes a QEMU binary with the sole purpose of retrieving information from a binary. This function is then applied to query the target name from the given binary and use it as the architecture on QEMUMachine. Given that many tests depend on the current behavior, and for the sake of clarity, the automatic setting of the archicture is not done by default, it requires the "automatic_devices=True" to be given as a parameter to QEMUMachine. Signed-off-by: Cleber Rosa <crosa@redhat.com>
- Loading branch information
Showing
2 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import sys | ||
| import os | ||
| import glob | ||
| import unittest | ||
|
|
||
| from qemu import qemu_bin_arch | ||
|
|
||
|
|
||
| def get_built_qemu_binaries(src_root=None): | ||
| if src_root is None: | ||
| src_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
| binaries = glob.glob(os.path.join(src_root, '*-softmmu/qemu-system-*')) | ||
| if 'win' in sys.platform: | ||
| bin_filter = lambda x: x.endswith(".exe") | ||
| else: | ||
| bin_filter = lambda x: not x.endswith(".exe") | ||
| return [_ for _ in binaries if bin_filter(_)] | ||
|
|
||
|
|
||
| class QEMU(unittest.TestCase): | ||
|
|
||
| @unittest.skipUnless(get_built_qemu_binaries(), | ||
| "Could not find any QEMU binaries built to use on " | ||
| "arch check") | ||
| def test_qemu_bin_arch(self): | ||
| """ | ||
| Checks that the qemu_bin_arch returns the expected architecture name | ||
| To avoid duplication of information, we assume the archicture matches | ||
| the last part of the binary name. | ||
| """ | ||
| for binary in get_built_qemu_binaries(): | ||
| self.assertEqual(qemu_bin_arch(binary), | ||
| binary.split('-')[-1].split(".exe")[0]) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |