|
2 | 2 | # SPDX-License-Identifier: Apache-2.0
|
3 | 3 | """Tests for ensuring correctness of CPU and cache topology in the guest."""
|
4 | 4 |
|
5 |
| -import json |
6 |
| -import os |
7 | 5 | import platform
|
8 |
| -from ast import literal_eval |
| 6 | +import subprocess |
9 | 7 |
|
10 | 8 | import pytest
|
11 | 9 |
|
@@ -90,31 +88,24 @@ def _check_cache_topology_arm(test_microvm, no_cpus):
|
90 | 88 | # There are 2 types of L1 cache (instruction and data) that is why the
|
91 | 89 | # "cache_info" variable below has 4 items.
|
92 | 90 |
|
93 |
| - path = "/sys/devices/system/cpu/" |
| 91 | + sys_cpu = "/sys/devices/system/cpu" |
| 92 | + fields = ["level", "type", "size", "coherency_line_size", "number_of_sets"] |
94 | 93 |
|
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" |
96 | 95 |
|
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", |
99 | 106 | )
|
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 |
118 | 109 |
|
119 | 110 |
|
120 | 111 | @pytest.mark.skipif(
|
|
0 commit comments