Skip to content

Commit 234aeb9

Browse files
zulinx86kalyazin
authored andcommitted
test(tool): Add guest CPU config consistency test
Add a test to verify that the dumped guest CPU configs obtained consecutively are consistent. Signed-off-by: Takahiro Itazuri <[email protected]>
1 parent 1407f62 commit 234aeb9

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

tests/integration_tests/functional/test_cpu_template_helper.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ def template_dump(self, vm_config_path, output_path):
5454
)
5555
utils.run_cmd(cmd)
5656

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+
5763
def template_verify(self, vm_config_path):
5864
"""Verify the specified CPU template"""
5965
cmd = f"{self.BINARY_PATH} template verify --config {vm_config_path}"
@@ -338,7 +344,7 @@ def test_json_static_templates(
338344
test_microvm_with_api, cpu_template_helper, tmp_path, custom_cpu_template
339345
):
340346
"""
341-
Verify that JSON static CPU templates are applied as intended
347+
Verify that JSON static CPU templates are applied as intended.
342348
"""
343349
# Generate VM config with JSON static CPU template
344350
microvm = test_microvm_with_api
@@ -348,3 +354,37 @@ def test_json_static_templates(
348354

349355
# Verify the JSON static CPU template.
350356
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

Comments
 (0)