Skip to content

Commit

Permalink
selftests: livepatch: Fix it to do root uid check and skip
Browse files Browse the repository at this point in the history
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 <[email protected]>

Fix it to check root uid and exit with skip code instead.

Signed-off-by: Shuah Khan <[email protected]>
Acked-by: Joe Lawrence <[email protected]>
Reviewed-by: Petr Mladek <[email protected]>
Signed-off-by: Shuah Khan <[email protected]>
  • Loading branch information
shuahkh committed Dec 23, 2019
1 parent c65e415 commit 05564c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 14 additions & 1 deletion tools/testing/selftests/livepatch/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
MAX_RETRIES=600
RETRY_INTERVAL=".1" # seconds

# Kselftest framework requirement - SKIP code is 4
ksft_skip=4

# log(msg) - write message to kernel log
# msg - insightful words
function log() {
Expand All @@ -18,7 +21,16 @@ function log() {
function skip() {
log "SKIP: $1"
echo "SKIP: $1" >&2
exit 4
exit $ksft_skip
}

# root test
function is_root() {
uid=$(id -u)
if [ $uid -ne 0 ]; then
echo "skip all tests: must be run as root" >&2
exit $ksft_skip
fi
}

# die(msg) - game over, man
Expand Down Expand Up @@ -62,6 +74,7 @@ function set_ftrace_enabled() {
# for verbose livepatching output and turn on
# the ftrace_enabled sysctl.
function setup_config() {
is_root
push_config
set_dynamic_debug
set_ftrace_enabled 1
Expand Down
3 changes: 1 addition & 2 deletions tools/testing/selftests/livepatch/test-state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ MOD_LIVEPATCH=test_klp_state
MOD_LIVEPATCH2=test_klp_state2
MOD_LIVEPATCH3=test_klp_state3

set_dynamic_debug

setup_config

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

Expand Down

0 comments on commit 05564c2

Please sign in to comment.