Skip to content

Commit 7900e9f

Browse files
pb8ozulinx86
authored andcommitted
test: refactor cache topology test
Get the data with the same command for host and guest, and avoid a file in the rootfs. Signed-off-by: Pablo Barbáchano <pablob@amazon.com>
1 parent 37cdc54 commit 7900e9f

File tree

2 files changed

+16
-53
lines changed

2 files changed

+16
-53
lines changed

resources/overlay/usr/local/bin/get_cache_info.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/integration_tests/functional/test_topology.py

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
# SPDX-License-Identifier: Apache-2.0
33
"""Tests for ensuring correctness of CPU and cache topology in the guest."""
44

5-
import json
6-
import os
75
import platform
8-
from ast import literal_eval
6+
import subprocess
97

108
import pytest
119

@@ -90,31 +88,24 @@ def _check_cache_topology_arm(test_microvm, no_cpus):
9088
# There are 2 types of L1 cache (instruction and data) that is why the
9189
# "cache_info" variable below has 4 items.
9290

93-
path = "/sys/devices/system/cpu/"
91+
sys_cpu = "/sys/devices/system/cpu"
92+
fields = ["level", "type", "size", "coherency_line_size", "number_of_sets"]
9493

95-
cache_files = ["level", "type", "size", "coherency_line_size", "number_of_sets"]
94+
cmd = f"grep . {sys_cpu}/cpu{{0..{no_cpus-1}}}/cache/index*/{{{','.join(fields)}}} |sort"
9695

97-
_, stdout, stderr = test_microvm.ssh.execute_command(
98-
"/usr/local/bin/get_cache_info.sh"
96+
_, guest_stdout, guest_stderr = test_microvm.ssh.execute_command(cmd)
97+
assert guest_stderr == ""
98+
99+
res = subprocess.run(
100+
cmd,
101+
shell=True,
102+
executable="/bin/bash",
103+
capture_output=True,
104+
check=True,
105+
encoding="ascii",
99106
)
100-
assert stderr == ""
101-
102-
guest_dict = json.loads(literal_eval(stdout.strip()))
103-
host_dict = {}
104-
for i in range(no_cpus):
105-
cpu_path = os.path.join(os.path.join(path, "cpu{}".format(i)), "cache")
106-
dirs = os.listdir(cpu_path)
107-
for cache_level in dirs:
108-
if "index" not in os.path.basename(cache_level):
109-
continue
110-
cache_path = os.path.join(cpu_path, cache_level)
111-
112-
for cache_file in cache_files:
113-
absolute_cache_file = os.path.join(cache_path, cache_file)
114-
with open(absolute_cache_file, "r", encoding="utf-8") as file:
115-
host_val = file.readline().strip()
116-
host_dict[str(absolute_cache_file)] = str(host_val)
117-
assert guest_dict == host_dict
107+
assert res.stderr == ""
108+
assert res.stdout == guest_stdout
118109

119110

120111
@pytest.mark.skipif(

0 commit comments

Comments
 (0)