Skip to content

Commit 17d1ea1

Browse files
Patryk Wlazlynlenb
authored andcommitted
tools/power turbostat: Add selftests
Signed-off-by: Patryk Wlazlyn <[email protected]> Signed-off-by: Len Brown <[email protected]>
1 parent 05a2f07 commit 17d1ea1

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/env python3
2+
3+
import subprocess
4+
from shutil import which
5+
6+
turbostat = which('turbostat')
7+
if turbostat is None:
8+
print('Could not find turbostat binary')
9+
exit(1)
10+
11+
timeout = which('timeout')
12+
if timeout is None:
13+
print('Could not find timeout binary')
14+
exit(1)
15+
16+
proc_turbostat = subprocess.run([turbostat, '--list'], capture_output = True)
17+
if proc_turbostat.returncode != 0:
18+
print(f'turbostat failed with {proc_turbostat.returncode}')
19+
exit(1)
20+
21+
#
22+
# By default --list reports also "usec" and "Time_Of_Day_Seconds" columns
23+
# which are only visible when running with --debug.
24+
#
25+
expected_columns_debug = proc_turbostat.stdout.replace(b',', b'\t').strip()
26+
expected_columns = expected_columns_debug.replace(b'usec\t', b'').replace(b'Time_Of_Day_Seconds\t', b'').replace(b'X2APIC\t', b'').replace(b'APIC\t', b'')
27+
28+
#
29+
# Run turbostat with no options for 10 seconds and send SIGINT
30+
#
31+
timeout_argv = [timeout, '--preserve-status', '-s', 'SIGINT', '-k', '3', '1s']
32+
turbostat_argv = [turbostat, '-i', '0.250']
33+
34+
print(f'Running turbostat with {turbostat_argv=}... ', end = '', flush = True)
35+
proc_turbostat = subprocess.run(timeout_argv + turbostat_argv, capture_output = True)
36+
if proc_turbostat.returncode != 0:
37+
print(f'turbostat failed with {proc_turbostat.returncode}')
38+
exit(1)
39+
actual_columns = proc_turbostat.stdout.split(b'\n')[0]
40+
if expected_columns != actual_columns:
41+
print(f'turbostat column check failed\n{expected_columns=}\n{actual_columns=}')
42+
exit(1)
43+
print('OK')
44+
45+
#
46+
# Same, but with --debug
47+
#
48+
turbostat_argv.append('--debug')
49+
50+
print(f'Running turbostat with {turbostat_argv=}... ', end = '', flush = True)
51+
proc_turbostat = subprocess.run(timeout_argv + turbostat_argv, capture_output = True)
52+
if proc_turbostat.returncode != 0:
53+
print(f'turbostat failed with {proc_turbostat.returncode}')
54+
exit(1)
55+
actual_columns = proc_turbostat.stdout.split(b'\n')[0]
56+
if expected_columns_debug != actual_columns:
57+
print(f'turbostat column check failed\n{expected_columns_debug=}\n{actual_columns=}')
58+
exit(1)
59+
print('OK')

0 commit comments

Comments
 (0)