]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
check, common/rc: support normal user privilege
authorShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Mon, 13 Feb 2023 02:00:08 +0000 (11:00 +0900)
committerShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Tue, 28 Feb 2023 03:47:05 +0000 (12:47 +0900)
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 <joshi.k@samsung.com>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Documentation/running-tests.md
check
common/rc

index 586be0b47a7ca9153a9f7eedf6634575d7176482..3550f377f487dae2bb883bb7bee39ffc90ba2a2d 100644 (file)
@@ -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 34e96c487f3923604a29c9a92ca93a4a237314f0..8eaf5c65167cbd2107decda4e7716a8ffc7b083a 100755 (executable)
--- 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
index ef23ebee770460c8b0408f6ce974d4c67c489a9c..af4c0b1cab22af3663a5b6f816b7e65a4ebd317a 100644 (file)
--- 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"
+}