kselftest: Add basic test for probing the rust sample modules
PATCH v4 1/1 kselftest: Add basic test for probing the rust sample modules
Add new basic kselftest that checks if the available rust sample modules can be added and removed correctly.
---
Depends on:
- https://lore.kernel.org/all/[email protected]/T/#u
- https://lore.kernel.org/all/[email protected]/
Changes in v4:
- Added config file
Changes in v3:
- Removed useless KSFT_PASS, KSFT_FAIL, KSFT_SKIP constants
- Used ktap_finished to print the results summary and handle the return code Changes in v2:
- Added missing SPDX line
- Edited test_probe_samples.sh script to use the common KTAP helpers file
--- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/rust/Makefile | 4 +++ tools/testing/selftests/rust/config | 5 +++ .../selftests/rust/test_probe_samples.sh | 34 +++++++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 tools/testing/selftests/rust/Makefile create mode 100644 tools/testing/selftests/rust/config create mode 100755 tools/testing/selftests/rust/test_probe_samples.sh
MAINTAINERS +1 -0
@@ -19231,6 +19231,7 @@ F: Documentation/rust/ F: rust/ F: samples/rust/ F: scripts/*rust* +F: tools/testing/selftests/rust/ K: \b(?i:rust)\b RXRPC SOCKETS (AF_RXRPC)
tools/testing/selftests/Makefile +1 -0
@@ -80,6 +80,7 @@ TARGETS += riscv TARGETS += rlimits TARGETS += rseq TARGETS += rtc +TARGETS += rust TARGETS += seccomp TARGETS += sgx TARGETS += sigaltstack
tools/testing/selftests/rust/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 +TEST_PROGS += test_probe_samples.sh + +include ../lib.mk
tools/testing/selftests/rust/config new file +5 -0
@@ -0,0 +1,5 @@ +CONFIG_RUST=y +CONFIG_SAMPLES=y +CONFIG_SAMPLES_RUST=y +CONFIG_SAMPLE_RUST_MINIMAL=m +CONFIG_SAMPLE_RUST_PRINT=m
tools/testing/selftests/rust/test_probe_samples.sh new file +34 -0
@@ -0,0 +1,34 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2023 Collabora Ltd +# +# This script tests whether the rust sample modules can +# be added and removed correctly. +# + +DIR="$(dirname "$(readlink -f "$0")")" + +source "${DIR}"/../kselftest/ktap_helpers.sh + +rust_sample_modules=("rust_minimal" "rust_print") + +ktap_print_header + +ktap_set_plan "${#rust_sample_modules[@]}" + +for sample in "${rust_sample_modules[@]}"; do + if ! /sbin/modprobe -n -q "$sample"; then + ktap_test_skip "module $sample is not found in /lib/modules/$(uname -r)" + continue + fi + + if /sbin/modprobe -q "$sample"; then + /sbin/modprobe -q -r "$sample" + ktap_test_pass "$sample" + else + ktap_test_fail "$sample" + fi +done + +ktap_finished
Signature · 1 line
2.30.2
Shuah Khan
maintainerHi Laura,
Quoted 25 lines · Laura Nao
Add new basic kselftest that checks if the available rust sample modules can be added and removed correctly.
Signed-off-by Laura Nao <[email protected]>Reviewed-by Sergio Gonzalez Collado <[email protected]>Reviewed-by Muhammad Usama Anjum <[email protected]>---
Depends on:
- https://lore.kernel.org/all/[email protected]/T/#u
- https://lore.kernel.org/all/[email protected]/
Changes in v4:
- Added config file
Changes in v3:
- Removed uselessKSFT_PASS,KSFT_FAIL,KSFT_SKIPconstants
- Usedktap_finishedto print the results summary and handle the return code Changes in v2:
- Added missing SPDX line
- Editedtest_probe_samples.shscript to use the common KTAP helpers file--- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/rust/Makefile | 4 +++ tools/testing/selftests/rust/config | 5 +++ .../selftests/rust/test_probe_samples.sh | 34 +++++++++++++++++++ 5 files changed, 45 insertions(+)
Quoted 4 lines
create mode 100644
tools/testing/selftests/rust/Makefilecreate mode 100644tools/testing/selftests/rust/configcreate mode 100755tools/testing/selftests/rust/test_probe_samples.sh
I ran test again and I still see the same. I would like to see the script to handle error conditions.
MAINTAINERS
Quoted 6 lines
MAINTAINERS +4
-0+ +DIR="$(dirname "$(readlink -f "$0")")" + +source "${DIR}"/../kselftest/ktap_helpers.sh
It tries to source and keeps going. Why can't we test for the file to exist and skip gracefully without printing the following messages.
./test_probe_samples.sh: line 12: /linux/linux_6.8/tools/testing/selftests/rust/../kselftest/ktap_helpers.sh: No such file or director
# ./test_probe_samples.sh: line 16: ktap_print_header: command not found
# ./test_probe_samples.sh: line 18: ktap_set_plan: command not found
# ./test_probe_samples.sh: line 22: ktap_test_skip: command not found
# ./test_probe_samples.sh: line 22: ktap_test_skip: command not found
# ./test_probe_samples.sh: line 34: ktap_finished: command not found
not ok 1 selftests: rust: test_probe_samples.sh # exit=127
MAINTAINERS
Quoted 11 lines
MAINTAINERS +11
-0+ +rust_sample_modules=("rust_minimal" "rust_print") + +ktap_print_header + +ktap_set_plan "${#rust_sample_modules[@]}" + +for sample in "${rust_sample_modules[@]}"; do + if ! /sbin/modprobe -n -q "$sample"; then + ktap_test_skip "module $sample is not found in /lib/modules/$(uname -r)" + continue
Why are we continuing here? Isn't this skip condition?
MAINTAINERS
Quoted 11 lines
MAINTAINERS +11
-0+ fi + + if /sbin/modprobe -q "$sample"; then + /sbin/modprobe -q -r "$sample" + ktap_test_pass "$sample" + else + ktap_test_fail "$sample" + fi +done + +ktap_finished
I would like to see the test exit with skip code when RUST isn't enabled. Please refer to existing tests that do this properly.
thanks,
-- Shuah
Hi Shuah,
Quoted 60 lines · Shuah Khan
Hi Laura,
Quoted 28 lines · Laura Nao
Add new basic kselftest that checks if the available rust sample modules can be added and removed correctly.
Signed-off-by Laura Nao <[email protected]>Reviewed-by Sergio Gonzalez Collado <[email protected]>Reviewed-by Muhammad Usama Anjum <[email protected]>---
Depends on:
-
https://lore.kernel.org/all/[email protected]/T/#u
-
https://lore.kernel.org/all/[email protected]/
Changes in v4:
- Added config file
Changes in v3:
- Removed uselessKSFT_PASS,KSFT_FAIL,KSFT_SKIPconstants
- Usedktap_finishedto print the results summary and handle the return code
Changes in v2:
- Added missing SPDX line
- Editedtest_probe_samples.shscript to use the common KTAP helpers file--- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/rust/Makefile | 4 +++ tools/testing/selftests/rust/config | 5 +++ .../selftests/rust/test_probe_samples.sh | 34 +++++++++++++++++++ 5 files changed, 45 insertions(+)Quoted 4 lines
create mode 100644
tools/testing/selftests/rust/Makefilecreate mode 100644tools/testing/selftests/rust/configcreate mode 100755tools/testing/selftests/rust/test_probe_samples.shI ran test again and I still see the same. I would like to see the script to handle error conditions.
MAINTAINERS
Quoted 6 lines
MAINTAINERS +4
-0+ +DIR="$(dirname "$(readlink -f "$0")")" + +source "${DIR}"/../kselftest/ktap_helpers.shIt tries to source and keeps going. Why can't we test for the file to exist and skip gracefully without printing the following messages.
./test_probe_samples.sh: line 12:
/linux/linux_6.8/tools/testing/selftests/rust/../kselftest/ktap_helpers.sh: No such file or director # ./test_probe_samples.sh: line 16:ktap_print_header: command not found
# ./test_probe_samples.sh: line 18:ktap_set_plan: command not found
# ./test_probe_samples.sh: line 22:ktap_test_skip: command not found
# ./test_probe_samples.sh: line 22:ktap_test_skip: command not found
# ./test_probe_samples.sh: line 34:ktap_finished: command not found
Quoted 3 lines
not ok 1 selftests: rust:
test_probe_samples.sh# exit=127
Sorry, I misunderstood the request in your previous reply on v3 - will do.
Quoted 6 lines
Quoted 6 lines
MAINTAINERS +6
-0+ +rust_sample_modules=("rust_minimal" "rust_print") + +ktap_print_header + +ktap_set_plan "${#rust_sample_modules[@]}"
Quoted 9 lines
Quoted 6 lines
MAINTAINERS +4
-0+ +for sample in "${rust_sample_modules[@]}"; do + if ! /sbin/modprobe -n -q "$sample"; then + ktap_test_skip "module $sample is not found in/lib/modules/$(uname -r)"
+ continueWhy are we continuing here? Isn't this skip condition?
At first, I hadn't planned for the kselftest to skip entirely if only one of the two sample modules was missing. However, considering that this kselftest is designed to test all available sample modules, and given that both are enabled with the provided configuration file, I believe it's more logical to verify the presence of both modules before running the test. If either of them is missing, then we exit the test with a skip code. This also covers the case where rust is not available.
Quoted 7 lines
Quoted 7 lines
MAINTAINERS +7
-0+ fi + + if /sbin/modprobe -q "$sample"; then + /sbin/modprobe -q -r "$sample" + ktap_test_pass "$sample" + else + ktap_test_fail "$sample"
Quoted 9 lines
MAINTAINERS
Quoted 4 lines
MAINTAINERS +4
-0+ fi +done + +ktap_finishedI would like to see the test exit with skip code when RUST isn't enabled. Please refer to existing tests that do this properly.
Sent a v5 with the changes mentioned above: https://lore.kernel.org/linux-kselftest/[email protected]/T/#u
Thanks!
Laura