9
9
10
10
PARSER = argparse .ArgumentParser (
11
11
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" ,
13
13
help = "Path to print-sys-info app" )
14
+ PARSER .add_argument ("--build-dir" ,
15
+ help = "Search this dir for print-sys-info app" )
14
16
15
17
16
18
def main ():
17
19
args = PARSER .parse_args ()
18
20
19
- if args .print_sys_info :
21
+ if args .print_sys_info_path :
20
22
app = Path (args .print_sys_info_path )
21
- if not app .exists :
22
- exit ("FAILED: file not found: {app}" )
23
23
else :
24
- app = find_app ()
24
+ app = find_app (args . build_dir )
25
25
26
26
app_features_yesno : Dict [str , bool ] = detect_features_from_app (app )
27
27
28
28
os_features_list = detect_features_from_os ()
29
29
30
+ # TODO: compare app_features_yesno and os_features_list
31
+
30
32
31
33
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 ()
33
36
34
37
app_name = 'print-sys-info'
35
38
if os .name == 'nt' :
@@ -38,7 +41,8 @@ def find_app(build_dir: Optional[str]) -> Path:
38
41
for file in build_dir .glob (f"**/{ app_name } " ):
39
42
return file
40
43
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
+ "\n Pass --build-dir to hint location." )
42
46
43
47
44
48
def find_build_dir () -> Path :
@@ -48,13 +52,14 @@ def find_build_dir() -> Path:
48
52
return build_dir
49
53
dir = dir .parent
50
54
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. " )
52
56
53
57
54
58
def detect_features_from_app (app_path : Path ) -> Dict [str , bool ]:
55
59
result = run ([str (app_path )],
56
60
capture_output = True ,
57
61
text = True )
62
+ print (f"--- { app_path } ---" )
58
63
print (result .stderr )
59
64
print (result .stdout )
60
65
if result .returncode != 0 :
@@ -76,7 +81,8 @@ def detect_features_from_app(app_path: Path) -> Dict[str, bool]:
76
81
# 'amd_sse4_1': false
77
82
features = {}
78
83
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 :
80
86
name = m .group (1 )
81
87
is_present = m .group (2 ) == 'true'
82
88
features [name ] = is_present
@@ -89,13 +95,24 @@ def detect_features_from_app(app_path: Path) -> Dict[str, bool]:
89
95
def detect_features_from_os () -> List [str ]:
90
96
features = []
91
97
98
+ cpuinfo_path = '/proc/cpuinfo'
92
99
try :
93
- with open ('/proc/cpuinfo' ) as f :
100
+ with open (cpuinfo_path ) as f :
94
101
cpuinfo_text = f .read ()
95
102
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
97
114
98
- # for line in cpuinfo_text:
115
+ exit ( f"FAILED: Cannot detect 'flags' in { cpuinfo_path } " )
99
116
100
117
101
118
if __name__ == '__main__' :
0 commit comments