diff mbox series

[bpf-next,v2,3/3] selftests/bpf: add wrong type test to cgroup dev

Message ID 20240729-convert_dev_cgroup-v2-3-4c1fc0520545@bootlin.com (mailing list archive)
State New
Headers show
Series selftests/bpf: convert test_dev_cgroup to test_progs | expand

Commit Message

Alexis Lothoré (eBPF Foundation) July 29, 2024, 8:20 a.m. UTC
Current cgroup_dev test mostly tests that device operation is accepted or
refused base on passed major/minor (and so, any operation performed during
test involves only char device)

Add a small subtest ensuring that the device type passed to bpf program
allows it to take decisions as well.

Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
---
Changes in v2:
- change test name ("null" block device does not make sense)
- use updated subtest API for this new subtest
---
 tools/testing/selftests/bpf/prog_tests/cgroup_dev.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Alan Maguire July 29, 2024, 5:40 p.m. UTC | #1
On 29/07/2024 09:20, Alexis Lothoré (eBPF Foundation) wrote:
> Current cgroup_dev test mostly tests that device operation is accepted or
> refused base on passed major/minor (and so, any operation performed during
> test involves only char device)
> 
> Add a small subtest ensuring that the device type passed to bpf program
> allows it to take decisions as well.
> 
> Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>

Reviewed-by: Alan Maguire <alan.maguire@oracle.com>

> ---
> Changes in v2:
> - change test name ("null" block device does not make sense)
> - use updated subtest API for this new subtest
> ---
>  tools/testing/selftests/bpf/prog_tests/cgroup_dev.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_dev.c b/tools/testing/selftests/bpf/prog_tests/cgroup_dev.c
> index af0b70086c21..a840973c87b1 100644
> --- a/tools/testing/selftests/bpf/prog_tests/cgroup_dev.c
> +++ b/tools/testing/selftests/bpf/prog_tests/cgroup_dev.c
> @@ -91,6 +91,9 @@ void test_cgroup_dev(void)
>  	if (test__start_subtest("allow-mknod"))
>  		test_mknod("/dev/test_dev_cgroup_null", S_IFCHR, 1, 3, 0);
>  
> +	if (test__start_subtest("deny-mknod-wrong-type"))
> +		test_mknod("/dev/test_dev_cgroup_block", S_IFBLK, 1, 3, -EPERM);
> +
>  	if (test__start_subtest("allow-read"))
>  		test_read("/dev/urandom", buf, TEST_BUFFER_SIZE, TEST_BUFFER_SIZE);
>  
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_dev.c b/tools/testing/selftests/bpf/prog_tests/cgroup_dev.c
index af0b70086c21..a840973c87b1 100644
--- a/tools/testing/selftests/bpf/prog_tests/cgroup_dev.c
+++ b/tools/testing/selftests/bpf/prog_tests/cgroup_dev.c
@@ -91,6 +91,9 @@  void test_cgroup_dev(void)
 	if (test__start_subtest("allow-mknod"))
 		test_mknod("/dev/test_dev_cgroup_null", S_IFCHR, 1, 3, 0);
 
+	if (test__start_subtest("deny-mknod-wrong-type"))
+		test_mknod("/dev/test_dev_cgroup_block", S_IFBLK, 1, 3, -EPERM);
+
 	if (test__start_subtest("allow-read"))
 		test_read("/dev/urandom", buf, TEST_BUFFER_SIZE, TEST_BUFFER_SIZE);