From: Shin'ichiro Kawasaki Date: Mon, 13 Feb 2023 02:00:08 +0000 (+0900) Subject: check, common/rc: support normal user privilege X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=5f3bd34bf6260eca33aebed7870c25ef3530f31f;p=users%2Fsagi%2Fblktests.git check, common/rc: support normal user privilege To run commands with normal user privilege, add a new config variable NORMAL_USER and two helper functions _run_user and _require_normal_user. The user name specified to NORMAL_USER is used to run the commands specified to _run_user. The test cases which require NORMAL_USER shall call _require_normal_user to ensure the NORMAL_USER is valid. Tested-by: Kanchan Joshi Signed-off-by: Shin'ichiro Kawasaki --- diff --git a/Documentation/running-tests.md b/Documentation/running-tests.md index 586be0b..3550f37 100644 --- a/Documentation/running-tests.md +++ b/Documentation/running-tests.md @@ -113,6 +113,16 @@ use_siw=1 ./check nvmeof-mp/ use_siw=1 ./check srp/ ``` +### Normal user + +To run test cases which require normal user privilege, prepare a user and +specify it to the `NORMAL_USER` variable. The test cases are skipped unless a +valid user is specified. + +```sh +NORMAL_USER=blktests_user +``` + ### Custom Setup The `config` file is really just a bash file that is sourced at the beginning diff --git a/check b/check index 34e96c4..8eaf5c6 100755 --- a/check +++ b/check @@ -799,6 +799,7 @@ fi : "${LOGGER_PROG:="$(type -P logger || echo true)"}" : "${RUN_ZONED_TESTS:=0}" +: "${NORMAL_USER:=''}" # Sanity check options. if [[ $QUICK_RUN -ne 0 && ! "${TIMEOUT:-}" ]]; then diff --git a/common/rc b/common/rc index ef23ebe..af4c0b1 100644 --- a/common/rc +++ b/common/rc @@ -381,6 +381,14 @@ _require_test_dev_is_partition() { return 0 } +_require_normal_user() { + if ! id "$NORMAL_USER" >/dev/null 2>&1; then + SKIP_REASONS+=("valid NORMAL_USER is not specfied") + return 1 + fi + return 0 +} + # Prints a space-separated list with the names of all I/O schedulers supported # by block device $1. _io_schedulers() { @@ -409,3 +417,8 @@ _have_writeable_kmsg() { fi return 0 } + +# Run the given command as NORMAL_USER +_run_user() { + su "$NORMAL_USER" -c "$1" +}