Skip to content

Commit 390174c

Browse files
Ming Leiaxboe
authored andcommitted
selftests: ublk: improve test usability
Add UBLK_TEST_QUIET, so we can print test result(PASS/SKIP/FAIL) only. Also always run from test script's current directory, then the same test script can be started from other work directory. This way helps a lot to reuse this test source code and scripts for other projects(liburing, blktests, ...) Signed-off-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20250303124324.3563605-12-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent af83ccc commit 390174c

8 files changed

Lines changed: 17 additions & 11 deletions

File tree

tools/testing/selftests/ublk/test_common.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ _prep_test() {
8080
local type=$1
8181
shift 1
8282
modprobe ublk_drv
83-
echo "ublk $type: $*"
83+
[ "$UBLK_TEST_QUIET" -eq 0 ] && echo "ublk $type: $*"
8484
}
8585

8686
_remove_test_files()
@@ -209,6 +209,12 @@ __run_io_and_remove()
209209
wait
210210
}
211211

212+
_ublk_test_top_dir()
213+
{
214+
cd "$(dirname "$0")" && pwd
215+
}
212216

213-
UBLK_PROG=$(pwd)/kublk
217+
UBLK_PROG=$(_ublk_test_top_dir)/kublk
218+
UBLK_TEST_QUIET=1
214219
export UBLK_PROG
220+
export UBLK_TEST_QUIET

tools/testing/selftests/ublk/test_loop_01.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4-
. test_common.sh
4+
. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
55

66
TID="loop_01"
77
ERR_CODE=0

tools/testing/selftests/ublk/test_loop_02.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4-
. test_common.sh
4+
. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
55

66
TID="loop_02"
77
ERR_CODE=0

tools/testing/selftests/ublk/test_loop_03.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4-
. test_common.sh
4+
. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
55

66
TID="loop_03"
77
ERR_CODE=0

tools/testing/selftests/ublk/test_loop_04.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4-
. test_common.sh
4+
. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
55

66
TID="loop_04"
77
ERR_CODE=0

tools/testing/selftests/ublk/test_null_01.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4-
. test_common.sh
4+
. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
55

66
TID="null_01"
77
ERR_CODE=0

tools/testing/selftests/ublk/test_stress_01.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4-
. test_common.sh
4+
. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
55
TID="stress_01"
66
ERR_CODE=0
77
DEV_ID=-1
@@ -17,7 +17,7 @@ ublk_io_and_remove()
1717
DEV_ID=$(_add_ublk_dev "$@")
1818
_check_add_dev $TID $? "${backfile}"
1919

20-
echo "run ublk IO vs. remove device(ublk add $*)"
20+
[ "$UBLK_TEST_QUIET" -eq 0 ] && echo "run ublk IO vs. remove device(ublk add $*)"
2121
if ! __run_io_and_remove "${DEV_ID}" "${size}" "no"; then
2222
echo "/dev/ublkc${DEV_ID} isn't removed"
2323
_remove_backfile "${backfile}"

tools/testing/selftests/ublk/test_stress_02.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4-
. test_common.sh
4+
. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
55
TID="stress_02"
66
ERR_CODE=0
77
DEV_ID=-1
@@ -17,7 +17,7 @@ ublk_io_and_kill_daemon()
1717
DEV_ID=$(_add_ublk_dev "$@")
1818
_check_add_dev $TID $? "${backfile}"
1919

20-
echo "run ublk IO vs kill ublk server(ublk add $*)"
20+
[ "$UBLK_TEST_QUIET" -eq 0 ] && echo "run ublk IO vs kill ublk server(ublk add $*)"
2121
if ! __run_io_and_remove "${DEV_ID}" "${size}" "yes"; then
2222
echo "/dev/ublkc${DEV_ID} isn't removed res ${res}"
2323
_remove_backfile "${backfile}"

0 commit comments

Comments
 (0)