@@ -77,7 +77,7 @@ def _check_extended_cache_features(vm):
7777 assert cache_size > 0
7878
7979
80- def get_cpu_template_name_str (cpu_template ):
80+ def get_cpu_template_name_str (cpu_template , with_type = False ):
8181 """
8282 Utility function to return a valid string which will be used as
8383 name of the directory where snapshot artifacts are stored during
@@ -87,9 +87,13 @@ def get_cpu_template_name_str(cpu_template):
8787 if isinstance (cpu_template , str ):
8888 # static CPU template
8989 name = cpu_template .lower ()
90+ if with_type :
91+ name = "static_" + name
9092 elif isinstance (cpu_template , dict ):
9193 # custom CPU template
9294 name = cpu_template ["name" ].lower ()
95+ if with_type :
96+ name = "custom_" + name
9397 return name
9498
9599
@@ -363,7 +367,7 @@ def dump_msr_state_to_file(dump_fname, ssh_conn, shared_names):
363367)
364368@pytest .mark .timeout (900 )
365369@pytest .mark .nonci
366- def test_cpu_wrmsr_snapshot (microvm_factory , guest_kernel , rootfs , msr_cpu_template ):
370+ def test_cpu_wrmsr_snapshot (microvm_factory , guest_kernel , rootfs , cpu_template_any ):
367371 """
368372 This is the first part of the test verifying
369373 that MSRs retain their values after restoring from a snapshot.
@@ -389,10 +393,10 @@ def test_cpu_wrmsr_snapshot(microvm_factory, guest_kernel, rootfs, msr_cpu_templ
389393 vm .basic_config (
390394 vcpu_count = vcpus ,
391395 mem_size_mib = guest_mem_mib ,
392- cpu_template = msr_cpu_template ,
393396 track_dirty_pages = True ,
394397 boot_args = "msr.allow_writes=on" ,
395398 )
399+ vm .set_cpu_template (cpu_template_any )
396400 vm .start ()
397401
398402 # Make MSR modifications
@@ -413,7 +417,7 @@ def test_cpu_wrmsr_snapshot(microvm_factory, guest_kernel, rootfs, msr_cpu_templ
413417 snapshot_artifacts_dir = (
414418 Path (shared_names ["snapshot_artifacts_root_dir_wrmsr" ])
415419 / guest_kernel .name
416- / ( msr_cpu_template if msr_cpu_template else "none" )
420+ / get_cpu_template_name_str ( cpu_template_any , with_type = True )
417421 )
418422 clean_and_mkdir (snapshot_artifacts_dir )
419423
@@ -465,7 +469,7 @@ def check_msrs_are_equal(before_recs, after_recs):
465469)
466470@pytest .mark .timeout (900 )
467471@pytest .mark .nonci
468- def test_cpu_wrmsr_restore (microvm_factory , msr_cpu_template , guest_kernel ):
472+ def test_cpu_wrmsr_restore (microvm_factory , cpu_template_any , guest_kernel ):
469473 """
470474 This is the second part of the test verifying
471475 that MSRs retain their values after restoring from a snapshot.
@@ -481,7 +485,7 @@ def test_cpu_wrmsr_restore(microvm_factory, msr_cpu_template, guest_kernel):
481485 """
482486
483487 shared_names = SNAPSHOT_RESTORE_SHARED_NAMES
484- cpu_template_dir = msr_cpu_template if msr_cpu_template else "none"
488+ cpu_template_dir = get_cpu_template_name_str ( cpu_template_any , with_type = True )
485489 snapshot_artifacts_dir = (
486490 Path (shared_names ["snapshot_artifacts_root_dir_wrmsr" ])
487491 / guest_kernel .name
@@ -520,7 +524,7 @@ def dump_cpuid_to_file(dump_fname, ssh_conn):
520524)
521525@pytest .mark .timeout (900 )
522526@pytest .mark .nonci
523- def test_cpu_cpuid_snapshot (microvm_factory , guest_kernel , rootfs , msr_cpu_template ):
527+ def test_cpu_cpuid_snapshot (microvm_factory , guest_kernel , rootfs , cpu_template_any ):
524528 """
525529 This is the first part of the test verifying
526530 that CPUID remains the same after restoring from a snapshot.
@@ -543,13 +547,13 @@ def test_cpu_cpuid_snapshot(microvm_factory, guest_kernel, rootfs, msr_cpu_templ
543547 vm .basic_config (
544548 vcpu_count = 1 ,
545549 mem_size_mib = 1024 ,
546- cpu_template = msr_cpu_template ,
547550 track_dirty_pages = True ,
548551 )
552+ vm .set_cpu_template (cpu_template_any )
549553 vm .start ()
550554
551555 # Dump CPUID to a file that will be published to S3 for the 2nd part of the test
552- cpu_template_dir = get_cpu_template_name_str (msr_cpu_template )
556+ cpu_template_dir = get_cpu_template_name_str (cpu_template_any , with_type = True )
553557 snapshot_artifacts_dir = (
554558 Path (shared_names ["snapshot_artifacts_root_dir_cpuid" ])
555559 / guest_kernel .name
@@ -587,7 +591,7 @@ def check_cpuid_is_equal(before_cpuid_fname, after_cpuid_fname):
587591)
588592@pytest .mark .timeout (900 )
589593@pytest .mark .nonci
590- def test_cpu_cpuid_restore (microvm_factory , guest_kernel , msr_cpu_template ):
594+ def test_cpu_cpuid_restore (microvm_factory , guest_kernel , cpu_template_any ):
591595 """
592596 This is the second part of the test verifying
593597 that CPUID remains the same after restoring from a snapshot.
@@ -601,7 +605,7 @@ def test_cpu_cpuid_restore(microvm_factory, guest_kernel, msr_cpu_template):
601605 """
602606
603607 shared_names = SNAPSHOT_RESTORE_SHARED_NAMES
604- cpu_template_dir = get_cpu_template_name_str (msr_cpu_template )
608+ cpu_template_dir = get_cpu_template_name_str (cpu_template_any , with_type = True )
605609 snapshot_artifacts_dir = (
606610 Path (shared_names ["snapshot_artifacts_root_dir_cpuid" ])
607611 / guest_kernel .name
0 commit comments