Skip to content

Commit 05564c2

Browse files
committed
selftests: livepatch: Fix it to do root uid check and skip
livepatch test configures the system and debug environment to run tests. Some of these actions fail without root access and test dumps several permission denied messages before it exits. Fix test-state.sh to call setup_config instead of set_dynamic_debug as suggested by Petr Mladek <pmladek@suse.com> Fix it to check root uid and exit with skip code instead. Signed-off-by: Shuah Khan <skhan@linuxfoundation.org> Acked-by: Joe Lawrence <joe.lawrence@redhat.com> Reviewed-by: Petr Mladek <pmladek@suse.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent c65e415 commit 05564c2

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

tools/testing/selftests/livepatch/functions.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
MAX_RETRIES=600
88
RETRY_INTERVAL=".1" # seconds
99

10+
# Kselftest framework requirement - SKIP code is 4
11+
ksft_skip=4
12+
1013
# log(msg) - write message to kernel log
1114
# msg - insightful words
1215
function log() {
@@ -18,7 +21,16 @@ function log() {
1821
function skip() {
1922
log "SKIP: $1"
2023
echo "SKIP: $1" >&2
21-
exit 4
24+
exit $ksft_skip
25+
}
26+
27+
# root test
28+
function is_root() {
29+
uid=$(id -u)
30+
if [ $uid -ne 0 ]; then
31+
echo "skip all tests: must be run as root" >&2
32+
exit $ksft_skip
33+
fi
2234
}
2335

2436
# die(msg) - game over, man
@@ -62,6 +74,7 @@ function set_ftrace_enabled() {
6274
# for verbose livepatching output and turn on
6375
# the ftrace_enabled sysctl.
6476
function setup_config() {
77+
is_root
6578
push_config
6679
set_dynamic_debug
6780
set_ftrace_enabled 1

tools/testing/selftests/livepatch/test-state.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ MOD_LIVEPATCH=test_klp_state
88
MOD_LIVEPATCH2=test_klp_state2
99
MOD_LIVEPATCH3=test_klp_state3
1010

11-
set_dynamic_debug
12-
11+
setup_config
1312

1413
# TEST: Loading and removing a module that modifies the system state
1514

0 commit comments

Comments
 (0)