Skip to content

Commit c7e8470

Browse files
musamaanjumshuahkh
authored andcommitted
selftests: cpufreq: conform test to TAP
This test outputs lots of information. Let's conform the core part of the test to TAP and leave the information printing messages for now. Include ktap_helpers.sh to print conformed logs. Use KSFT_* macros to return the correct exit code for the kselftest framework and CIs to understand the exit status. Signed-off-by: Muhammad Usama Anjum <[email protected]> Acked-by: Viresh Kumar <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 557f137 commit c7e8470

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

tools/testing/selftests/cpufreq/cpufreq.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ cpufreq_basic_tests()
178178

179179
count=$(count_cpufreq_managed_cpus)
180180
if [ $count = 0 ]; then
181-
printf "No cpu is managed by cpufreq core, exiting\n"
182-
exit;
181+
ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting\n"
183182
else
184183
printf "CPUFreq manages: $count CPUs\n\n"
185184
fi

tools/testing/selftests/cpufreq/main.sh

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ source governor.sh
77
source module.sh
88
source special-tests.sh
99

10+
DIR="$(dirname $(readlink -f "$0"))"
11+
source "${DIR}"/../kselftest/ktap_helpers.sh
12+
1013
FUNC=basic # do basic tests by default
1114
OUTFILE=cpufreq_selftest
1215
SYSFS=
1316
CPUROOT=
1417
CPUFREQROOT=
1518

16-
# Kselftest framework requirement - SKIP code is 4.
17-
ksft_skip=4
18-
1919
helpme()
2020
{
2121
printf "Usage: $0 [-h] [-todg args]
@@ -32,38 +32,38 @@ helpme()
3232
[-d <driver's module name: only with \"-t modtest>\"]
3333
[-g <governor's module name: only with \"-t modtest>\"]
3434
\n"
35-
exit 2
35+
exit "${KSFT_FAIL}"
3636
}
3737

3838
prerequisite()
3939
{
4040
msg="skip all tests:"
4141

4242
if [ $UID != 0 ]; then
43-
echo $msg must be run as root >&2
44-
exit $ksft_skip
43+
ktap_skip_all "$msg must be run as root"
44+
exit "${KSFT_SKIP}"
4545
fi
4646

4747
taskset -p 01 $$
4848

4949
SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
5050

5151
if [ ! -d "$SYSFS" ]; then
52-
echo $msg sysfs is not mounted >&2
53-
exit 2
52+
ktap_skip_all "$msg sysfs is not mounted"
53+
exit "${KSFT_SKIP}"
5454
fi
5555

5656
CPUROOT=$SYSFS/devices/system/cpu
5757
CPUFREQROOT="$CPUROOT/cpufreq"
5858

5959
if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then
60-
echo $msg cpus not available in sysfs >&2
61-
exit 2
60+
ktap_skip_all "$msg cpus not available in sysfs"
61+
exit "${KSFT_SKIP}"
6262
fi
6363

6464
if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then
65-
echo $msg cpufreq directory not available in sysfs >&2
66-
exit 2
65+
ktap_skip_all "$msg cpufreq directory not available in sysfs"
66+
exit "${KSFT_SKIP}"
6767
fi
6868
}
6969

@@ -105,8 +105,7 @@ do_test()
105105
count=$(count_cpufreq_managed_cpus)
106106

107107
if [ $count = 0 -a $FUNC != "modtest" ]; then
108-
echo "No cpu is managed by cpufreq core, exiting"
109-
exit 2;
108+
ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting"
110109
fi
111110

112111
case "$FUNC" in
@@ -125,8 +124,7 @@ do_test()
125124
"modtest")
126125
# Do we have modules in place?
127126
if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then
128-
echo "No driver or governor module passed with -d or -g"
129-
exit 2;
127+
ktap_exit_fail_msg "No driver or governor module passed with -d or -g"
130128
fi
131129

132130
if [ $DRIVER_MOD ]; then
@@ -137,8 +135,7 @@ do_test()
137135
fi
138136
else
139137
if [ $count = 0 ]; then
140-
echo "No cpu is managed by cpufreq core, exiting"
141-
exit 2;
138+
ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting"
142139
fi
143140

144141
module_governor_test $GOVERNOR_MOD
@@ -162,7 +159,7 @@ do_test()
162159
;;
163160

164161
*)
165-
echo "Invalid [-f] function type"
162+
ktap_print_msg "Invalid [-f] function type"
166163
helpme
167164
;;
168165
esac
@@ -186,13 +183,25 @@ dmesg_dumps()
186183
dmesg >> $1.dmesg_full.txt
187184
}
188185

186+
ktap_print_header
187+
189188
# Parse arguments
190189
parse_arguments $@
191190

191+
ktap_set_plan 1
192+
192193
# Make sure all requirements are met
193194
prerequisite
194195

195196
# Run requested functions
196197
clear_dumps $OUTFILE
197198
do_test | tee -a $OUTFILE.txt
199+
if [ "${PIPESTATUS[0]}" -ne 0 ]; then
200+
exit ${PIPESTATUS[0]};
201+
fi
198202
dmesg_dumps $OUTFILE
203+
204+
ktap_test_pass "Completed successfully"
205+
206+
ktap_print_totals
207+
exit "${KSFT_PASS}"

tools/testing/selftests/cpufreq/module.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@ test_basic_insmod_rmmod()
2424
# insert module
2525
insmod $1
2626
if [ $? != 0 ]; then
27-
printf "Insmod $1 failed\n"
28-
exit;
27+
ktap_exit_fail_msg "Insmod $1 failed\n"
2928
fi
3029

3130
printf "Removing $1 module\n"
3231
# remove module
3332
rmmod $1
3433
if [ $? != 0 ]; then
35-
printf "rmmod $1 failed\n"
36-
exit;
34+
ktap_exit_fail_msg "rmmod $1 failed\n"
3735
fi
3836

3937
printf "\n"

0 commit comments

Comments
 (0)