rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] kselftest: Add basic test for probing the rust sample modules
@ 2024-02-22 16:29 Laura Nao
  2024-02-23 21:48 ` Shuah Khan
  0 siblings, 1 reply; 4+ messages in thread
From: Laura Nao @ 2024-02-22 16:29 UTC (permalink / raw)
  To: ojeda, alex.gaynor, wedsonaf, shuah
  Cc: usama.anjum, a.hindborg, aliceryhl, benno.lossin, bjorn3_gh,
	boqun.feng, gary, kernel, laura.nao, linux-kernel,
	linux-kselftest, rust-for-linux, kernel, Sergio Gonzalez Collado

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>
---
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 +++
 .../selftests/rust/test_probe_samples.sh      | 34 +++++++++++++++++++
 4 files changed, 40 insertions(+)
 create mode 100644 tools/testing/selftests/rust/Makefile
 create mode 100755 tools/testing/selftests/rust/test_probe_samples.sh

diff --git a/MAINTAINERS b/MAINTAINERS
index c1a18af3593a..5f62904c80bd 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -19207,6 +19207,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)
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index f7255969b695..e1504833654d 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -80,6 +80,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
index 000000000000..fce1584d3bc0
--- /dev/null
+++ b/tools/testing/selftests/rust/Makefile
@@ -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/test_probe_samples.sh b/tools/testing/selftests/rust/test_probe_samples.sh
new file mode 100755
index 000000000000..389d180f14a5
--- /dev/null
+++ b/tools/testing/selftests/rust/test_probe_samples.sh
@@ -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
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] kselftest: Add basic test for probing the rust sample modules
  2024-02-22 16:29 [PATCH v3] kselftest: Add basic test for probing the rust sample modules Laura Nao
@ 2024-02-23 21:48 ` Shuah Khan
  2024-02-23 22:02   ` Shuah Khan
  0 siblings, 1 reply; 4+ messages in thread
From: Shuah Khan @ 2024-02-23 21:48 UTC (permalink / raw)
  To: Laura Nao, ojeda, alex.gaynor, wedsonaf, shuah
  Cc: usama.anjum, a.hindborg, aliceryhl, benno.lossin, bjorn3_gh,
	boqun.feng, gary, kernel, linux-kernel, linux-kselftest,
	rust-for-linux, kernel, Sergio Gonzalez Collado, Shuah Khan

On 2/22/24 09:29, Laura Nao wrote:
> 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>
> ---
> 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 +++
>   .../selftests/rust/test_probe_samples.sh      | 34 +++++++++++++++++++
>   4 files changed, 40 insertions(+)
>   create mode 100644 tools/testing/selftests/rust/Makefile
>   create mode 100755 tools/testing/selftests/rust/test_probe_samples.sh
> 

Looks good to me. Don't you need a config file for this test?
Refer to config files for existing tests as a reference.

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] kselftest: Add basic test for probing the rust sample modules
  2024-02-23 21:48 ` Shuah Khan
@ 2024-02-23 22:02   ` Shuah Khan
  2024-02-26 10:21     ` Laura Nao
  0 siblings, 1 reply; 4+ messages in thread
From: Shuah Khan @ 2024-02-23 22:02 UTC (permalink / raw)
  To: Laura Nao, ojeda, alex.gaynor, wedsonaf, shuah
  Cc: usama.anjum, a.hindborg, aliceryhl, benno.lossin, bjorn3_gh,
	boqun.feng, gary, kernel, linux-kernel, linux-kselftest,
	rust-for-linux, kernel, Sergio Gonzalez Collado, Shuah Khan

On 2/23/24 14:48, Shuah Khan wrote:
> On 2/22/24 09:29, Laura Nao wrote:
>> 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>
>> ---
>> 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 +++
>>   .../selftests/rust/test_probe_samples.sh      | 34 +++++++++++++++++++
>>   4 files changed, 40 insertions(+)
>>   create mode 100644 tools/testing/selftests/rust/Makefile
>>   create mode 100755 tools/testing/selftests/rust/test_probe_samples.sh
>>
> 
> Looks good to me. Don't you need a config file for this test?
> Refer to config files for existing tests as a reference.
> 
make kselftest TARGETS=rust
or
make run_tests

On Linux 6.8-rc5 give the following? Doesn't look right.
  
TAP version 13
1..1
# timeout set to 45
# selftests: rust: test_probe_samples.sh
# ./test_probe_samples.sh: line 12: /linux/linux_6.8/tools/testing/selftests/rust/../kselftest/ktap_helpers.sh: No such file or directory
# ./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

thanks,
-- Shuah


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] kselftest: Add basic test for probing the rust sample modules
  2024-02-23 22:02   ` Shuah Khan
@ 2024-02-26 10:21     ` Laura Nao
  0 siblings, 0 replies; 4+ messages in thread
From: Laura Nao @ 2024-02-26 10:21 UTC (permalink / raw)
  To: skhan
  Cc: a.hindborg, alex.gaynor, aliceryhl, benno.lossin, bjorn3_gh,
	boqun.feng, gary, kernel, kernel, laura.nao, linux-kernel,
	linux-kselftest, ojeda, rust-for-linux, sergio.collado, shuah,
	usama.anjum, wedsonaf

Hi Shuah,

On 2/23/24 23:02, Shuah Khan wrote:
> On 2/23/24 14:48, Shuah Khan wrote:
>> On 2/22/24 09:29, Laura Nao wrote:
>>> 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>
>>> ---
>>> 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 +++
>>>   .../selftests/rust/test_probe_samples.sh      | 34 +++++++++++++++++++
>>>   4 files changed, 40 insertions(+)
>>>   create mode 100644 tools/testing/selftests/rust/Makefile
>>>   create mode 100755 tools/testing/selftests/rust/test_probe_samples.sh
>>>
>>
>> Looks good to me. Don't you need a config file for this test?
>> Refer to config files for existing tests as a reference.
>>

Right, in order for the tests to not be skipped support for rust and its
sample modules need to be enabled.

I added the config file in v4: https://lore.kernel.org/linux-kselftest/20240226101646.291337-1-laura.nao@collabora.com/T/#u

> make kselftest TARGETS=rust
> or
> make run_tests
> 
> On Linux 6.8-rc5 give the following? Doesn't look right.
> 
> TAP version 13
> 1..1
> # timeout set to 45
> # selftests: rust: test_probe_samples.sh
> # ./test_probe_samples.sh: line 12: 
> /linux/linux_6.8/tools/testing/selftests/rust/../kselftest/ktap_helpers.sh: No such file or directory
> # ./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
> 

This patch requires
https://lore.kernel.org/all/20240102141528.169947-1-laura.nao@collabora.com/T/#u
and
https://lore.kernel.org/all/20240131-ktap-sh-helpers-extend-v1-0-98ffb468712c@collabora.com/
, which are both scheduled for 6.9-rc1. Sorry I didn't mention it above!

Thanks,

Laura


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-02-26 10:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-22 16:29 [PATCH v3] kselftest: Add basic test for probing the rust sample modules Laura Nao
2024-02-23 21:48 ` Shuah Khan
2024-02-23 22:02   ` Shuah Khan
2024-02-26 10:21     ` Laura Nao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).