Skip to content

Commit 63e38b9

Browse files
committed
WIP
1 parent b192bff commit 63e38b9

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

bin/system_info/test-print-system-info.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,30 @@
99

1010
PARSER = argparse.ArgumentParser(
1111
description="Run print-sys-info to detect CPU features. Fail if the results seem wrong.")
12-
PARSER.add_argument("print-sys-info-path",
12+
PARSER.add_argument("--print-sys-info-path",
1313
help="Path to print-sys-info app")
14+
PARSER.add_argument("--build-dir",
15+
help="Search this dir for print-sys-info app")
1416

1517

1618
def main():
1719
args = PARSER.parse_args()
1820

19-
if args.print_sys_info:
21+
if args.print_sys_info_path:
2022
app = Path(args.print_sys_info_path)
21-
if not app.exists:
22-
exit("FAILED: file not found: {app}")
2323
else:
24-
app = find_app()
24+
app = find_app(args.build_dir)
2525

2626
app_features_yesno: Dict[str, bool] = detect_features_from_app(app)
2727

2828
os_features_list = detect_features_from_os()
2929

30+
# TODO: compare app_features_yesno and os_features_list
31+
3032

3133
def find_app(build_dir: Optional[str]) -> Path:
32-
build_dir = find_build_dir()
34+
if build_dir is None:
35+
build_dir = find_build_dir()
3336

3437
app_name = 'print-sys-info'
3538
if os.name == 'nt':
@@ -38,7 +41,8 @@ def find_app(build_dir: Optional[str]) -> Path:
3841
for file in build_dir.glob(f"**/{app_name}"):
3942
return file
4043

41-
exit("FAILED: Can't find print-sys-info. Pass location as argument")
44+
exit(f"FAILED: Can't find '{app_name}' under: {build_dir}."
45+
"\nPass --build-dir to hint location.")
4246

4347

4448
def find_build_dir() -> Path:
@@ -48,13 +52,14 @@ def find_build_dir() -> Path:
4852
return build_dir
4953
dir = dir.parent
5054

51-
exit("FAILED: Can't find print-sys-info. Pass location as argument")
55+
exit("FAILED: Can't find build dir. Pass --build-dir to hint location.")
5256

5357

5458
def detect_features_from_app(app_path: Path) -> Dict[str, bool]:
5559
result = run([str(app_path)],
5660
capture_output=True,
5761
text=True)
62+
print(f"--- {app_path} ---")
5863
print(result.stderr)
5964
print(result.stdout)
6065
if result.returncode != 0:
@@ -76,7 +81,8 @@ def detect_features_from_app(app_path: Path) -> Dict[str, bool]:
7681
# 'amd_sse4_1': false
7782
features = {}
7883
for line in lines:
79-
if m := re.search(f"'{machine}_(.+)': (false|true)", line):
84+
m = re.search(f"'{machine}_(.+)': (false|true)", line)
85+
if m:
8086
name = m.group(1)
8187
is_present = m.group(2) == 'true'
8288
features[name] = is_present
@@ -89,13 +95,24 @@ def detect_features_from_app(app_path: Path) -> Dict[str, bool]:
8995
def detect_features_from_os() -> List[str]:
9096
features = []
9197

98+
cpuinfo_path = '/proc/cpuinfo'
9299
try:
93-
with open('/proc/cpuinfo') as f:
100+
with open(cpuinfo_path) as f:
94101
cpuinfo_text = f.read()
95102
except:
96-
exit("SKIP TEST: currently, this test only works on machines with /proc/cpuinfo")
103+
print(f"SKIP TEST: currently, this test only works on machines with /proc/cpuinfo")
104+
exit(0)
105+
106+
# looking for line like: flags : fpu vme de pse ...
107+
print(f"--- {cpuinfo_path} ---")
108+
for line in cpuinfo_text.splitlines():
109+
print(line)
110+
m = re.match(r"flags\s+:(.*)", line)
111+
if m:
112+
flags = m.group(1).split()
113+
return flags
97114

98-
# for line in cpuinfo_text:
115+
exit(f"FAILED: Cannot detect 'flags' in {cpuinfo_path}")
99116

100117

101118
if __name__ == '__main__':

builder.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
},
2323
"test_steps": [
2424
"test",
25-
["python3", "{source_dir}/bin/system_info/test-print-system-info.py", "{install_dir}/bin/print-sys-info{exe}"]
25+
["python3", "{source_dir}/bin/system_info/test-print-system-info.py", "--build-dir", "{build_dir}"]
2626
]
2727
}

0 commit comments

Comments
 (0)