rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kselftest: Add basic test for probing the rust sample modules
@ 2023-12-15 13:21 Laura Nao
  2023-12-17 23:22 ` Sergio González Collado
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Laura Nao @ 2023-12-15 13:21 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Shuah Khan
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, rust-for-linux, linux-kernel,
	linux-kselftest, kernel, 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 <laura.nao@collabora.com>
---
 MAINTAINERS                                   |  1 +
 tools/testing/selftests/Makefile              |  1 +
 tools/testing/selftests/rust/.gitignore       |  1 +
 tools/testing/selftests/rust/Makefile         |  8 ++++
 .../selftests/rust/test_probe_samples.sh      | 42 +++++++++++++++++++
 5 files changed, 53 insertions(+)
 create mode 100644 tools/testing/selftests/rust/.gitignore
 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 e2c6187a3ac8..acf283a5d2c0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -18847,6 +18847,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 3b2061d1c1a5..26140426c849 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -74,6 +74,7 @@ TARGETS += riscv
 TARGETS += rlimits
 TARGETS += rseq
 TARGETS += rtc
+TARGETS += rust
 TARGETS += seccomp
 TARGETS += sgx
 TARGETS += sigaltstack
diff --git a/tools/testing/selftests/rust/.gitignore b/tools/testing/selftests/rust/.gitignore
new file mode 100644
index 000000000000..e3c5c04d1b19
--- /dev/null
+++ b/tools/testing/selftests/rust/.gitignore
@@ -0,0 +1 @@
+ktap_helpers.sh
diff --git a/tools/testing/selftests/rust/Makefile b/tools/testing/selftests/rust/Makefile
new file mode 100644
index 000000000000..ccaa50f35b5b
--- /dev/null
+++ b/tools/testing/selftests/rust/Makefile
@@ -0,0 +1,8 @@
+
+TEST_PROGS += test_probe_samples.sh
+TEST_GEN_FILES := ktap_helpers.sh
+
+include ../lib.mk
+
+$(OUTPUT)/ktap_helpers.sh:
+	cp $(top_srcdir)/tools/testing/selftests/dt/ktap_helpers.sh $@
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..a46550543f73
--- /dev/null
+++ b/tools/testing/selftests/rust/test_probe_samples.sh
@@ -0,0 +1,42 @@
+#!/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}"/ktap_helpers.sh
+
+rust_sample_modules=("rust_minimal" "rust_print")
+
+KSFT_PASS=0
+KSFT_FAIL=1
+KSFT_SKIP=4
+
+ret="${KSFT_PASS}"
+
+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
+        ret="${KSFT_FAIL}"
+        ktap_test_fail "$sample"
+    fi
+done
+
+ktap_print_totals
+exit "${ret}"
-- 
2.30.2


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

* Re: [PATCH] kselftest: Add basic test for probing the rust sample modules
  2023-12-15 13:21 [PATCH] kselftest: Add basic test for probing the rust sample modules Laura Nao
@ 2023-12-17 23:22 ` Sergio González Collado
  2023-12-21 19:46 ` Miguel Ojeda
  2023-12-30  8:19 ` Muhammad Usama Anjum
  2 siblings, 0 replies; 6+ messages in thread
From: Sergio González Collado @ 2023-12-17 23:22 UTC (permalink / raw)
  To: Laura Nao
  Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Shuah Khan,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, rust-for-linux, linux-kernel,
	linux-kselftest, kernel

On Fri, 15 Dec 2023 at 14:25, Laura Nao <laura.nao@collabora.com> 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>
> ---
>  MAINTAINERS                                   |  1 +
>  tools/testing/selftests/Makefile              |  1 +
>  tools/testing/selftests/rust/.gitignore       |  1 +
>  tools/testing/selftests/rust/Makefile         |  8 ++++
>  .../selftests/rust/test_probe_samples.sh      | 42 +++++++++++++++++++
>  5 files changed, 53 insertions(+)
>  create mode 100644 tools/testing/selftests/rust/.gitignore
>  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 e2c6187a3ac8..acf283a5d2c0 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -18847,6 +18847,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 3b2061d1c1a5..26140426c849 100644
> --- a/tools/testing/selftests/Makefile
> +++ b/tools/testing/selftests/Makefile
> @@ -74,6 +74,7 @@ TARGETS += riscv
>  TARGETS += rlimits
>  TARGETS += rseq
>  TARGETS += rtc
> +TARGETS += rust
>  TARGETS += seccomp
>  TARGETS += sgx
>  TARGETS += sigaltstack
> diff --git a/tools/testing/selftests/rust/.gitignore b/tools/testing/selftests/rust/.gitignore
> new file mode 100644
> index 000000000000..e3c5c04d1b19
> --- /dev/null
> +++ b/tools/testing/selftests/rust/.gitignore
> @@ -0,0 +1 @@
> +ktap_helpers.sh
> diff --git a/tools/testing/selftests/rust/Makefile b/tools/testing/selftests/rust/Makefile
> new file mode 100644
> index 000000000000..ccaa50f35b5b
> --- /dev/null
> +++ b/tools/testing/selftests/rust/Makefile
> @@ -0,0 +1,8 @@
> +
> +TEST_PROGS += test_probe_samples.sh
> +TEST_GEN_FILES := ktap_helpers.sh
> +
> +include ../lib.mk
> +
> +$(OUTPUT)/ktap_helpers.sh:
> +       cp $(top_srcdir)/tools/testing/selftests/dt/ktap_helpers.sh $@
> 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..a46550543f73
> --- /dev/null
> +++ b/tools/testing/selftests/rust/test_probe_samples.sh
> @@ -0,0 +1,42 @@
> +#!/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}"/ktap_helpers.sh
> +
> +rust_sample_modules=("rust_minimal" "rust_print")
> +
> +KSFT_PASS=0
> +KSFT_FAIL=1
> +KSFT_SKIP=4
> +
> +ret="${KSFT_PASS}"
> +
> +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
> +        ret="${KSFT_FAIL}"
> +        ktap_test_fail "$sample"
> +    fi
> +done
> +
> +ktap_print_totals
> +exit "${ret}"
> --
> 2.30.2
>
>

Reviewed-by: Sergio Gonzalez Collado <sergio.collado@gmail.com>

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

* Re: [PATCH] kselftest: Add basic test for probing the rust sample modules
  2023-12-15 13:21 [PATCH] kselftest: Add basic test for probing the rust sample modules Laura Nao
  2023-12-17 23:22 ` Sergio González Collado
@ 2023-12-21 19:46 ` Miguel Ojeda
  2024-01-02 14:25   ` Laura Nao
  2023-12-30  8:19 ` Muhammad Usama Anjum
  2 siblings, 1 reply; 6+ messages in thread
From: Miguel Ojeda @ 2023-12-21 19:46 UTC (permalink / raw)
  To: Laura Nao
  Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Shuah Khan,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, rust-for-linux, linux-kernel,
	linux-kselftest, kernel, David Gow

On Fri, Dec 15, 2023 at 2:21 PM Laura Nao <laura.nao@collabora.com> 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>

Thanks Laura!

Shuah: do you want that we pick this one? If so, your `Acked-by` would
be nice -- thanks! Otherwise, please feel free to pick it up.

Cc'ing David too since it involves KTAP in case he has comments.

> diff --git a/tools/testing/selftests/rust/Makefile b/tools/testing/selftests/rust/Makefile

Missing SPDX line? (it can be added when picking it up, though).

> +$(OUTPUT)/ktap_helpers.sh:
> +       cp $(top_srcdir)/tools/testing/selftests/dt/ktap_helpers.sh $@

This may be something for another series, but should these helpers be
factored out perhaps / provided by the framework? Does it work
sourcing them from `dt` directly instead of copying meanwhile (to
simplify)?

> +KSFT_PASS=0
> +KSFT_FAIL=1
> +KSFT_SKIP=4

Similarly, would it make sense for this kind of "common constants" be
factored somehow? Or does that not make sense (I see other tests also
define them "manually")?

Cheers,
Miguel

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

* Re: [PATCH] kselftest: Add basic test for probing the rust sample modules
  2023-12-15 13:21 [PATCH] kselftest: Add basic test for probing the rust sample modules Laura Nao
  2023-12-17 23:22 ` Sergio González Collado
  2023-12-21 19:46 ` Miguel Ojeda
@ 2023-12-30  8:19 ` Muhammad Usama Anjum
  2 siblings, 0 replies; 6+ messages in thread
From: Muhammad Usama Anjum @ 2023-12-30  8:19 UTC (permalink / raw)
  To: Laura Nao, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Shuah Khan
  Cc: Muhammad Usama Anjum, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, rust-for-linux,
	linux-kernel, linux-kselftest, kernel

On 12/15/23 6:21 PM, 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: Muhammad Usama Anjum <usama.anjum@collabora.com>
Tested-by: Muhammad Usama Anjum <usama.anjum@collabora.com>

> ---
>  MAINTAINERS                                   |  1 +
>  tools/testing/selftests/Makefile              |  1 +
>  tools/testing/selftests/rust/.gitignore       |  1 +
>  tools/testing/selftests/rust/Makefile         |  8 ++++
>  .../selftests/rust/test_probe_samples.sh      | 42 +++++++++++++++++++
>  5 files changed, 53 insertions(+)
>  create mode 100644 tools/testing/selftests/rust/.gitignore
>  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 e2c6187a3ac8..acf283a5d2c0 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -18847,6 +18847,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 3b2061d1c1a5..26140426c849 100644
> --- a/tools/testing/selftests/Makefile
> +++ b/tools/testing/selftests/Makefile
> @@ -74,6 +74,7 @@ TARGETS += riscv
>  TARGETS += rlimits
>  TARGETS += rseq
>  TARGETS += rtc
> +TARGETS += rust
>  TARGETS += seccomp
>  TARGETS += sgx
>  TARGETS += sigaltstack
> diff --git a/tools/testing/selftests/rust/.gitignore b/tools/testing/selftests/rust/.gitignore
> new file mode 100644
> index 000000000000..e3c5c04d1b19
> --- /dev/null
> +++ b/tools/testing/selftests/rust/.gitignore
> @@ -0,0 +1 @@
> +ktap_helpers.sh
> diff --git a/tools/testing/selftests/rust/Makefile b/tools/testing/selftests/rust/Makefile
> new file mode 100644
> index 000000000000..ccaa50f35b5b
> --- /dev/null
> +++ b/tools/testing/selftests/rust/Makefile
> @@ -0,0 +1,8 @@
> +
> +TEST_PROGS += test_probe_samples.sh
> +TEST_GEN_FILES := ktap_helpers.sh
> +
> +include ../lib.mk
> +
> +$(OUTPUT)/ktap_helpers.sh:
> +	cp $(top_srcdir)/tools/testing/selftests/dt/ktap_helpers.sh $@
> 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..a46550543f73
> --- /dev/null
> +++ b/tools/testing/selftests/rust/test_probe_samples.sh
> @@ -0,0 +1,42 @@
> +#!/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}"/ktap_helpers.sh
> +
> +rust_sample_modules=("rust_minimal" "rust_print")
> +
> +KSFT_PASS=0
> +KSFT_FAIL=1
> +KSFT_SKIP=4
> +
> +ret="${KSFT_PASS}"
> +
> +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
> +        ret="${KSFT_FAIL}"
> +        ktap_test_fail "$sample"
> +    fi
> +done
> +
> +ktap_print_totals
> +exit "${ret}"

-- 
BR,
Muhammad Usama Anjum

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

* Re: [PATCH] kselftest: Add basic test for probing the rust sample modules
  2023-12-21 19:46 ` Miguel Ojeda
@ 2024-01-02 14:25   ` Laura Nao
  2024-02-22 15:20     ` Laura Nao
  0 siblings, 1 reply; 6+ messages in thread
From: Laura Nao @ 2024-01-02 14:25 UTC (permalink / raw)
  To: miguel.ojeda.sandonis
  Cc: a.hindborg, alex.gaynor, aliceryhl, benno.lossin, bjorn3_gh,
	boqun.feng, davidgow, gary, kernel, laura.nao, linux-kernel,
	linux-kselftest, ojeda, rust-for-linux, shuah, wedsonaf

On 12/21/23 20:46, Miguel Ojeda wrote:
> On Fri, Dec 15, 2023 at 2:21 PM Laura Nao <laura.nao@collabora.com>
> 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>
> 
> Thanks Laura!
> 
> Shuah: do you want that we pick this one? If so, your `Acked-by` would
> be nice -- thanks! Otherwise, please feel free to pick it up.
> 
> Cc'ing David too since it involves KTAP in case he has comments.
> 
>> diff --git a/tools/testing/selftests/rust/Makefile
>> b/tools/testing/selftests/rust/Makefile
> 
> Missing SPDX line? (it can be added when picking it up, though).
> 

Thanks for the feedback Miguel!

>> +$(OUTPUT)/ktap_helpers.sh:
>> +       cp $(top_srcdir)/tools/testing/selftests/dt/ktap_helpers.sh
>> $@
> 
> This may be something for another series, but should these helpers be
> factored out perhaps / provided by the framework? Does it work
> sourcing them from `dt` directly instead of copying meanwhile (to
> simplify)?
> 
>> +KSFT_PASS=0
>> +KSFT_FAIL=1
>> +KSFT_SKIP=4
> 
> Similarly, would it make sense for this kind of "common constants" be
> factored somehow? Or does that not make sense (I see other tests also
> define them "manually")?
> 

Sourcing the file from the `dt` folder does work when running the test
with `make -C tools/testing/selftests TARGETS=rust run_tests`, but fails
when the test is installed with `make -C tools/testing/selftests
TARGETS=rust install` and run with
`./tools/testing/selftests/kselftest_install/run_kselftest.sh` (unless
the dt kselftest is installed too).

I agree factoring out the helpers might be a better solution. I sent a
patch to move the ktap_helpers.sh file to the kselftest common
directory, so that kselftests written in bash can make use of the helper
functions more easily:

https://lore.kernel.org/linux-kselftest/20240102141528.169947-1-laura.nao@collabora.com/T/#u

If that patch is merged first, I'll rework this one and send a v2 with
the proper adjustments.

Best,

Laura 

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

* Re: [PATCH] kselftest: Add basic test for probing the rust sample modules
  2024-01-02 14:25   ` Laura Nao
@ 2024-02-22 15:20     ` Laura Nao
  0 siblings, 0 replies; 6+ messages in thread
From: Laura Nao @ 2024-02-22 15:20 UTC (permalink / raw)
  To: laura.nao
  Cc: a.hindborg, alex.gaynor, aliceryhl, benno.lossin, bjorn3_gh,
	boqun.feng, davidgow, gary, kernel, linux-kernel,
	linux-kselftest, miguel.ojeda.sandonis, ojeda, rust-for-linux,
	shuah, wedsonaf

On 1/2/24 15:25, Laura Nao wrote:
> I agree factoring out the helpers might be a better solution. I sent a
> patch to move the ktap_helpers.sh file to the kselftest common
> directory, so that kselftests written in bash can make use of the helper
> functions more easily:
> 
> https://lore.kernel.org/linux-kselftest/20240102141528.169947-1-laura.nao@collabora.com/T/#u
> 
> If that patch is merged first, I'll rework this one and send a v2 with
> the proper adjustments.
> 

v2 sent: https://lore.kernel.org/linux-kselftest/20240222151009.461264-1-laura.nao@collabora.com/T/#u

Best,

Laura

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-15 13:21 [PATCH] kselftest: Add basic test for probing the rust sample modules Laura Nao
2023-12-17 23:22 ` Sergio González Collado
2023-12-21 19:46 ` Miguel Ojeda
2024-01-02 14:25   ` Laura Nao
2024-02-22 15:20     ` Laura Nao
2023-12-30  8:19 ` Muhammad Usama Anjum

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).