Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
graebm committed Jan 24, 2025
1 parent b192bff commit 63e38b9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
41 changes: 29 additions & 12 deletions bin/system_info/test-print-system-info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,30 @@

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


def main():
args = PARSER.parse_args()

if args.print_sys_info:
if args.print_sys_info_path:
app = Path(args.print_sys_info_path)
if not app.exists:
exit("FAILED: file not found: {app}")
else:
app = find_app()
app = find_app(args.build_dir)

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

os_features_list = detect_features_from_os()

# TODO: compare app_features_yesno and os_features_list


def find_app(build_dir: Optional[str]) -> Path:
build_dir = find_build_dir()
if build_dir is None:
build_dir = find_build_dir()

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

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


def find_build_dir() -> Path:
Expand All @@ -48,13 +52,14 @@ def find_build_dir() -> Path:
return build_dir
dir = dir.parent

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


def detect_features_from_app(app_path: Path) -> Dict[str, bool]:
result = run([str(app_path)],
capture_output=True,
text=True)
print(f"--- {app_path} ---")
print(result.stderr)
print(result.stdout)
if result.returncode != 0:
Expand All @@ -76,7 +81,8 @@ def detect_features_from_app(app_path: Path) -> Dict[str, bool]:
# 'amd_sse4_1': false
features = {}
for line in lines:
if m := re.search(f"'{machine}_(.+)': (false|true)", line):
m = re.search(f"'{machine}_(.+)': (false|true)", line)
if m:
name = m.group(1)
is_present = m.group(2) == 'true'
features[name] = is_present
Expand All @@ -89,13 +95,24 @@ def detect_features_from_app(app_path: Path) -> Dict[str, bool]:
def detect_features_from_os() -> List[str]:
features = []

cpuinfo_path = '/proc/cpuinfo'
try:
with open('/proc/cpuinfo') as f:
with open(cpuinfo_path) as f:
cpuinfo_text = f.read()
except:
exit("SKIP TEST: currently, this test only works on machines with /proc/cpuinfo")
print(f"SKIP TEST: currently, this test only works on machines with /proc/cpuinfo")
exit(0)

# looking for line like: flags : fpu vme de pse ...
print(f"--- {cpuinfo_path} ---")
for line in cpuinfo_text.splitlines():
print(line)
m = re.match(r"flags\s+:(.*)", line)
if m:
flags = m.group(1).split()
return flags

# for line in cpuinfo_text:
exit(f"FAILED: Cannot detect 'flags' in {cpuinfo_path}")


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
},
"test_steps": [
"test",
["python3", "{source_dir}/bin/system_info/test-print-system-info.py", "{install_dir}/bin/print-sys-info{exe}"]
["python3", "{source_dir}/bin/system_info/test-print-system-info.py", "--build-dir", "{build_dir}"]
]
}

0 comments on commit 63e38b9

Please sign in to comment.