Skip to content

Commit 5144394

Browse files
committed
refactor(test): Remove local utility functions used only once
Such local utility functions were defined away from where they are used, resulting in less readability. Unless they are used in multiple places, there is not much value to split them as utility functions, especially when they don't have so many lines of code. Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
1 parent b623232 commit 5144394

File tree

1 file changed

+24
-31
lines changed

1 file changed

+24
-31
lines changed

tests/integration_tests/functional/test_cpu_features_x86_64.py

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,35 +48,6 @@ def clean_and_mkdir(dir_path):
4848
os.makedirs(dir_path)
4949

5050

51-
def _check_cpuid_x86(test_microvm, expected_cpu_count, expected_htt):
52-
expected_cpu_features = {
53-
"maximum IDs for CPUs in pkg": f"{expected_cpu_count:#x} ({expected_cpu_count})",
54-
"CLFLUSH line size": "0x8 (8)",
55-
"hypervisor guest status": "true",
56-
"hyper-threading / multi-core supported": expected_htt,
57-
}
58-
59-
cpuid_utils.check_guest_cpuid_output(
60-
test_microvm, "cpuid -1", None, "=", expected_cpu_features
61-
)
62-
63-
64-
def _check_extended_cache_features(vm):
65-
l3_params = cpuid_utils.get_guest_cpuid(vm, "0x80000006")[(0x80000006, 0, "edx")]
66-
67-
# fmt: off
68-
line_size = (l3_params >> 0) & 0xFF
69-
lines_per_tag = (l3_params >> 8) & 0xF
70-
assoc = (l3_params >> 12) & 0xF
71-
cache_size = (l3_params >> 18) & 0x3FFF
72-
# fmt: on
73-
74-
assert line_size > 0
75-
assert lines_per_tag == 0x1 # This is hardcoded in the AMD spec
76-
assert assoc == 0x9 # This is hardcoded in the AMD spec
77-
assert cache_size > 0
78-
79-
8051
def get_cpu_template_name_str(cpu_template, with_type=False):
8152
"""
8253
Utility function to return a valid string which will be used as
@@ -135,7 +106,16 @@ def test_cpuid(uvm_plain_any, num_vcpus, htt):
135106
vm.basic_config(vcpu_count=num_vcpus, smt=htt)
136107
vm.add_net_iface()
137108
vm.start()
138-
_check_cpuid_x86(vm, num_vcpus, "true" if num_vcpus > 1 else "false")
109+
110+
expected_cpu_features = {
111+
"maximum IDs for CPUs in pkg": f"{num_vcpus:#x} ({num_vcpus})",
112+
"CLFLUSH line size": "0x8 (8)",
113+
"hypervisor guest status": "true",
114+
"hyper-threading / multi-core supported": "true" if num_vcpus > 1 else "false",
115+
}
116+
cpuid_utils.check_guest_cpuid_output(
117+
vm, "cpuid -1", None, "=", expected_cpu_features
118+
)
139119

140120

141121
@pytest.mark.skipif(
@@ -151,7 +131,20 @@ def test_extended_cache_features(uvm_plain_any):
151131
vm.basic_config()
152132
vm.add_net_iface()
153133
vm.start()
154-
_check_extended_cache_features(vm)
134+
135+
l3_params = cpuid_utils.get_guest_cpuid(vm, "0x80000006")[(0x80000006, 0, "edx")]
136+
137+
# fmt: off
138+
line_size = (l3_params >> 0) & 0xFF
139+
lines_per_tag = (l3_params >> 8) & 0xF
140+
assoc = (l3_params >> 12) & 0xF
141+
cache_size = (l3_params >> 18) & 0x3FFF
142+
# fmt: on
143+
144+
assert line_size > 0
145+
assert lines_per_tag == 0x1 # This is hardcoded in the AMD spec
146+
assert assoc == 0x9 # This is hardcoded in the AMD spec
147+
assert cache_size > 0
155148

156149

157150
def test_brand_string(uvm_plain_any):

0 commit comments

Comments
 (0)