@@ -253,19 +253,10 @@ def test_brand_string(uvm_plain_any):
253
253
MSR_SUPPORTED_TEMPLATES = ["T2A" , "T2CL" , "T2S" ]
254
254
255
255
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
-
265
256
@pytest .mark .timeout (900 )
266
257
@pytest .mark .nonci
267
258
def 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
269
260
):
270
261
"""
271
262
Test MSRs that are available to the guest.
@@ -298,14 +289,16 @@ def test_cpu_rdmsr(
298
289
- All supported guest kernels and rootfs
299
290
- Microvm: 1vCPU with 1024 MB RAM
300
291
"""
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." )
301
295
302
296
vcpus , guest_mem_mib = 1 , 1024
303
297
vm = microvm_factory .build (guest_kernel , rootfs , monitor_memory = False )
304
298
vm .spawn ()
305
299
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 )
309
302
vm .start ()
310
303
vm .ssh .scp_put (DATA_FILES / "msr_reader.sh" , "/tmp/msr_reader.sh" )
311
304
_ , stdout , stderr = vm .ssh .run ("/tmp/msr_reader.sh" , timeout = None )
@@ -319,7 +312,7 @@ def test_cpu_rdmsr(
319
312
host_kv = global_props .host_linux_version
320
313
guest_kv = re .search (r"vmlinux-(\d+\.\d+)" , guest_kernel .name ).group (1 )
321
314
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"
323
316
)
324
317
# save it as an artifact, so we don't have to manually launch an instance to
325
318
# get a baseline
@@ -371,7 +364,7 @@ def dump_msr_state_to_file(dump_fname, ssh_conn, shared_names):
371
364
)
372
365
@pytest .mark .timeout (900 )
373
366
@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 ):
375
368
"""
376
369
This is the first part of the test verifying
377
370
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
388
381
This part of the test is responsible for taking a snapshot and publishing
389
382
its files along with the `before` MSR dump.
390
383
"""
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
+
391
388
shared_names = SNAPSHOT_RESTORE_SHARED_NAMES
392
389
393
390
vcpus , guest_mem_mib = 1 , 1024
@@ -397,10 +394,10 @@ def test_cpu_wrmsr_snapshot(microvm_factory, guest_kernel, rootfs, msr_cpu_templ
397
394
vm .basic_config (
398
395
vcpu_count = vcpus ,
399
396
mem_size_mib = guest_mem_mib ,
400
- cpu_template = msr_cpu_template ,
401
397
track_dirty_pages = True ,
402
398
boot_args = "msr.allow_writes=on" ,
403
399
)
400
+ vm .set_cpu_template (cpu_template_any )
404
401
vm .start ()
405
402
406
403
# Make MSR modifications
@@ -421,7 +418,7 @@ def test_cpu_wrmsr_snapshot(microvm_factory, guest_kernel, rootfs, msr_cpu_templ
421
418
snapshot_artifacts_dir = (
422
419
Path (shared_names ["snapshot_artifacts_root_dir_wrmsr" ])
423
420
/ 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 )
425
422
)
426
423
clean_and_mkdir (snapshot_artifacts_dir )
427
424
@@ -473,7 +470,7 @@ def check_msrs_are_equal(before_recs, after_recs):
473
470
)
474
471
@pytest .mark .timeout (900 )
475
472
@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 ):
477
474
"""
478
475
This is the second part of the test verifying
479
476
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):
487
484
This part of the test is responsible for restoring from a snapshot and
488
485
comparing two sets of MSR values.
489
486
"""
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." )
490
490
491
491
shared_names = SNAPSHOT_RESTORE_SHARED_NAMES
492
- cpu_template_dir = get_cpu_template_name (msr_cpu_template , with_type = True )
493
492
snapshot_artifacts_dir = (
494
493
Path (shared_names ["snapshot_artifacts_root_dir_wrmsr" ])
495
494
/ guest_kernel .name
496
- / cpu_template_dir
495
+ / get_cpu_template_name ( cpu_template_any , with_type = True )
497
496
)
498
497
499
498
skip_test_based_on_artifacts (snapshot_artifacts_dir )
@@ -528,7 +527,7 @@ def dump_cpuid_to_file(dump_fname, ssh_conn):
528
527
)
529
528
@pytest .mark .timeout (900 )
530
529
@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 ):
532
531
"""
533
532
This is the first part of the test verifying
534
533
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
540
539
This part of the test is responsible for taking a snapshot and publishing
541
540
its files along with the `before` CPUID dump.
542
541
"""
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
+
543
546
shared_names = SNAPSHOT_RESTORE_SHARED_NAMES
544
547
545
548
vm = microvm_factory .build (
@@ -551,17 +554,16 @@ def test_cpu_cpuid_snapshot(microvm_factory, guest_kernel, rootfs, msr_cpu_templ
551
554
vm .basic_config (
552
555
vcpu_count = 1 ,
553
556
mem_size_mib = 1024 ,
554
- cpu_template = msr_cpu_template ,
555
557
track_dirty_pages = True ,
556
558
)
559
+ vm .set_cpu_template (cpu_template_any )
557
560
vm .start ()
558
561
559
562
# 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 )
561
563
snapshot_artifacts_dir = (
562
564
Path (shared_names ["snapshot_artifacts_root_dir_cpuid" ])
563
565
/ guest_kernel .name
564
- / cpu_template_dir
566
+ / get_cpu_template_name ( cpu_template_any , with_type = True )
565
567
)
566
568
clean_and_mkdir (snapshot_artifacts_dir )
567
569
@@ -595,7 +597,7 @@ def check_cpuid_is_equal(before_cpuid_fname, after_cpuid_fname):
595
597
)
596
598
@pytest .mark .timeout (900 )
597
599
@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 ):
599
601
"""
600
602
This is the second part of the test verifying
601
603
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):
607
609
This part of the test is responsible for restoring from a snapshot and
608
610
comparing two CPUIDs.
609
611
"""
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." )
610
615
611
616
shared_names = SNAPSHOT_RESTORE_SHARED_NAMES
612
- cpu_template_dir = get_cpu_template_name (msr_cpu_template , with_type = True )
613
617
snapshot_artifacts_dir = (
614
618
Path (shared_names ["snapshot_artifacts_root_dir_cpuid" ])
615
619
/ guest_kernel .name
616
- / cpu_template_dir
620
+ / get_cpu_template_name ( cpu_template_any , with_type = True )
617
621
)
618
622
619
623
skip_test_based_on_artifacts (snapshot_artifacts_dir )
@@ -633,25 +637,26 @@ def test_cpu_cpuid_restore(microvm_factory, guest_kernel, msr_cpu_template):
633
637
)
634
638
635
639
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 ):
640
641
"""
641
642
Test masked and enabled cpu features against the expected template.
642
643
643
644
This test checks that all expected masked features are not present in the
644
645
guest and that expected enabled features are present for each of the
645
646
supported CPU templates.
646
647
"""
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
+
647
652
test_microvm = uvm_plain_any
648
653
test_microvm .spawn ()
649
654
# Set template as specified in the `cpu_template` parameter.
650
655
test_microvm .basic_config (
651
656
vcpu_count = 1 ,
652
657
mem_size_mib = 256 ,
653
- cpu_template = cpu_template ,
654
658
)
659
+ test_microvm .set_cpu_template (cpu_template_any )
655
660
test_microvm .add_net_iface ()
656
661
657
662
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):
662
667
663
668
test_microvm .start ()
664
669
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 )
667
672
668
673
# Check that cpu features are still correct
669
674
# after snap/restore cycle.
670
675
snapshot = test_microvm .snapshot_full ()
671
676
restored_vm = microvm_factory .build ()
672
677
restored_vm .spawn ()
673
678
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 )
676
681
677
682
678
683
def check_masked_features (test_microvm , cpu_template ):
0 commit comments