Skip to content

Commit b83a523

Browse files
committed
test: PC10 residency and resume time
Add option to run check-suspend-resume test with sleepgraph, to measure resume time. Updated test-socwatch to measure residency time. Signed-off-by: Emilia Kurdybelska <emiliax.kurdybelska@intel.com>
1 parent 60f43ba commit b83a523

File tree

3 files changed

+228
-58
lines changed

3 files changed

+228
-58
lines changed

test-case/check-suspend-resume.sh

Lines changed: 81 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -e
55
##
66
## Case Name: check suspend/resume status
77
## Preconditions:
8-
## N/A
8+
## - (if ran with --sleepgraph) Sleepgraph installed on dut
99
## Description:
1010
## Run the suspend/resume command to check device status
1111
## Case step:
@@ -26,27 +26,36 @@ source "$TOPDIR"/case-lib/lib.sh
2626
random_min=3 # wait time should >= 3 for other device wakeup from sleep
2727
random_max=20
2828

29-
OPT_NAME['l']='loop' OPT_DESC['l']='loop count'
30-
OPT_HAS_ARG['l']=1 OPT_VAL['l']=5
29+
OPT_NAME['l']='loop' OPT_DESC['l']='loop count'
30+
OPT_HAS_ARG['l']=1 OPT_VAL['l']=5
3131

32-
OPT_NAME['T']='type' OPT_DESC['T']="suspend/resume type from /sys/power/mem_sleep"
33-
OPT_HAS_ARG['T']=1 OPT_VAL['T']=""
32+
OPT_NAME['T']='type' OPT_DESC['T']="suspend/resume type from /sys/power/mem_sleep"
33+
OPT_HAS_ARG['T']=1 OPT_VAL['T']=""
3434

35-
OPT_NAME['S']='sleep' OPT_DESC['S']='suspend/resume command:rtcwake sleep duration'
36-
OPT_HAS_ARG['S']=1 OPT_VAL['S']=5
35+
OPT_NAME['S']='sleep' OPT_DESC['S']='suspend/resume command:rtcwake sleep duration'
36+
OPT_HAS_ARG['S']=1 OPT_VAL['S']=5
3737

38-
OPT_NAME['u']='unload-audio' OPT_DESC['u']='unload audio modules for the test'
39-
OPT_HAS_ARG['u']=0 OPT_VAL['u']=0
38+
OPT_NAME['u']='unload-audio' OPT_DESC['u']='unload audio modules for the test'
39+
OPT_HAS_ARG['u']=0 OPT_VAL['u']=0
4040

41-
OPT_NAME['w']='wait' OPT_DESC['w']='idle time after suspend/resume wakeup'
42-
OPT_HAS_ARG['w']=1 OPT_VAL['w']=5
41+
OPT_NAME['w']='wait' OPT_DESC['w']='idle time after suspend/resume wakeup'
42+
OPT_HAS_ARG['w']=1 OPT_VAL['w']=5
4343

44-
OPT_NAME['r']='random' OPT_DESC['r']="Randomly setup wait/sleep time, range is [$random_min-$random_max], this option will overwrite s & w option"
45-
OPT_HAS_ARG['r']=0 OPT_VAL['r']=0
44+
OPT_NAME['r']='random' OPT_DESC['r']="Randomly setup wait/sleep time, range is [$random_min-$random_max], this option will overwrite s & w option"
45+
OPT_HAS_ARG['r']=0 OPT_VAL['r']=0
4646

4747
# processid is set by check-suspend-resume-with-audio.sh for audio test case
48-
OPT_NAME['p']='processid' OPT_DESC['p']='Fail immediately if this process dies'
49-
OPT_HAS_ARG['p']=1 OPT_VAL['p']=''
48+
OPT_NAME['p']='processid' OPT_DESC['p']='Fail immediately if this process dies'
49+
OPT_HAS_ARG['p']=1 OPT_VAL['p']=''
50+
51+
OPT_NAME['s']='sleepgraph' OPT_DESC['s']='run with sleepgraph (http://github.com/intel/pm-graph.git)'
52+
OPT_HAS_ARG['s']=0 OPT_VAL['s']=0
53+
54+
OPT_NAME['t']='resume-time' OPT_DESC['t']='resume time threshold'
55+
OPT_HAS_ARG['t']=1 OPT_VAL['t']=''
56+
57+
OPT_NAME['a']='acceptance-range' OPT_DESC['a']='acceptance range for thresholds'
58+
OPT_HAS_ARG['a']=1 OPT_VAL['a']=0.3
5059

5160
func_opt_parse_option "$@"
5261
func_lib_check_sudo
@@ -69,21 +78,28 @@ dlogi "Current suspend/resume type mode: $(cat /sys/power/mem_sleep)"
6978
loop_count=${OPT_VAL['l']}
7079
declare -a sleep_lst wait_lst
7180

72-
if [ ${OPT_VAL['r']} -eq 1 ]; then
81+
if [ "${OPT_VAL['r']}" -eq 1 ]; then
7382
# create random number list
74-
for i in $(seq 1 $loop_count)
83+
for i in $(seq 1 "$loop_count")
7584
do
76-
sleep_lst[$i]=$(func_lib_get_random $random_max $random_min)
77-
wait_lst[$i]=$(func_lib_get_random $random_max $random_min)
85+
sleep_lst[i]=$(func_lib_get_random $random_max $random_min)
86+
wait_lst[i]=$(func_lib_get_random $random_max $random_min)
7887
done
7988
else
80-
for i in $(seq 1 $loop_count)
89+
for i in $(seq 1 "$loop_count")
8190
do
82-
sleep_lst[$i]=${OPT_VAL['S']}
83-
wait_lst[$i]=${OPT_VAL['w']}
91+
sleep_lst[i]=${OPT_VAL['S']}
92+
wait_lst[i]=${OPT_VAL['w']}
8493
done
8594
fi
8695

96+
if [ "${OPT_VAL['s']}" -eq 1 ]; then
97+
if ! command -v sleepgraph >/dev/null 2>&1; then
98+
echo "Sleepgraph is not installed! Exiting..."
99+
exit 1
100+
fi
101+
fi
102+
87103
save_initial_stats()
88104
{
89105
printf '\n\n'
@@ -143,7 +159,7 @@ main()
143159

144160
local keep_modules=true already_unloaded=false
145161

146-
if [ ${OPT_VAL['u']} = 1 ]; then
162+
if [ "${OPT_VAL['u']}" = 1 ]; then
147163
keep_modules=false
148164
fi
149165

@@ -159,7 +175,7 @@ main()
159175
expected_wakeup_count=$(cat /sys/power/wakeup_count)
160176
expected_stats_success=$(cat /sys/power/suspend_stats/success)
161177
save_initial_stats
162-
for i in $(seq 1 $loop_count)
178+
for i in $(seq 1 "$loop_count")
163179
do
164180
sleep_once "$i"
165181
done
@@ -170,6 +186,45 @@ main()
170186
die "Found kernel error after reloading audio drivers"
171187
}
172188

189+
analyze_sleepgraph_results()
190+
{
191+
dlogi "Analyzing sleepgraph results"
192+
results_file=$(find suspend-*/*.html)
193+
cp "$results_file" "$LOG_ROOT/"
194+
195+
thresholds=$( jq -n \
196+
--arg resume_time "${OPT_VAL['t']}" \
197+
'{"sof-audio-pci-intel-ptl":{"resume":$resume_time}}')
198+
199+
thresholds_acceptance_range="${OPT_VAL['a']}"
200+
201+
dlogi "Analyzing $results_file file..."
202+
if python3 "$SCRIPT_HOME"/tools/analyze-sleepgraph-results.py "$results_file" "$thresholds" "$thresholds_acceptance_range"; then
203+
dlogi "All times measurements within the thresholds"
204+
return 0
205+
else
206+
dlogw "Time measurements not within the thresholds!"
207+
return 1
208+
fi
209+
}
210+
211+
run_rtcwake()
212+
{
213+
if [ "${OPT_VAL['s']}" -eq 1 ]; then
214+
# remove any files from previous sleepgraph runs
215+
rm -rf suspend-*
216+
217+
dlogc "Run the command: sleepgraph -rtcwake ${sleep_lst[$i]} -m freeze"
218+
sudo sleepgraph -rtcwake "${sleep_lst[$i]}" -m freeze ||
219+
dump_and_die "rtcwake returned $?"
220+
analyze_sleepgraph_results
221+
else
222+
dlogc "Run the command: rtcwake -m mem -s ${sleep_lst[$i]}"
223+
sudo rtcwake -m mem -s "${sleep_lst[$i]}" ||
224+
dump_and_die "rtcwake returned $?"
225+
fi
226+
}
227+
173228
sleep_once()
174229
{
175230
local i="$1"
@@ -179,11 +234,9 @@ sleep_once()
179234
setup_kernel_check_point
180235
expected_wakeup_count=$((expected_wakeup_count+1))
181236
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 $?"
237+
run_rtcwake
185238
dlogc "sleep for ${wait_lst[$i]}"
186-
sleep ${wait_lst[$i]}
239+
sleep "${wait_lst[$i]}"
187240
dlogi "Check for the kernel log status"
188241
# check kernel log for each iteration to catch issues
189242
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" || dump_and_die "Caught error in kernel log"

test-case/test-socwatch.sh

Lines changed: 73 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ OPT_NAME['u']='unload-audio' OPT_DESC['u']='unload audio modules for the test'
3838
OPT_HAS_ARG['u']=0 OPT_VAL['u']=0
3939

4040
: "${SOCWATCH_PATH:=$HOME/socwatch}"
41-
SOCWATCH_VERSION=$("$SOCWATCH_PATH"/socwatch --version |grep Version)
42-
43-
# reference cmd: sudo ./socwatch -t 20 -s 5 -f cpu-cstate -f pkg-pwr -o fredtest5
44-
#SOCWATCH_CMD="./socwatch"
45-
SOCWATCH_FEATURE_PARAMS=( -f cpu-cstate -f pkg-pwr )
41+
SOCWATCH_VERSION=$(sudo "$SOCWATCH_PATH"/socwatch --version | grep Version)
4642

4743
func_opt_parse_option "$@"
4844
func_lib_check_sudo
@@ -57,41 +53,57 @@ check_socwatch_module_loaded()
5753
lsmod | grep -q socwatch || dlogi "socwatch is not loaded"
5854
}
5955

56+
check_for_PC10_state()
57+
{
58+
pc10_count=$(awk '/Package C-State Summary: Entry Counts/{f=1; next} f && /PC10/{print $3; exit}' "$socwatch_output".csv)
59+
if [ -z "$pc10_count" ]; then
60+
die "PC10 State not achieved"
61+
fi
62+
dlogi "Entered into PC10 State $pc10_count times"
63+
64+
pc10_per=$(awk '/Package C-State Summary: Residency/{f=1; next} f && /PC10/{print $3; exit}' "$socwatch_output".csv)
65+
pc10_time=$(awk '/Package C-State Summary: Residency/{f=1; next} f && /PC10/{print $5; exit}' "$socwatch_output".csv)
66+
dlogi "Spent $pc10_time ms ($pc10_per %) in PC10 State"
67+
68+
json_str=$( jq -n \
69+
--arg id "$i" \
70+
--arg cnt "$pc10_count" \
71+
--arg time "$pc10_time" \
72+
--arg per "$pc10_per" \
73+
'{$id: {pc10_entires_count: $cnt, time_ms: $time, time_percentage: $per}}' )
74+
75+
results=$(jq --slurp 'add' <(echo "$results") <(echo "$json_str"))
76+
}
77+
6078
socwatch_test_once()
6179
{
6280
local i="$1"
6381
dlogi "===== Loop($i/$loop_count) ====="
6482
dlogi "SoCWatch version: ${SOCWATCH_VERSION}"
6583

84+
socwatch_output="$LOG_ROOT/socwatch-results/socwatch_output_$i"
85+
6686
# set up checkpoint for each iteration
6787
setup_kernel_check_point
6888

69-
# load socwatch module, if the module is loaded, go ahead with the testing (-q)
70-
sudo "$SOCWATCH_PATH"/drivers/insmod-socwatch -q || true
71-
check_socwatch_module_loaded || die "socwatch module not loaded"
72-
7389
( set -x
74-
sudo "$SOCWATCH_PATH"/socwatch -t "$duration" -s "$wait_time" "${SOCWATCH_FEATURE_PARAMS[@]}" -o "$SOCWATCH_PATH/sofsocwatch-$i" ) ||
90+
sudo "$SOCWATCH_PATH"/socwatch -m -f sys -f cpu -f cpu-hw -f pcie -f hw-cpu-cstate \
91+
-f pcd-slps0 -f tcss-state -f tcss -f pcie-lpm -n 200 -t "$duration" -s "$wait_time" \
92+
-r json -o "$socwatch_output" ) ||
7593
die "socwatch returned $?"
7694

77-
# filter output and copy to log directory
78-
grep "Package C-State Summary: Residency" -B 8 -A 11 "$SOCWATCH_PATH/sofsocwatch-$i.csv" | tee "$SOCWATCH_PATH/socwatch-$i.txt"
79-
grep "Package Power Summary: Average Rate" -B 6 -A 4 "$SOCWATCH_PATH/sofsocwatch-$i.csv" | tee -a "$SOCWATCH_PATH/socwatch-$i.txt"
80-
# zip original csv report
81-
gzip "$SOCWATCH_PATH/sofsocwatch-$i.csv"
82-
mv "$SOCWATCH_PATH/socwatch-$i.txt" "$SOCWATCH_PATH/sofsocwatch-$i.csv.gz" "$LOG_ROOT"/
95+
# analyze SoCWatch results
96+
check_for_PC10_state
8397

84-
dlogi "Check for the kernel log status"
8598
# check kernel log for each iteration to catch issues
99+
dlogi "Check for the kernel log status"
86100
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" || die "Caught error in kernel log"
87-
88-
# unload socwatch module
89-
sudo "$SOCWATCH_PATH"/drivers/rmmod-socwatch || true
90101
}
91102

92-
main()
103+
unload_modules()
93104
{
94-
local keep_modules=true already_unloaded=false
105+
keep_modules=true
106+
already_unloaded=false
95107

96108
[ -d "$SOCWATCH_PATH" ] ||
97109
die "SOCWATCH not found in SOCWATCH_PATH=$SOCWATCH_PATH"
@@ -106,22 +118,53 @@ main()
106118
dlogw 'modules already unloaded, ignoring option -u!'
107119
}
108120

109-
$already_unloaded || $keep_modules || "$TOPDIR"/tools/kmod/sof_remove.sh ||
121+
if ! [ $already_unloaded ] || [ $keep_modules ]; then
122+
"$TOPDIR"/tools/kmod/sof_remove.sh ||
110123
die "Failed to unload audio drivers"
124+
fi
125+
}
126+
127+
load_modules()
128+
{
129+
if ! [ $already_unloaded ] || [ $keep_modules ]; then
130+
"$TOPDIR"/tools/kmod/sof_insert.sh ||
131+
die "Failed to reload audio drivers"
132+
fi
133+
134+
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" ||
135+
die "Found kernel error after reloading audio drivers"
136+
}
137+
138+
run_socwatch_tests()
139+
{
140+
# load socwatch module, if the module is loaded, go ahead with the testing
141+
sudo bash "$SOCWATCH_PATH"/drivers/insmod-socwatch || true
142+
check_socwatch_module_loaded || die "socwatch module not loaded"
143+
144+
mkdir "$LOG_ROOT/socwatch-results"
145+
pc10_results_file="$LOG_ROOT/socwatch-results/pc10_results.json"
146+
touch "$pc10_results_file"
111147

112-
# socwatch test from here
113148
for i in $(seq 1 "$loop_count")
114149
do
115150
socwatch_test_once "$i"
116151
done
152+
echo "$results" > "$pc10_results_file"
117153

118-
$already_unloaded || $keep_modules || "$TOPDIR"/tools/kmod/sof_insert.sh ||
119-
die "Failed to reload audio drivers"
120-
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" ||
121-
die "Found kernel error after reloading audio drivers"
154+
# zip all SoCWatch reports
155+
cd "$LOG_ROOT"
156+
tar -zcvf socwatch-results.tar.gz socwatch-results/
157+
rm -rf "$LOG_ROOT/socwatch-results/"
122158

123-
# DON"T delete socwatch directory after test, delete before new test
124-
# rm -rf $SOCWATCH_PATH
159+
# unload socwatch module
160+
sudo bash "$SOCWATCH_PATH"/drivers/rmmod-socwatch
161+
}
162+
163+
main()
164+
{
165+
unload_modules
166+
run_socwatch_tests
167+
load_modules
125168
}
126169

127170
main "$@"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
from bs4 import BeautifulSoup
2+
from pathlib import Path
3+
import re
4+
import sys
5+
import json
6+
import os
7+
8+
9+
# pylint: disable=R0914
10+
def analyze_sleepgraph_file(file, thresholds, acceptance_range):
11+
with open(file, 'r', encoding='utf-8') as f:
12+
soup = BeautifulSoup(f, 'lxml')
13+
complete_results={}
14+
test_passed=True
15+
16+
components=thresholds.keys()
17+
for component in components:
18+
# pylint: disable=W0621
19+
results = {}
20+
divs = soup.find_all("div", title=lambda t, component=component: t and component in t)
21+
22+
for div in divs:
23+
title = div.get('title')
24+
match = re.search(r'\((\d+(?:\.\d+)?)\s*ms\)\s+(\S+)$', title)
25+
if match:
26+
time_ms = float(match.group(1))
27+
measurement_name = match.group(2)
28+
if measurement_name in thresholds[component]:
29+
results[measurement_name] = {"value": time_ms, "pass": True}
30+
threshold = float(thresholds[component][measurement_name])
31+
# pylint: disable=R1716
32+
if time_ms<(threshold * (1-acceptance_range)) or time_ms>(threshold * (1+acceptance_range)):
33+
results[measurement_name]["pass"] = False
34+
test_passed = False
35+
36+
complete_results[component]=results
37+
38+
print(complete_results)
39+
return test_passed, complete_results
40+
41+
42+
def save_results_to_file(result):
43+
# pylint: disable=W0621
44+
results_file = f'{os.getenv("LOG_ROOT")}/resume_time_results.json'
45+
data = []
46+
47+
if Path(results_file).is_file():
48+
with open(results_file, 'r', encoding='utf-8') as f:
49+
data = json.load(f)
50+
51+
data.append(result)
52+
print(f"Current results: {data}")
53+
54+
with open(results_file, "w", encoding='utf-8') as f:
55+
f.write(json.dumps(data))
56+
return results_file
57+
58+
59+
if __name__ == "__main__":
60+
if len(sys.argv) != 4:
61+
print("Incorrect number of args!")
62+
sys.exit(1)
63+
64+
sleepgraph_file = sys.argv[1]
65+
sleepgraph_thresholds = json.loads(sys.argv[2])
66+
thresholds_buffer = float(sys.argv[3])
67+
68+
test_pass, results = analyze_sleepgraph_file(sleepgraph_file, sleepgraph_thresholds, thresholds_buffer)
69+
print(f"Sleepgraph report analysis passed: {test_pass}")
70+
71+
results_file = save_results_to_file(results)
72+
print(f"Saved results to file: {results_file}")
73+
74+
sys.exit(0 if test_pass else 1)

0 commit comments

Comments
 (0)