Skip to content

Commit 6b07275

Browse files
committed
tests: test_feat_parity.py: use fixtures instead of MicrovmBuilder
While working on other changes, the `import from conftest` started failing, so move it over to just using plain fixtures. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent d8e873e commit 6b07275

File tree

3 files changed

+56
-90
lines changed

3 files changed

+56
-90
lines changed

tests/conftest.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_with_any_microvm(test_microvm_any):
9494

9595
import host_tools.cargo_build as build_tools
9696
from framework import defs, utils
97-
from framework.artifacts import ArtifactCollection, FirecrackerArtifact
97+
from framework.artifacts import ArtifactCollection, DiskArtifact, FirecrackerArtifact
9898
from framework.defs import _test_images_s3_bucket
9999
from framework.microvm import Microvm
100100
from framework.properties import global_props
@@ -499,6 +499,22 @@ def rootfs(request, record_property):
499499
return fs
500500

501501

502+
@pytest.fixture(
503+
params=ARTIFACTS_COLLECTION.disks("bionic-msrtools"),
504+
ids=lambda fs: fs.name() if isinstance(fs, DiskArtifact) else None,
505+
)
506+
def rootfs_msrtools(request, record_property):
507+
"""Common disk fixture for tests needing msrtools
508+
509+
When we regenerate the rootfs, we should include this always
510+
"""
511+
fs = request.param
512+
record_property("rootfs", fs.name())
513+
fs.download()
514+
fs.ssh_key().download()
515+
return fs
516+
517+
502518
@pytest.fixture(params=SUPPORTED_CPU_TEMPLATES)
503519
def cpu_template(request, record_property):
504520
"""Return all CPU templates supported by the vendor."""

tests/framework/microvm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from functools import cached_property
2323
from pathlib import Path
2424
from threading import Lock
25+
from typing import Optional
2526

2627
from retry import retry
2728

@@ -539,6 +540,7 @@ def basic_config(
539540
use_initrd: bool = False,
540541
track_dirty_pages: bool = False,
541542
rootfs_io_engine=None,
543+
cpu_template: Optional[str] = None,
542544
):
543545
"""Shortcut for quickly configuring a microVM.
544546
@@ -556,6 +558,7 @@ def basic_config(
556558
smt=smt,
557559
mem_size_mib=mem_size_mib,
558560
track_dirty_pages=track_dirty_pages,
561+
cpu_template=cpu_template,
559562
)
560563
assert self._api_session.is_status_no_content(
561564
response.status_code

tests/integration_tests/functional/test_feat_parity.py

Lines changed: 36 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,16 @@
66
import pytest
77

88
import framework.utils_cpuid as cpuid_utils
9-
from conftest import ARTIFACTS_COLLECTION
10-
from framework.artifacts import DiskArtifact
11-
from framework.builder import MicrovmBuilder
9+
from framework.properties import global_props
1210
from framework.utils_cpu_templates import SUPPORTED_CPU_TEMPLATES
1311

14-
# CPU templates designed to provide instruction set feature parity
15-
INST_SET_TEMPLATES = ["T2A", "T2CL"]
16-
17-
18-
@pytest.fixture(name="vm_builder", scope="session")
19-
def vm_builder_fxt(bin_cloner_path):
20-
"""Return a microvm builder."""
21-
return MicrovmBuilder(bin_cloner_path)
22-
23-
24-
@pytest.fixture(
25-
name="microvm",
26-
params=ARTIFACTS_COLLECTION.microvms(keyword="1vcpu_1024mb"),
27-
ids=lambda uvm: uvm.name(),
12+
pytestmark = pytest.mark.skipif(
13+
global_props.cpu_architecture != "x86_64", reason="x86_64 specific tests"
2814
)
29-
def microvm_fxt(request):
30-
"""Common microvm fixture for tests in this file"""
31-
uvm = request.param
32-
uvm.download()
33-
return uvm
3415

3516

36-
@pytest.fixture(
37-
name="disk",
38-
params=ARTIFACTS_COLLECTION.disks(keyword="bionic-msrtools"),
39-
ids=lambda disk: disk.name() if isinstance(disk, DiskArtifact) else None,
40-
)
41-
def disk_fxt(request):
42-
"""Common disk fixture for tests in this file"""
43-
disk = request.param
44-
disk.download()
45-
return disk
17+
# CPU templates designed to provide instruction set feature parity
18+
INST_SET_TEMPLATES = ["T2A", "T2CL"]
4619

4720

4821
@pytest.fixture(
@@ -54,41 +27,29 @@ def inst_set_cpu_template_fxt(request):
5427
return request.param
5528

5629

57-
@pytest.fixture(
58-
name="inst_set_cpu_template_ext",
59-
params=set(SUPPORTED_CPU_TEMPLATES).intersection(INST_SET_TEMPLATES + ["T2"]),
60-
)
61-
def inst_set_cpu_template_ext_fxt(request):
62-
"""CPU template fixture for instruction set feature parity templates plus T2"""
63-
return request.param
64-
65-
66-
def create_vm(vm_builder, cpu_template, microvm, kernel, disk):
30+
@pytest.fixture(name="vm")
31+
def vm_fxt(
32+
microvm_factory,
33+
inst_set_cpu_template,
34+
guest_kernel,
35+
rootfs_msrtools,
36+
network_config,
37+
):
6738
"""
68-
Create a VM.
39+
Create a VM, using the normal CPU templates
6940
"""
70-
root_disk = disk.copy()
71-
vm_instance = vm_builder.build(
72-
kernel=kernel,
73-
disks=[root_disk],
74-
ssh_key=disk.ssh_key(),
75-
config=microvm,
76-
cpu_template=cpu_template,
77-
)
78-
vm = vm_instance.vm
79-
41+
vm = microvm_factory.build(guest_kernel, rootfs_msrtools)
42+
vm.spawn()
43+
vm.basic_config(vcpu_count=1, mem_size_mib=1024, cpu_template=inst_set_cpu_template)
44+
vm.ssh_network_config(network_config, "1")
45+
vm.start()
8046
return vm
8147

8248

83-
def check_cpuid_feat_flags(
84-
vm_builder, cpu_template, microvm, kernel, disk, must_be_set, must_be_unset
85-
):
49+
def check_cpuid_feat_flags(vm, must_be_set, must_be_unset):
8650
"""
8751
Check that CPUID feature flag are set and unset as expected.
8852
"""
89-
vm = create_vm(vm_builder, cpu_template, microvm, kernel, disk)
90-
vm.start()
91-
9253
cpuid = cpuid_utils.get_guest_cpuid(vm)
9354
allowed_regs = ["eax", "ebx", "ecx", "edx"]
9455

@@ -109,7 +70,7 @@ def check_cpuid_feat_flags(
10970
), f"{leaf=:#x} {subleaf=:#x} {reg=} {actual=:#x}, {expected=:#x}"
11071

11172

112-
def test_feat_parity_cpuid_mpx(vm_builder, cpu_template, microvm, guest_kernel, disk):
73+
def test_feat_parity_cpuid_mpx(vm):
11374
"""
11475
Verify that MPX (Memory Protection Extensions) is not enabled in any of the supported CPU templates.
11576
@@ -125,19 +86,18 @@ def test_feat_parity_cpuid_mpx(vm_builder, cpu_template, microvm, guest_kernel,
12586
# fmt: on
12687

12788
check_cpuid_feat_flags(
128-
vm_builder,
129-
cpu_template,
130-
microvm,
131-
guest_kernel,
132-
disk,
89+
vm,
13390
must_be_set,
13491
must_be_unset,
13592
)
13693

13794

138-
def test_feat_parity_cpuid_inst_set(
139-
vm_builder, inst_set_cpu_template_ext, microvm, guest_kernel, disk
140-
):
95+
@pytest.mark.parametrize(
96+
"inst_set_cpu_template",
97+
set(SUPPORTED_CPU_TEMPLATES).intersection(INST_SET_TEMPLATES + ["T2"]),
98+
indirect=True,
99+
)
100+
def test_feat_parity_cpuid_inst_set(vm):
141101
"""
142102
Verify that CPUID feature flags related to instruction sets are properly set
143103
for T2, T2CL and T2A CPU templates.
@@ -209,19 +169,13 @@ def test_feat_parity_cpuid_inst_set(
209169
# fmt: on
210170

211171
check_cpuid_feat_flags(
212-
vm_builder,
213-
inst_set_cpu_template_ext,
214-
microvm,
215-
guest_kernel,
216-
disk,
172+
vm,
217173
must_be_set,
218174
must_be_unset,
219175
)
220176

221177

222-
def test_feat_parity_cpuid_sec(
223-
vm_builder, inst_set_cpu_template, microvm, guest_kernel, disk
224-
):
178+
def test_feat_parity_cpuid_sec(vm):
225179
"""
226180
Verify that security-related CPUID feature flags are properly set
227181
for T2CL and T2A CPU templates.
@@ -297,32 +251,25 @@ def test_feat_parity_cpuid_sec(
297251
raise Exception("Unsupported CPU vendor.")
298252

299253
check_cpuid_feat_flags(
300-
vm_builder,
301-
inst_set_cpu_template,
302-
microvm,
303-
guest_kernel,
304-
disk,
254+
vm,
305255
must_be_set,
306256
must_be_unset,
307257
)
308258

309259

310-
def test_feat_parity_msr_arch_cap(
311-
vm_builder, inst_set_cpu_template, microvm, guest_kernel, disk
312-
):
260+
def test_feat_parity_msr_arch_cap(vm):
313261
"""
314262
Verify availability and value of the IA32_ARCH_CAPABILITIES MSR for T2CL and T2A CPU templates.
315263
316264
@type: functional
317265
"""
318-
vm = create_vm(vm_builder, inst_set_cpu_template, microvm, guest_kernel, disk)
319-
vm.start()
320-
321266
arch_capabilities_addr = "0x10a"
322267
rdmsr_cmd = f"rdmsr {arch_capabilities_addr}"
323268
_, stdout, stderr = vm.ssh.execute_command(rdmsr_cmd)
324269

325-
if inst_set_cpu_template == "T2CL":
270+
cpu_template = vm.full_cfg.get().json()["machine-config"]["cpu_template"]
271+
272+
if cpu_template == "T2CL":
326273
assert stderr.read() == ""
327274
actual = int(stdout.read().strip(), 16)
328275
# fmt: off
@@ -336,6 +283,6 @@ def test_feat_parity_msr_arch_cap(
336283
)
337284
# fmt: on
338285
assert actual == expected, f"{actual=:#x} != {expected=:#x}"
339-
elif inst_set_cpu_template == "T2A":
286+
elif cpu_template == "T2A":
340287
# IA32_ARCH_CAPABILITIES shall not be available
341288
assert stderr.read() != ""

0 commit comments

Comments
 (0)