kselftest: Add basic test for probing the rust sample modules
authorLaura Nao <laura.nao@collabora.com>
Thu, 29 Feb 2024 15:52:35 +0000 (16:52 +0100)
committerShuah Khan <skhan@linuxfoundation.org>
Mon, 4 Mar 2024 20:13:04 +0000 (13:13 -0700)
Add new basic kselftest that checks if the available rust sample modules
can be added and removed correctly.

Signed-off-by: Laura Nao <laura.nao@collabora.com>
Reviewed-by: Sergio Gonzalez Collado <sergio.collado@gmail.com>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
MAINTAINERS
tools/testing/selftests/Makefile
tools/testing/selftests/rust/Makefile [new file with mode: 0644]
tools/testing/selftests/rust/config [new file with mode: 0644]
tools/testing/selftests/rust/test_probe_samples.sh [new file with mode: 0755]

index f8f6207469340680edf3ace56e8d5e5cf5789b93..4eda22ec74dd75b4bcd583c9e059525bf02be0f9 100644 (file)
@@ -19095,6 +19095,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)
index 7e5960cda08c007d2a8fea8337b31a7088ead2c5..cd9ae576bfde3fcce5d4ae8733483d59d5bf13f6 100644 (file)
@@ -79,6 +79,7 @@ TARGETS += riscv
 TARGETS += rlimits
 TARGETS += rseq
 TARGETS += rtc
+TARGETS += rust
 TARGETS += seccomp
 TARGETS += sgx
 TARGETS += sigaltstack
diff --git a/tools/testing/selftests/rust/Makefile b/tools/testing/selftests/rust/Makefile
new file mode 100644 (file)
index 0000000..fce1584
--- /dev/null
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+TEST_PROGS += test_probe_samples.sh
+
+include ../lib.mk
diff --git a/tools/testing/selftests/rust/config b/tools/testing/selftests/rust/config
new file mode 100644 (file)
index 0000000..b4002ac
--- /dev/null
@@ -0,0 +1,5 @@
+CONFIG_RUST=y
+CONFIG_SAMPLES=y
+CONFIG_SAMPLES_RUST=y
+CONFIG_SAMPLE_RUST_MINIMAL=m
+CONFIG_SAMPLE_RUST_PRINT=m
\ No newline at end of file
diff --git a/tools/testing/selftests/rust/test_probe_samples.sh b/tools/testing/selftests/rust/test_probe_samples.sh
new file mode 100755 (executable)
index 0000000..ad0397e
--- /dev/null
@@ -0,0 +1,41 @@
+#!/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")")"
+
+KTAP_HELPERS="${DIR}/../kselftest/ktap_helpers.sh"
+if [ -e "$KTAP_HELPERS" ]; then
+    source "$KTAP_HELPERS"
+else
+    echo "$KTAP_HELPERS file not found [SKIP]"
+    exit 4
+fi
+
+rust_sample_modules=("rust_minimal" "rust_print")
+
+ktap_print_header
+
+for sample in "${rust_sample_modules[@]}"; do
+    if ! /sbin/modprobe -n -q "$sample"; then
+        ktap_skip_all "module $sample is not found in /lib/modules/$(uname -r)"
+        exit "$KSFT_SKIP"
+    fi
+done
+
+ktap_set_plan "${#rust_sample_modules[@]}"
+
+for sample in "${rust_sample_modules[@]}"; do
+    if /sbin/modprobe -q "$sample"; then
+        /sbin/modprobe -q -r "$sample"
+        ktap_test_pass "$sample"
+    else
+        ktap_test_fail "$sample"
+    fi
+done
+
+ktap_finished