Skip to content

Commit 7b1491d

Browse files
committed
check-suspend-resume: add sleepgraph.py
Signed-off-by: Emilia Kurdybelska <emiliax.kurdybelska@intel.com>
1 parent 60f43ba commit 7b1491d

4 files changed

Lines changed: 156 additions & 3 deletions

File tree

test-case/check-suspend-resume.sh

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,29 @@ main()
170170
die "Found kernel error after reloading audio drivers"
171171
}
172172

173+
analyze_sleepgraph_results()
174+
{
175+
dlogi "TODO: Analyze sleepgraph results..."
176+
results_file=$(ls suspend-* | grep html)
177+
178+
}
179+
180+
run_rtcwake()
181+
{
182+
if [[ "$RUN_SLEEPGRAPH" == true ]]; then
183+
# Remove old sleepgraph results directories
184+
sudo rm -rf suspend-*
185+
dlogc "Run the command: $SLEEPGRAPH_PATH -rtcwake ${sleep_lst[$i]} -m freeze" #TODO: change it back to mem
186+
sudo "$SLEEPGRAPH_PATH" -rtcwake "${sleep_lst[$i]}" -m freeze ||
187+
dump_and_die "rtcwake returned $?"
188+
analyze_sleepgraph_results
189+
else
190+
dlogc "Run the command: rtcwake -m mem -s ${sleep_lst[$i]}"
191+
sudo rtcwake -m mem -s "${sleep_lst[$i]}" ||
192+
dump_and_die "rtcwake returned $?"
193+
fi
194+
}
195+
173196
sleep_once()
174197
{
175198
local i="$1"
@@ -179,9 +202,7 @@ sleep_once()
179202
setup_kernel_check_point
180203
expected_wakeup_count=$((expected_wakeup_count+1))
181204
expected_stats_success=$((expected_stats_success+1))
182-
dlogc "Run the command: rtcwake -m mem -s ${sleep_lst[$i]}"
183-
sudo rtcwake -m mem -s "${sleep_lst[$i]}" ||
184-
dump_and_die "rtcwake returned $?"
205+
run_rtcwake
185206
dlogc "sleep for ${wait_lst[$i]}"
186207
sleep ${wait_lst[$i]}
187208
dlogi "Check for the kernel log status"

test-case/sleepgraph-wrapper.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
##
4+
## Case Name: Wrapper to run a given test case with sleepgraph.py in setup that cannot set the environment variable.
5+
## Keep this script as simple as possible and avoid additional layers of indirections when possible.
6+
## Preconditions:
7+
## Sleepgraph.py script is available.
8+
## Description:
9+
## This script serves as a wrapper to execute a test case script with additionally running sleepgraph.py.
10+
## It expects the test case script file name (without path) as the first parameter,
11+
## followed by other parameters required for that test case.
12+
##
13+
14+
set -e
15+
16+
# Ensure the test case script file name is provided
17+
if [ -z "$1" ]; then
18+
echo "Error: No test case script file name provided. Exiting..."
19+
exit 1
20+
fi
21+
22+
# Check if sleepgraph is installed
23+
export SLEEPGRAPH_PATH="$HOME/pm-graph/sleepgraph.py"
24+
if [ ! -f "$SLEEPGRAPH_PATH" ]; then
25+
echo "Sleepgraph is not installed! Exiting..."
26+
exit 1
27+
fi
28+
29+
export RUN_SLEEPGRAPH=true
30+
31+
TESTDIR=$(realpath -e "$(dirname "${BASH_SOURCE[0]}")/..")
32+
33+
# shellcheck disable=SC2145
34+
[ -x "$TESTDIR/test-case/$(basename "$1")" ] && exec "$TESTDIR"/test-case/"$@"

tools/analyze-powertop-results.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from bs4 import BeautifulSoup
2+
import re
3+
import sys
4+
import json
5+
6+
ACCEPTANCE_RANGE=0.2
7+
8+
9+
def analyze_powertop_file(file, thresholds):
10+
with open(file, 'r', encoding='utf-8') as f:
11+
soup = BeautifulSoup(f, 'lxml')
12+
complete_results={}
13+
test_passed=True
14+
15+
components=thresholds.keys()
16+
for component in components:
17+
results = {}
18+
divs = soup.find_all("div", title=lambda t: t and component in t)
19+
20+
for div in divs:
21+
title = div.get('title')
22+
# print(title)
23+
match = re.search(r'\((\d+(?:\.\d+)?)\s*ms\)\s+(\S+)$', title)
24+
if match:
25+
time_ms = float(match.group(1))
26+
measurement_name = match.group(2)
27+
if measurement_name in thresholds[component]:
28+
results[measurement_name] = {"value": time_ms, "pass": True}
29+
threshold = float(thresholds[component][measurement_name])
30+
if time_ms<(threshold * (1-acceptance_range)) and time_ms>(threshold * (1+acceptance_range)):
31+
results[measurement_name]["pass"] = False
32+
test_passed = False
33+
34+
complete_results[component]=results
35+
36+
print(complete_results)
37+
return test_passed, complete_results
38+
39+
40+
if __name__ == "__main__":
41+
if len(sys.argv) != 3:
42+
print("Incorrect args. Usage: python3 analyze-powertop-results.py <path_to_csv_file> <expected_pc10_%")
43+
sys.exit(1)
44+
45+
filename = sys.argv[1]
46+
threshold = sys.argv[2]
47+
48+
test_passed, results = analyze_powertop_file(filename, threshold)
49+
sys.exit(0 if test_passed else 1)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from bs4 import BeautifulSoup
2+
import re
3+
import sys
4+
import json
5+
6+
ACCEPTANCE_RANGE=0.2
7+
8+
9+
def analyze_sleepgraph_file(file, thresholds, acceptance_range=ACCEPTANCE_RANGE):
10+
with open(file, 'r', encoding='utf-8') as f:
11+
soup = BeautifulSoup(f, 'lxml')
12+
complete_results={}
13+
test_passed=True
14+
15+
components=thresholds.keys()
16+
for component in components:
17+
results = {}
18+
divs = soup.find_all("div", title=lambda t: t and component in t)
19+
20+
for div in divs:
21+
title = div.get('title')
22+
# print(title)
23+
match = re.search(r'\((\d+(?:\.\d+)?)\s*ms\)\s+(\S+)$', title)
24+
if match:
25+
time_ms = float(match.group(1))
26+
measurement_name = match.group(2)
27+
if measurement_name in thresholds[component]:
28+
results[measurement_name] = {"value": time_ms, "pass": True}
29+
threshold = float(thresholds[component][measurement_name])
30+
if time_ms<(threshold * (1-acceptance_range)) and time_ms>(threshold * (1+acceptance_range)):
31+
results[measurement_name]["pass"] = False
32+
test_passed = False
33+
34+
complete_results[component]=results
35+
36+
print(complete_results)
37+
return test_passed, complete_results
38+
39+
40+
if __name__ == "__main__":
41+
if len(sys.argv) != 3:
42+
print("Incorrect args. Usage: python3 analyze-sleepgraph-results.py <path_to_html_file> <thresholds_as_json_str>")
43+
sys.exit(1)
44+
45+
sleepgraph_file = sys.argv[1]
46+
thresholds = json.loads(sys.argv[2])
47+
48+
test_passed, results = analyze_sleepgraph_file(sleepgraph_file, thresholds)
49+
sys.exit(0 if test_passed else 1)

0 commit comments

Comments
 (0)