@@ -253,19 +253,10 @@ def test_brand_string(uvm_plain_any):
253253MSR_SUPPORTED_TEMPLATES = ["T2A" , "T2CL" , "T2S" ]
254254
255255
256- @pytest .fixture (
257- name = "msr_cpu_template" ,
258- params = sorted (set (SUPPORTED_CPU_TEMPLATES ).intersection (MSR_SUPPORTED_TEMPLATES )),
259- )
260- def msr_cpu_template_fxt (request ):
261- """CPU template fixture for MSR read/write supported CPU templates"""
262- return request .param
263-
264-
265256@pytest .mark .timeout (900 )
266257@pytest .mark .nonci
267258def test_cpu_rdmsr (
268- microvm_factory , msr_cpu_template , guest_kernel , rootfs , results_dir
259+ microvm_factory , cpu_template_any , guest_kernel , rootfs , results_dir
269260):
270261 """
271262 Test MSRs that are available to the guest.
@@ -298,14 +289,16 @@ def test_cpu_rdmsr(
298289 - All supported guest kernels and rootfs
299290 - Microvm: 1vCPU with 1024 MB RAM
300291 """
292+ cpu_template_name = get_cpu_template_name (cpu_template_any )
293+ if cpu_template_name not in MSR_SUPPORTED_TEMPLATES :
294+ pytest .skip (f"This test does not support { cpu_template_name } template." )
301295
302296 vcpus , guest_mem_mib = 1 , 1024
303297 vm = microvm_factory .build (guest_kernel , rootfs , monitor_memory = False )
304298 vm .spawn ()
305299 vm .add_net_iface ()
306- vm .basic_config (
307- vcpu_count = vcpus , mem_size_mib = guest_mem_mib , cpu_template = msr_cpu_template
308- )
300+ vm .basic_config (vcpu_count = vcpus , mem_size_mib = guest_mem_mib )
301+ vm .set_cpu_template (cpu_template_any )
309302 vm .start ()
310303 vm .ssh .scp_put (DATA_FILES / "msr_reader.sh" , "/tmp/msr_reader.sh" )
311304 _ , stdout , stderr = vm .ssh .run ("/tmp/msr_reader.sh" , timeout = None )
@@ -319,7 +312,7 @@ def test_cpu_rdmsr(
319312 host_kv = global_props .host_linux_version
320313 guest_kv = re .search (r"vmlinux-(\d+\.\d+)" , guest_kernel .name ).group (1 )
321314 baseline_file_name = (
322- f"msr_list_{ msr_cpu_template } _{ host_cpu } _{ host_kv } host_{ guest_kv } guest.csv"
315+ f"msr_list_{ cpu_template_name } _{ host_cpu } _{ host_kv } host_{ guest_kv } guest.csv"
323316 )
324317 # save it as an artifact, so we don't have to manually launch an instance to
325318 # get a baseline
@@ -371,7 +364,7 @@ def dump_msr_state_to_file(dump_fname, ssh_conn, shared_names):
371364)
372365@pytest .mark .timeout (900 )
373366@pytest .mark .nonci
374- def test_cpu_wrmsr_snapshot (microvm_factory , guest_kernel , rootfs , msr_cpu_template ):
367+ def test_cpu_wrmsr_snapshot (microvm_factory , guest_kernel , rootfs , cpu_template_any ):
375368 """
376369 This is the first part of the test verifying
377370 that MSRs retain their values after restoring from a snapshot.
@@ -388,6 +381,10 @@ def test_cpu_wrmsr_snapshot(microvm_factory, guest_kernel, rootfs, msr_cpu_templ
388381 This part of the test is responsible for taking a snapshot and publishing
389382 its files along with the `before` MSR dump.
390383 """
384+ cpu_template_name = get_cpu_template_name (cpu_template_any )
385+ if cpu_template_name not in MSR_SUPPORTED_TEMPLATES :
386+ pytest .skip (f"This test does not support { cpu_template_name } template." )
387+
391388 shared_names = SNAPSHOT_RESTORE_SHARED_NAMES
392389
393390 vcpus , guest_mem_mib = 1 , 1024
@@ -397,10 +394,10 @@ def test_cpu_wrmsr_snapshot(microvm_factory, guest_kernel, rootfs, msr_cpu_templ
397394 vm .basic_config (
398395 vcpu_count = vcpus ,
399396 mem_size_mib = guest_mem_mib ,
400- cpu_template = msr_cpu_template ,
401397 track_dirty_pages = True ,
402398 boot_args = "msr.allow_writes=on" ,
403399 )
400+ vm .set_cpu_template (cpu_template_any )
404401 vm .start ()
405402
406403 # Make MSR modifications
@@ -421,7 +418,7 @@ def test_cpu_wrmsr_snapshot(microvm_factory, guest_kernel, rootfs, msr_cpu_templ
421418 snapshot_artifacts_dir = (
422419 Path (shared_names ["snapshot_artifacts_root_dir_wrmsr" ])
423420 / guest_kernel .name
424- / get_cpu_template_name (msr_cpu_template , with_type = True )
421+ / get_cpu_template_name (cpu_template_any , with_type = True )
425422 )
426423 clean_and_mkdir (snapshot_artifacts_dir )
427424
@@ -473,7 +470,7 @@ def check_msrs_are_equal(before_recs, after_recs):
473470)
474471@pytest .mark .timeout (900 )
475472@pytest .mark .nonci
476- def test_cpu_wrmsr_restore (microvm_factory , msr_cpu_template , guest_kernel ):
473+ def test_cpu_wrmsr_restore (microvm_factory , cpu_template_any , guest_kernel ):
477474 """
478475 This is the second part of the test verifying
479476 that MSRs retain their values after restoring from a snapshot.
@@ -487,13 +484,15 @@ def test_cpu_wrmsr_restore(microvm_factory, msr_cpu_template, guest_kernel):
487484 This part of the test is responsible for restoring from a snapshot and
488485 comparing two sets of MSR values.
489486 """
487+ cpu_template_name = get_cpu_template_name (cpu_template_any )
488+ if cpu_template_name not in MSR_SUPPORTED_TEMPLATES :
489+ pytest .skip (f"This test does not support { cpu_template_name } template." )
490490
491491 shared_names = SNAPSHOT_RESTORE_SHARED_NAMES
492- cpu_template_dir = get_cpu_template_name (msr_cpu_template , with_type = True )
493492 snapshot_artifacts_dir = (
494493 Path (shared_names ["snapshot_artifacts_root_dir_wrmsr" ])
495494 / guest_kernel .name
496- / cpu_template_dir
495+ / get_cpu_template_name ( cpu_template_any , with_type = True )
497496 )
498497
499498 skip_test_based_on_artifacts (snapshot_artifacts_dir )
@@ -528,7 +527,7 @@ def dump_cpuid_to_file(dump_fname, ssh_conn):
528527)
529528@pytest .mark .timeout (900 )
530529@pytest .mark .nonci
531- def test_cpu_cpuid_snapshot (microvm_factory , guest_kernel , rootfs , msr_cpu_template ):
530+ def test_cpu_cpuid_snapshot (microvm_factory , guest_kernel , rootfs , cpu_template_any ):
532531 """
533532 This is the first part of the test verifying
534533 that CPUID remains the same after restoring from a snapshot.
@@ -540,6 +539,10 @@ def test_cpu_cpuid_snapshot(microvm_factory, guest_kernel, rootfs, msr_cpu_templ
540539 This part of the test is responsible for taking a snapshot and publishing
541540 its files along with the `before` CPUID dump.
542541 """
542+ cpu_template_name = get_cpu_template_name (cpu_template_any )
543+ if cpu_template_name not in MSR_SUPPORTED_TEMPLATES :
544+ pytest .skip ("This test does not support {cpu_template_name} template." )
545+
543546 shared_names = SNAPSHOT_RESTORE_SHARED_NAMES
544547
545548 vm = microvm_factory .build (
@@ -551,17 +554,16 @@ def test_cpu_cpuid_snapshot(microvm_factory, guest_kernel, rootfs, msr_cpu_templ
551554 vm .basic_config (
552555 vcpu_count = 1 ,
553556 mem_size_mib = 1024 ,
554- cpu_template = msr_cpu_template ,
555557 track_dirty_pages = True ,
556558 )
559+ vm .set_cpu_template (cpu_template_any )
557560 vm .start ()
558561
559562 # Dump CPUID to a file that will be published to S3 for the 2nd part of the test
560- cpu_template_dir = get_cpu_template_name (msr_cpu_template , with_type = True )
561563 snapshot_artifacts_dir = (
562564 Path (shared_names ["snapshot_artifacts_root_dir_cpuid" ])
563565 / guest_kernel .name
564- / cpu_template_dir
566+ / get_cpu_template_name ( cpu_template_any , with_type = True )
565567 )
566568 clean_and_mkdir (snapshot_artifacts_dir )
567569
@@ -595,7 +597,7 @@ def check_cpuid_is_equal(before_cpuid_fname, after_cpuid_fname):
595597)
596598@pytest .mark .timeout (900 )
597599@pytest .mark .nonci
598- def test_cpu_cpuid_restore (microvm_factory , guest_kernel , msr_cpu_template ):
600+ def test_cpu_cpuid_restore (microvm_factory , guest_kernel , cpu_template_any ):
599601 """
600602 This is the second part of the test verifying
601603 that CPUID remains the same after restoring from a snapshot.
@@ -607,13 +609,15 @@ def test_cpu_cpuid_restore(microvm_factory, guest_kernel, msr_cpu_template):
607609 This part of the test is responsible for restoring from a snapshot and
608610 comparing two CPUIDs.
609611 """
612+ cpu_template_name = get_cpu_template_name (cpu_template_any )
613+ if cpu_template_name not in MSR_SUPPORTED_TEMPLATES :
614+ pytest .skip ("This test does not support {cpu_template_name} template." )
610615
611616 shared_names = SNAPSHOT_RESTORE_SHARED_NAMES
612- cpu_template_dir = get_cpu_template_name (msr_cpu_template , with_type = True )
613617 snapshot_artifacts_dir = (
614618 Path (shared_names ["snapshot_artifacts_root_dir_cpuid" ])
615619 / guest_kernel .name
616- / cpu_template_dir
620+ / get_cpu_template_name ( cpu_template_any , with_type = True )
617621 )
618622
619623 skip_test_based_on_artifacts (snapshot_artifacts_dir )
@@ -633,25 +637,26 @@ def test_cpu_cpuid_restore(microvm_factory, guest_kernel, msr_cpu_template):
633637 )
634638
635639
636- @pytest .mark .parametrize (
637- "cpu_template" , sorted ({"T2" , "T2S" , "C3" }.intersection (SUPPORTED_CPU_TEMPLATES ))
638- )
639- def test_cpu_template (uvm_plain_any , cpu_template , microvm_factory ):
640+ def test_cpu_template (uvm_plain_any , cpu_template_any , microvm_factory ):
640641 """
641642 Test masked and enabled cpu features against the expected template.
642643
643644 This test checks that all expected masked features are not present in the
644645 guest and that expected enabled features are present for each of the
645646 supported CPU templates.
646647 """
648+ cpu_template_name = get_cpu_template_name (cpu_template_any )
649+ if cpu_template_name not in ["T2" , "T2S" , "C3" ]:
650+ pytest .skip ("This test does not support {cpu_template_name} template." )
651+
647652 test_microvm = uvm_plain_any
648653 test_microvm .spawn ()
649654 # Set template as specified in the `cpu_template` parameter.
650655 test_microvm .basic_config (
651656 vcpu_count = 1 ,
652657 mem_size_mib = 256 ,
653- cpu_template = cpu_template ,
654658 )
659+ test_microvm .set_cpu_template (cpu_template_any )
655660 test_microvm .add_net_iface ()
656661
657662 if cpuid_utils .get_cpu_vendor () != cpuid_utils .CpuVendor .INTEL :
@@ -662,17 +667,17 @@ def test_cpu_template(uvm_plain_any, cpu_template, microvm_factory):
662667
663668 test_microvm .start ()
664669
665- check_masked_features (test_microvm , cpu_template )
666- check_enabled_features (test_microvm , cpu_template )
670+ check_masked_features (test_microvm , cpu_template_name )
671+ check_enabled_features (test_microvm , cpu_template_name )
667672
668673 # Check that cpu features are still correct
669674 # after snap/restore cycle.
670675 snapshot = test_microvm .snapshot_full ()
671676 restored_vm = microvm_factory .build ()
672677 restored_vm .spawn ()
673678 restored_vm .restore_from_snapshot (snapshot , resume = True )
674- check_masked_features (restored_vm , cpu_template )
675- check_enabled_features (restored_vm , cpu_template )
679+ check_masked_features (restored_vm , cpu_template_name )
680+ check_enabled_features (restored_vm , cpu_template_name )
676681
677682
678683def check_masked_features (test_microvm , cpu_template ):
0 commit comments