forked from thesofproject/sof-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresidency-time-test.sh
More file actions
executable file
·183 lines (147 loc) · 5.29 KB
/
residency-time-test.sh
File metadata and controls
executable file
·183 lines (147 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
set -e
##
## Case Name: check-soc-power-status
## Preconditions:
## Intel SoCwatch tool must be installed on the device
## Description:
## Run the socwatch command to check SoC power status
## Test steps:
## 1. load socwatch kernel module
## 2. run socwatch command with desired parameters
## 3. check return value from socwatch
## 4. collect logs
## 5. check dmesg errors
## 6. unload socwatch kernel module
## Expect result:
## consistent power status across tests
## check kernel log and find no errors
##
TOPDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
# shellcheck source=case-lib/lib.sh
source "${TOPDIR}"/case-lib/lib.sh
OPT_NAME['l']='loop' OPT_DESC['l']='loop count'
OPT_HAS_ARG['l']=1 OPT_VAL['l']=1
OPT_NAME['d']='duration' OPT_DESC['d']='duration time for socwatch to collect the data'
OPT_HAS_ARG['d']=1 OPT_VAL['d']=20
OPT_NAME['w']='wait' OPT_DESC['w']='idle time before starting socwatch to collect the data'
OPT_HAS_ARG['w']=1 OPT_VAL['w']=5
# TODO: socwatch test after unloading audio module might be useful
OPT_NAME['u']='unload-audio' OPT_DESC['u']='unload audio modules for the test'
OPT_HAS_ARG['u']=0 OPT_VAL['u']=0
: "${SOCWATCH_PATH:=$HOME/socwatch}"
SOCWATCH_VERSION=$(sudo "$SOCWATCH_PATH"/socwatch --version | grep Version)
func_opt_parse_option "$@"
func_lib_check_sudo
duration=${OPT_VAL['d']}
wait_time=${OPT_VAL['w']}
loop_count=${OPT_VAL['l']}
start_test
check_socwatch_module_loaded()
{
lsmod | grep -q socwatch || die "socwatch is not loaded"
}
check_for_PC10_state()
{
pc10_count=$(awk '/Package C-State Summary: Entry Counts/{f=1; next} f && /PC10/{print $3; exit}' "$socwatch_output".csv)
if [ -z "$pc10_count" ] || [ "$pc10_count" -eq 0 ]; then
dlogw "PC10 State not achieved"
else
dlogi "Entered into PC10 State $pc10_count times"
pc10_achieved=true # PC10 state needs to be entered at least once to pass the test
fi
pc10_per=$(awk '/Package C-State Summary: Residency/{f=1; next} f && /PC10/{print $3; exit}' "$socwatch_output".csv)
pc10_time=$(awk '/Package C-State Summary: Residency/{f=1; next} f && /PC10/{print $5; exit}' "$socwatch_output".csv)
dlogi "Spent $pc10_time ms ($pc10_per %) in PC10 State"
json_str=$( jq -n \
--arg id "$i" \
--arg cnt "$pc10_count" \
--arg time "$pc10_time" \
--arg per "$pc10_per" \
'{$id: {pc10_entires_count: $cnt, time_ms: $time, time_percentage: $per}}' )
results=$(jq --slurp 'add' <(echo "$results") <(echo "$json_str"))
}
socwatch_test_once()
{
local i="$1"
dlogi "===== Loop($i/$loop_count) ====="
dlogi "SoCWatch version: ${SOCWATCH_VERSION}"
socwatch_output="$LOG_ROOT/socwatch-results/socwatch_output_$i"
# set up checkpoint for each iteration
setup_kernel_check_point
( set -x
sudo "$SOCWATCH_PATH"/socwatch -m -f sys -f cpu -f cpu-hw -f hw-cpu-cstate \
-f tcss-state -f pcie-lpm -n 200 -t "$duration" -s "$wait_time" \
-r json -o "$socwatch_output" ) ||
die "socwatch returned $?"
# analyze SoCWatch results
check_for_PC10_state
# check kernel log for each iteration to catch issues
dlogi "Check for the kernel log status"
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" || die "Caught error in kernel log"
}
unload_modules()
{
keep_modules=true
already_unloaded=false
[ -d "$SOCWATCH_PATH" ] ||
die "SOCWATCH not found in SOCWATCH_PATH=$SOCWATCH_PATH"
if [ "${OPT_VAL['u']}" = 1 ]; then
keep_modules=false
fi
lsmod | grep -q snd_sof || {
already_unloaded=true
$keep_modules ||
dlogw 'modules already unloaded, ignoring option -u!'
}
if ! [ $already_unloaded ] || [ $keep_modules ]; then
"$TOPDIR"/tools/kmod/sof_remove.sh ||
die "Failed to unload audio drivers"
fi
}
load_modules()
{
if ! [ $already_unloaded ] || [ $keep_modules ]; then
"$TOPDIR"/tools/kmod/sof_insert.sh ||
die "Failed to reload audio drivers"
fi
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" ||
die "Found kernel error after reloading audio drivers"
}
run_socwatch_tests()
{
# load socwatch module, if the module is loaded, go ahead with the testing
sudo bash "$SOCWATCH_PATH"/drivers/insmod-socwatch || true
check_socwatch_module_loaded || die "socwatch module not loaded"
# Create a dir for all socwatch reports
mkdir "$LOG_ROOT/socwatch-results"
pc10_results_file="$LOG_ROOT/socwatch-results/pc10_results.json"
touch "$pc10_results_file"
pc10_achieved=false
for i in $(seq 1 "$loop_count")
do
socwatch_test_once "$i"
done
echo "$results" > "$pc10_results_file"
dlogi "****** PC10 STATE RESULTS: ******"
dlogi "$results"
dlogi "*********************************"
# zip all SoCWatch reports
cd "$LOG_ROOT"
tar -zcvf socwatch-results.tar.gz socwatch-results/
rm -rf "$LOG_ROOT/socwatch-results/"
# unload socwatch module
sudo bash "$SOCWATCH_PATH"/drivers/rmmod-socwatch
if "$pc10_achieved"; then
dlogi "PASS: PC10 state entered at least once"
else
die "FAIL: PC10 state NOT ENTERED"
fi
}
main()
{
unload_modules
run_socwatch_tests
load_modules
}
main "$@"