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(+) diff --git a/tests/functional/aarch64/test_kvm.py b/tests/functional/aarch64/test_kvm.py index 7545f5ed554..b26c849ec67 100755 --- a/tests/functional/aarch64/test_kvm.py +++ b/tests/functional/aarch64/test_kvm.py @@ -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() -- 2.52.0
