Acceptance tests: boot Linux with KVM test
v4 cover Acceptance tests: boot Linux with KVM test
This adds boot Linux tests for x86_64, aarch64, ppc64, and s390x targets which, unlike others, enable the KVM acceleration. Likewise it was added test cases for tcg.
It is introduced an infraestructure on avocado_qemu framework so that:
a) simply tagging the test with accel:kvm (or accel:tcg) will automatically set the corresponding '-accel' on the launched QEMU;
b) test is canceled if the accelerator is not enabled on the QEMU binary or not available in the host. In special, it checks if SMT is disabled on POWER8.
The acceptance builder on Travis was changed too in order to make the test run.
Changes v3 -> v4:
- Broke changes per-arch to ease the reviews. Resulting on patches 02, 03, 05, 06.
- The test for aarch64 now passes '-cpu max' and -M 'virt,gic-version=max'. (patch 03) [drjones]
- Added a fix to accel.kvm_available() so that it detects correctly the availability of kvm on ppc64le. (patch 05)
- The test for ppc64le now checks if SMT is enabled on POWER8 then skip.
v3: [PATCH v3 0/4] Acceptance tests: boot Linux with KVM test
- https://www.mail-archive.com/[email protected]/msg672635.html
v2: [PATCH v2 0/3] Acceptance tests: boot Linux with KVM test
- https://www.mail-archive.com/[email protected]/msg666238.html
v1: [PATCH 0/3] Acceptance tests: boot Linux with KVM test
- https://www.mail-archive.com/[email protected]/msg627498.html
Tree:
- Git: https://github.com/wainersm/qemu
- Branch: acceptance_kvm_test-v4
CI:
- Travis (FAIL): https://travis-ci.org/wainersm/qemu/builds/646154220
Failed jobs are not related with this series changes.
Wainer dos Santos Moschetta (8):
tests/acceptance: avocado_qemu: Introduce the 'accel' test parameter tests/acceptance: boot_linux_console: Add boot Linux/x86 with KVM tests/acceptance: boot_linux_console: Add boot Linux/aarch64 with KVM python/qemu: accel: Fix kvm_available() on ppc64le test/acceptance: boot_linux_console: Add boot Linux/ppc64le with KVM tests/acceptance: boot_linux_console: Add boot Linux/s390x with KVM tests/acceptance: avocado_qemu: Refactor the handler of 'machine'
parameter
travis.yml: Enable acceptance KVM tests
.travis.yml | 7 +- docs/devel/testing.rst | 16 ++++ python/qemu/accel.py | 3 +- tests/acceptance/avocado_qemu/__init__.py | 27 +++++- tests/acceptance/boot_linux_console.py | 108 +++++++++++++++++----- 5 files changed, 136 insertions(+), 25 deletions(-)
Signature · 1 line
2.24.1
PATCH v4 1/8 tests/acceptance: avocado_qemu: Introduce the 'accel' test parameter
The test case may need to boot the VM with an accelerator that isn't actually enabled on the QEMU binary and/or present in the host. In this case the test behavior is undefined, and the best course of action is to skip its execution.
This change introduced the 'accel' parameter (and the handler of tag with same name) used to indicate the test case requires a given accelerator available. It was implemented a mechanism to skip the test case if the accelerator is not available. Moreover,
the QEMU -accel argument is set automatically to any VM
launched if the parameter is present.
--- docs/devel/testing.rst | 16 ++++++++++++++++ tests/acceptance/avocado_qemu/__init__.py | 23 +++++++++++++++++++++++ 2 files changed, 39 insertions(+)
docs/devel/testing.rst +16 -0
@@ -759,6 +759,17 @@ name. If one is not given explicitly, it will either be set to ``None``, or, if the test is tagged with one (and only one) ``:avocado: tags=machine:VALUE`` tag, it will be set to ``VALUE``. +accel +~~~~~ +The accelerator that will be set to all QEMUMachine instances created +by the test. + +The ``accel`` attribute will be set to the test parameter of the same +name. If one is not given explicitly, it will either be set to +``None``, or, if the test is tagged with one (and only one) +``:avocado: tags=accel:VALUE`` tag, it will be set to ``VALUE``. Currently +``VALUE`` should be either ``kvm`` or ``tcg``. + qemu_bin ~~~~~~~~
@@ -800,6 +811,11 @@ machine The machine type that will be set to all QEMUMachine instances created by the test. +accel +~~~~~ +The accelerator that will be set to all QEMUMachine instances created +by the test. In case the accelerator is not available (both QEMU +binary and the host system are checked) then the test is canceled. qemu_bin ~~~~~~~~
tests/acceptance/avocado_qemu/__init__.py +23 -0
@@ -20,6 +20,7 @@ SRC_ROOT_DIR = os.path.join(os.path.dirname(__file__), '..', '..', '..') sys.path.append(os.path.join(SRC_ROOT_DIR, 'python')) from qemu.machine import QEMUMachine +from qemu.accel import kvm_available, tcg_available def is_readable_executable_file(path): return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK)
@@ -111,6 +112,8 @@ class Test(avocado.Test): def setUp(self): self._vms = {} + # VM argumments that are mapped from parameters + self._param_to_vm_args = [] self.arch = self.params.get('arch', default=self._get_unique_tag_val('arch'))
@@ -124,10 +127,30 @@ class Test(avocado.Test): if self.qemu_bin is None: self.cancel("No QEMU binary defined or found in the source tree") + self.accel = self.params.get('accel', + default=self._get_unique_tag_val('accel')) + if self.accel: + avail = False + if self.accel == 'kvm': + if kvm_available(self.arch, self.qemu_bin): + avail = True + elif self.accel == 'tcg': + if tcg_available(self.qemu_bin): + avail = True + else: + self.cancel("Unknown accelerator: %s" % self.accel) + + if avail: + self._param_to_vm_args.extend(['-accel', self.accel]) + else: + self.cancel("%s is not available" % self.accel) + def _new_vm(self, *args): vm = QEMUMachine(self.qemu_bin, sock_dir=tempfile.mkdtemp()) if args: vm.add_args(*args) + if self._param_to_vm_args: + vm.add_args(*self._param_to_vm_args) return vm @property
Signature · 1 line
2.24.1
PATCH v4 2/8 tests/acceptance: boot_linux_console: Add boot Linux/x86 with KVM
In reply to Wainer dos Santos MoschettaAdded boot Linux on x86_64 test case that launch QEMU with KVM enabled. Likewise it was added one test for TCG.
--- tests/acceptance/boot_linux_console.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
tests/acceptance/boot_linux_console.py +17 -5
@@ -51,11 +51,7 @@ class BootLinuxConsole(Test): os.chdir(cwd) return self.workdir + path - def test_x86_64_pc(self): - """ - :avocado: tags=arch:x86_64 - :avocado: tags=machine:pc - """ + def do_test_x86_64_pc(self): kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' '/linux/releases/29/Everything/x86_64/os/images/pxeboot' '/vmlinuz')
@@ -70,6 +66,22 @@ class BootLinuxConsole(Test): console_pattern = 'Kernel command line: %s' % kernel_command_line self.wait_for_console_pattern(console_pattern) + def test_x86_64_pc_kvm(self): + """ + :avocado: tags=arch:x86_64 + :avocado: tags=machine:pc + :avocado: tags=accel:kvm + """ + self.do_test_x86_64_pc() + + def test_x86_64_pc_tcg(self): + """ + :avocado: tags=arch:x86_64 + :avocado: tags=machine:pc + :avocado: tags=accel:tcg + """ + self.do_test_x86_64_pc() + def test_mips_malta(self): """ :avocado: tags=arch:mips
Signature · 1 line
2.24.1
PATCH v4 3/8 tests/acceptance: boot_linux_console: Add boot Linux/aarch64 with KVM
In reply to Wainer dos Santos MoschettaThis split in two the boot Linux test for aarch64: one that uses KVM acceleration and another with TCG. It changes -cpu to 'max' which is a common match between kvm and tcg.
Note: on kvm test, even though it is tagged with 'machine:virt', it later has the value overwritten to pass the GIC version. The reason for that is an Avocado limitation, which is unable to parse correctly a tag containing ',' (this char being a tag delimiter). Keep the 'machine:virt' tag is still useful since it can be used on tests filtering.
--- tests/acceptance/boot_linux_console.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
tests/acceptance/boot_linux_console.py +19 -6
@@ -270,11 +270,7 @@ class BootLinuxConsole(Test): kernel_hash = '18d1c68f2e23429e266ca39ba5349ccd0aeb7180' self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash) - def test_aarch64_virt(self): - """ - :avocado: tags=arch:aarch64 - :avocado: tags=machine:virt - """ + def do_test_aarch64_virt(self): kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' '/linux/releases/29/Everything/aarch64/os/images/pxeboot' '/vmlinuz')
@@ -284,13 +280,30 @@ class BootLinuxConsole(Test): self.vm.set_console() kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyAMA0') - self.vm.add_args('-cpu', 'cortex-a53', + self.vm.add_args('-cpu', 'max', '-kernel', kernel_path, '-append', kernel_command_line) self.vm.launch() console_pattern = 'Kernel command line: %s' % kernel_command_line self.wait_for_console_pattern(console_pattern) + def test_aarch64_virt_kvm(self): + """ + :avocado: tags=arch:aarch64 + :avocado: tags=machine:virt + :avocado: tags=accel:kvm + """ + self.vm.set_machine('virt,gic-version=max') + self.do_test_aarch64_virt() + + def test_aarch64_virt_tcg(self): + """ + :avocado: tags=arch:aarch64 + :avocado: tags=machine:virt + :avocado: tags=accel:tcg + """ + self.do_test_aarch64_virt() + def test_arm_virt(self): """ :avocado: tags=arch:arm
Signature · 1 line
2.24.1
PATCH v4 4/8 python/qemu: accel: Fix kvm_available() on ppc64le
In reply to Wainer dos Santos MoschettaOn ppc64le, the accel.kvm_available() check may wrongly return False because the host arch (as returned by os.uname[4]) and the target arch (ppc64) mismatch. In order to solve this it is added an ppc64le -> ppc64 mapping which is used as an fallback verification.
--- python/qemu/accel.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
python/qemu/accel.py +2 -1
@@ -24,7 +24,8 @@ LOG = logging.getLogger(__name__) # support which often includes its 32 bit cousin. ADDITIONAL_ARCHES = { "x86_64" : "i386", - "aarch64" : "armhf" + "aarch64" : "armhf", + "ppc64le" : "ppc64", } def list_accel(qemu_bin):
Signature · 1 line
2.24.1
Re: [PATCH v4 4/8] python/qemu: accel: Fix kvm_available() on ppc64le
Quoted 18 lines · Wainer dos Santos Moschetta
On ppc64le, the
accel.kvm_available()check may wrongly return False because the host arch (as returned by os.uname[4]) and the target arch (ppc64) mismatch. In order to solve this it is added an ppc64le -> ppc64 mapping which is used as an fallback verification.Fixes 53a049d7d78e5ccf6d4c0d7Signed-off-by Wainer dos Santos Moschetta <[email protected]>--- python/qemu/accel.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)python/qemu/accel.py +0
-0
python/qemu/accel.py LOG = logging.getLogger(__name__) · line 31
Quoted 9 lines
python/qemu/accel.py +2
-1@@ -24,7 +24,8 @@ LOG = logging.getLogger(__name__) # support which often includes its 32 bit cousin. ADDITIONAL_ARCHES = { "x86_64" : "i386", - "aarch64" : "armhf" + "aarch64" : "armhf", + "ppc64le" : "ppc64", } def list_accel(qemu_bin):
And applied to my python-next tree:
https://gitlab.com/philmd/qemu/commits/python-next
PATCH v4 5/8 test/acceptance: boot_linux_console: Add boot Linux/ppc64le with KVM
In reply to Wainer dos Santos MoschettaLikewise this splitted the boot Linux for ppc64le test in a version for KVM and another for TCG.
The kvm test case is designed to run on POWER8 or greater, otherwise it is skipped. The SMT should be off on POWER8, that is also checked.
--- tests/acceptance/boot_linux_console.py | 39 ++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-)
tests/acceptance/boot_linux_console.py +34 -5
@@ -19,6 +19,8 @@ from avocado_qemu import exec_command_and_wait_for_pattern from avocado_qemu import wait_for_console_pattern from avocado.utils import process from avocado.utils import archive +from avocado.utils.cpu import get_cpu_vendor_name +from avocado.utils.path import find_command class BootLinuxConsole(Test):
@@ -551,11 +553,7 @@ class BootLinuxConsole(Test): console_pattern = 'Kernel command line: %s' % kernel_command_line self.wait_for_console_pattern(console_pattern) - def test_ppc64_pseries(self): - """ - :avocado: tags=arch:ppc64 - :avocado: tags=machine:pseries - """ + def do_test_ppc64_pseries(self): kernel_url = ('https://archives.fedoraproject.org/pub/archive' '/fedora-secondary/releases/29/Everything/ppc64le/os' '/ppc/ppc64/vmlinuz')
@@ -570,6 +568,37 @@ class BootLinuxConsole(Test): console_pattern = 'Kernel command line: %s' % kernel_command_line self.wait_for_console_pattern(console_pattern) + @skipUnless(find_command('ppc64_cpu', default=False)) + def test_ppc64_pseries_kvm(self): + """ + :avocado: tags=arch:ppc64 + :avocado: tags=machine:pseries + :avocado: tags=accel:kvm + + It assumes running on POWER8 or greater, otherwise skip the test. + If on POWER8 then SMT should be off, otherwise skip the test. + """ + cpu = get_cpu_vendor_name() + if not cpu.startswith('power'): + self.cancel('do not test with %s cpu' % cpu) + else: + version = int(cpu.replace('power', '')) + if version < 8: + self.cancel('cpu %s is not >= POWER8') + elif version == 8: + smt = process.run('ppc64_cpu --smt -n').stdout_text.strip() + if smt != 'SMT=1': + self.cancel('%s on POWER8' % smt) + self.do_test_ppc64_pseries() + + def test_ppc64_pseries_tcg(self): + """ + :avocado: tags=arch:ppc64 + :avocado: tags=machine:pseries + :avocado: tags=accel:tcg + """ + self.do_test_ppc64_pseries() + def test_m68k_q800(self): """ :avocado: tags=arch:m68k
Signature · 1 line
2.24.1
PATCH v4 6/8 tests/acceptance: boot_linux_console: Add boot Linux/s390x with KVM
In reply to Wainer dos Santos MoschettaYet another splitting of boot the Linux tests between KVM and TCG. This time for s390x.
--- tests/acceptance/boot_linux_console.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
tests/acceptance/boot_linux_console.py +17 -5
@@ -512,11 +512,7 @@ class BootLinuxConsole(Test): exec_command_and_wait_for_pattern(self, 'reboot', 'reboot: Restarting system') - def test_s390x_s390_ccw_virtio(self): - """ - :avocado: tags=arch:s390x - :avocado: tags=machine:s390-ccw-virtio - """ + def do_test_s390x_s390_ccw_virtio(self): kernel_url = ('https://archives.fedoraproject.org/pub/archive' '/fedora-secondary/releases/29/Everything/s390x/os/images' '/kernel.img')
@@ -532,6 +528,22 @@ class BootLinuxConsole(Test): console_pattern = 'Kernel command line: %s' % kernel_command_line self.wait_for_console_pattern(console_pattern) + def test_s390x_s390_ccw_virtio_kvm(self): + """ + :avocado: tags=arch:s390x + :avocado: tags=machine:s390-ccw-virtio + :avocado: tags=accel:kvm + """ + self.do_test_s390x_s390_ccw_virtio() + + def test_s390x_s390_ccw_virtio_tcg(self): + """ + :avocado: tags=arch:s390x + :avocado: tags=machine:s390-ccw-virtio + :avocado: tags=accel:tcg + """ + self.do_test_s390x_s390_ccw_virtio() + def test_alpha_clipper(self): """ :avocado: tags=arch:alpha
Signature · 1 line
2.24.1
PATCH v4 7/8 tests/acceptance: avocado_qemu: Refactor the handler of 'machine' parameter
In reply to Wainer dos Santos MoschettaThe Test._param_to_vm_args variable contain VM arguments that should be added at launch which were originated from test parameters. Use this variable to set -M from 'machine' parameter as well.
--- tests/acceptance/avocado_qemu/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tests/acceptance/avocado_qemu/__init__.py +2 -2
@@ -120,6 +120,8 @@ class Test(avocado.Test): self.machine = self.params.get('machine', default=self._get_unique_tag_val('machine')) + if self.machine: + self._param_to_vm_args.extend(['-M', self.machine]) default_qemu_bin = pick_default_qemu_bin(arch=self.arch) self.qemu_bin = self.params.get('qemu_bin',
@@ -162,8 +164,6 @@ class Test(avocado.Test): name = str(uuid.uuid4()) if self._vms.get(name) is None: self._vms[name] = self._new_vm(*args) - if self.machine is not None: - self._vms[name].set_machine(self.machine) return self._vms[name] def tearDown(self):
Signature · 1 line
2.24.1
Re: [PATCH v4 7/8] tests/acceptance: avocado_qemu: Refactor the handler of 'machine' parameter
Quoted 25 lines · Wainer dos Santos Moschetta
The Test._param_to_vm_args variable contain VM arguments that should be added at launch which were originated from test parameters. Use this variable to set -M from 'machine' parameter as well.
Signed-off-by Wainer dos Santos Moschetta <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>--- tests/acceptance/avocado_qemu/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tests/acceptance/avocado_qemu/__init__.py +2
-0@@ -120,6 +120,8 @@ class Test(avocado.Test): self.machine = self.params.get('machine', default=self._get_unique_tag_val('machine')) + if self.machine: + self._param_to_vm_args.extend(['-M', self.machine]) default_qemu_bin = pick_default_qemu_bin(arch=self.arch) self.qemu_bin = self.params.get('qemu_bin',
tests/acceptance/avocado_qemu/__init__.py class Test(avocado.Test): · line 169
Quoted 8 lines
tests/acceptance/avocado_qemu/__init__.py +0
-2@@ -162,8 +164,6 @@ class Test(avocado.Test): name = str(uuid.uuid4()) if self._vms.get(name) is None: self._vms[name] = self._new_vm(*args) - if self.machine is not None: - self._vms[name].set_machine(self.machine) return self._vms[name] def tearDown(self):
It would be cleaner if you add _param_to_vm_args[] with this fix as 1st patch of the series, then 2nd patch 'Introduce the 'accel' test parameter' on top.
PATCH v4 8/8 travis.yml: Enable acceptance KVM tests
In reply to Wainer dos Santos MoschettaSome acceptance tests require KVM or they are skipped. Travis enables nested virtualization by default with Ubuntu 18.04 (Bionic) on x86_64. So in order to run the kvm tests, this changed the acceptance builder to run in a Bionic VM. Also it was needed to ensure the current user has rw permission to /dev/kvm.
python3.5-venv is not packaged on Bionic. So it was replaced with python3.6-venv.
--- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
.travis.yml +6 -1
@@ -2,6 +2,7 @@ # Additional builds with specific requirements for a full VM need to # be added as additional matrix: entries later on dist: xenial +sudo: true language: c compiler: - gcc
@@ -83,6 +84,9 @@ git: before_script: - if command -v ccache ; then ccache --zero-stats ; fi + - if [[ -c /dev/kvm ]] && ! [[ -r /dev/kvm && -w /dev/kvm ]]; then + sudo chmod o+rw /dev/kvm ; + fi - mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} - ${SRC_DIR}/configure ${BASE_CONFIG} ${CONFIG} || { cat config.log && exit 1; } script:
@@ -272,12 +276,13 @@ matrix: - TEST_CMD="make check-acceptance" after_script: - python3 -c 'import json; r = json.load(open("tests/results/latest/results.json")); [print(t["logfile"]) for t in r["tests"] if t["status"] not in ("PASS", "SKIP")]' | xargs cat + dist: bionic addons: apt: packages: - python3-pil - python3-pip - - python3.5-venv + - python3.6-venv - tesseract-ocr - tesseract-ocr-eng
Signature · 1 line
2.24.1
Hi Wainer,
Quoted 52 lines · Wainer dos Santos Moschetta
This adds boot Linux tests for
x86_64, aarch64, ppc64, and s390x targets which, unlike others, enable the KVM acceleration. Likewise it was added test cases for tcg.It is introduced an infraestructure on
avocado_qemuframework so that:
a) simply tagging the test withaccel:kvm(oraccel:tcg) will automatically set the corresponding '-accel' on the launched QEMU;
b) test is canceled if the accelerator is not enabled on the QEMU binary or not available in the host. In special, it checks if SMT is disabled on POWER8.The acceptance builder on Travis was changed too in order to make the test run.
Changes v3 -> v4:
- Broke changes per-arch to ease the reviews. Resulting on patches 02, 03, 05, 06.
- The test for aarch64 now passes '-cpu max' and -M 'virt,gic-version=max'. (patch 03) [drjones]
- Added a fix toaccel.kvm_available()so that it detects correctly the availability of kvm on ppc64le. (patch 05)
- The test for ppc64le now checks if SMT is enabled on POWER8 then skip.v3: [PATCH v3 0/4] Acceptance tests: boot Linux with KVM test
- https://www.mail-archive.com/[email protected]/msg672635.html
v2: [PATCH v2 0/3] Acceptance tests: boot Linux with KVM test
- https://www.mail-archive.com/[email protected]/msg666238.html
v1: [PATCH 0/3] Acceptance tests: boot Linux with KVM test
- https://www.mail-archive.com/[email protected]/msg627498.htmlTree:
- Git: https://github.com/wainersm/qemu
- Branch: acceptance_kvm_test-v4CI:
- Travis (FAIL): https://travis-ci.org/wainersm/qemu/builds/646154220
Failed jobs are not related with this series changes.Wainer dos Santos Moschetta (8):
tests/acceptance:avocado_qemu: Introduce the 'accel' test parameter tests/acceptance:boot_linux_console: Add boot Linux/x86 with KVM tests/acceptance:boot_linux_console: Add boot Linux/aarch64 with KVM python/qemu: accel: Fixkvm_available()on ppc64le test/acceptance:boot_linux_console: Add boot Linux/ppc64le with KVM tests/acceptance:boot_linux_console: Add boot Linux/s390x with KVM tests/acceptance:avocado_qemu: Refactor the handler of 'machine'
parameter
travis.yml: Enable acceptance KVM tests
Quoted 6 lines
.travis.yml | 7 +- docs/devel/testing.rst | 16 ++++ python/qemu/accel.py | 3 +- tests/acceptance/avocado_qemu/__init__.py | 27 +++++- tests/acceptance/boot_linux_console.py | 108 +++++++++++++++++----- 5 files changed, 136 insertions(+), 25 deletions(-)
As I'm not sure this is the correct to do, I'll defer this review to Cleber. We can also have a look at it during the next Avocado call.