@@ -54,6 +54,12 @@ def template_dump(self, vm_config_path, output_path):
54
54
)
55
55
utils .run_cmd (cmd )
56
56
57
+ def template_strip (self , paths , suffix = "" ):
58
+ """Strip entries shared between multiple CPU template files"""
59
+ paths = " " .join ([str (path ) for path in paths ])
60
+ cmd = f"{ self .BINARY_PATH } template strip --paths { paths } --suffix '{ suffix } '"
61
+ utils .run_cmd (cmd )
62
+
57
63
def template_verify (self , vm_config_path ):
58
64
"""Verify the specified CPU template"""
59
65
cmd = f"{ self .BINARY_PATH } template verify --config { vm_config_path } "
@@ -338,7 +344,7 @@ def test_json_static_templates(
338
344
test_microvm_with_api , cpu_template_helper , tmp_path , custom_cpu_template
339
345
):
340
346
"""
341
- Verify that JSON static CPU templates are applied as intended
347
+ Verify that JSON static CPU templates are applied as intended.
342
348
"""
343
349
# Generate VM config with JSON static CPU template
344
350
microvm = test_microvm_with_api
@@ -348,3 +354,37 @@ def test_json_static_templates(
348
354
349
355
# Verify the JSON static CPU template.
350
356
cpu_template_helper .template_verify (vm_config_path )
357
+
358
+
359
+ def test_consecutive_cpu_config_consistency (
360
+ test_microvm_with_api , cpu_template_helper , tmp_path
361
+ ):
362
+ """
363
+ Verify that two dumped guest CPU configs obtained consecutively are
364
+ consistent. The dumped guest CPU config should not change without
365
+ any environmental changes (firecracker, kernel, microcode updates).
366
+ """
367
+ microvm = test_microvm_with_api
368
+ microvm .spawn ()
369
+ microvm .basic_config ()
370
+ vm_config_path = save_vm_config (microvm , tmp_path )
371
+
372
+ # Dump CPU config with the helper tool.
373
+ cpu_config_1 = tmp_path / "cpu_config_1.json"
374
+ cpu_template_helper .template_dump (vm_config_path , cpu_config_1 )
375
+ cpu_config_2 = tmp_path / "cpu_config_2.json"
376
+ cpu_template_helper .template_dump (vm_config_path , cpu_config_2 )
377
+
378
+ # Strip common entries.
379
+ cpu_template_helper .template_strip ([cpu_config_1 , cpu_config_2 ])
380
+
381
+ # Check the stripped result is empty.
382
+ if PLATFORM == "x86_64" :
383
+ empty_cpu_config = {
384
+ "cpuid_modifiers" : [],
385
+ "msr_modifiers" : [],
386
+ }
387
+ elif PLATFORM == "aarch64" :
388
+ empty_cpu_config = {"reg_modifiers" : []}
389
+ assert json .loads (cpu_config_1 .read_text (encoding = "utf-8" )) == empty_cpu_config
390
+ assert json .loads (cpu_config_2 .read_text (encoding = "utf-8" )) == empty_cpu_config
0 commit comments