tests/functional: Check for nested virtualization to run KVM tests
PATCH 1/1 tests/functional: Check for nested virtualization to run KVM tests
On Apple Silicon, nested virtualization starts to be usable with M3 models and later. Check for the CPU model to avoid failure on pre-M3:
qemu-system-aarch64: unable to find CPU model 'cortex-a72'
Now tests are correctly skipped, i.e. on M1:
ok 1 test_kvm.Aarch64VirtKVMTests.test_aarch64_nvhe_selftest # SKIP Nested Virtualization not available on Apple M1 Pro ok 2 test_kvm.Aarch64VirtKVMTests.test_aarch64_vhe_selftest # SKIP Nested Virtualization not available on Apple M1 Pro
--- tests/functional/aarch64/test_kvm.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
tests/functional/aarch64/test_kvm.py +23 -0
@@ -29,8 +29,31 @@ class Aarch64VirtKVMTests(LinuxKernelTest): # base of tests KUT_BASE = "/usr/share/kvm-unit-tests/" + def require_nested_virtualization(self): + """ + Requires the accelerator to support nested virtualization for the test + to continue + + If the check fails, the test is canceled. + """ + import platform, re, subprocess + + if platform.system() != 'Darwin': + return + r = subprocess.run(['sysctl', '-n', 'machdep.cpu.brand_string'], + text=True, capture_output=True) + if r.returncode != 0: + return + m = re.match(r"Apple M(\d+)( .*)?", r.stdout) + if m: + if int(m.group(1)) < 3: + self.skipTest("Nested Virtualization not available" + " on %s" % r.stdout.strip()) + def _launch_guest(self, kvm_mode="nvhe"): + self.require_nested_virtualization() + self.set_machine('virt') kernel_path = self.ASSET_KVM_TEST_KERNEL.fetch()
Signature · 1 line
2.52.0
Quoted 30 lines · Philippe Mathieu-Daudé
On Apple Silicon, nested virtualization starts to be usable with M3 models and later. Check for the CPU model to avoid failure on pre-M3:
qemu-system-aarch64: unable to find CPU model 'cortex-a72'
Now tests are correctly skipped, i.e. on M1:
ok 1 test_kvm.Aarch64VirtKVMTests.test_aarch64_nvhe_selftest # SKIP Nested Virtualization not available on Apple M1 Pro ok 2 test_kvm.Aarch64VirtKVMTests.test_aarch64_vhe_selftest # SKIP Nested Virtualization not available on Apple M1 Pro
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/functional/aarch64/test_kvm.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)tests/functional/aarch64/test_kvm.py +6
-0@@ -29,8 +29,31 @@ class Aarch64VirtKVMTests(LinuxKernelTest): # base of tests KUT_BASE = "/usr/share/kvm-unit-tests/" + def require_nested_virtualization(self): + """ + Requires the accelerator to support nested virtualization for the test + to continue + + If the check fails, the test is canceled.
tests/functional/aarch64/test_kvm.py class Aarch64VirtKVMTests(LinuxKernelTest): · line 47
Quoted 10 lines
tests/functional/aarch64/test_kvm.py +10
-0+ """ + import platform, re, subprocess + + if platform.system() != 'Darwin': + return + r = subprocess.run(['sysctl', '-n', 'machdep.cpu.brand_string'], + text=True, capture_output=True) + if r.returncode != 0: + return + m = re.match(r"Apple M(\d+)( .*)?", r.stdout)
I tend to prefer check_call/check_output over the plain 'run', in this case check_output is suitble
try
data = subprocess.check_output([..args..], encoding='utf8')
except CalledProcessError
return
m = re.match(r"Apple M(\d+)( .*)?", data)tests/functional/aarch64/test_kvm.py class Aarch64VirtKVMTests(LinuxKernelTest): · line 51
Quoted 4 lines
tests/functional/aarch64/test_kvm.py +4
-0+ if m: + if int(m.group(1)) < 3: + self.skipTest("Nested Virtualization not available" + " on %s" % r.stdout.strip())
Please add this as a decorator in tests/functional/qemu_tests/decorators.py called something like "skipUnlessNestedVirtSupported".
Quoted 12 lines
tests/functional/aarch64/test_kvm.py +3
-0+ def _launch_guest(self, kvm_mode="nvhe"): + self.require_nested_virtualization() + self.set_machine('virt') kernel_path = self.ASSET_KVM_TEST_KERNEL.fetch()Signature · 1 line
2.52.0
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|