Skip to contentSkip to conversation

selftests/rseq: add rseq syscall errors test

PATCH Applied Michael Jeanson 2 participants 2 messages Jan 21, 2025 – Feb 22, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/rseq: add rseq syscall errors test

This test adds coverage of expected errors during rseq registration and unregistration, it disables glibc integration and will thus always exercise the rseq syscall explictly.

---
 tools/testing/selftests/rseq/.gitignore       |   1 +
 tools/testing/selftests/rseq/Makefile         |   9 +-
 tools/testing/selftests/rseq/rseq.c           |   6 +-
 tools/testing/selftests/rseq/rseq.h           |   5 +
 .../selftests/rseq/run_syscall_errors_test.sh |   5 +
 .../selftests/rseq/syscall_errors_test.c      | 124 ++++++++++++++++++
 6 files changed, 145 insertions(+), 5 deletions(-)
 create mode 100755 tools/testing/selftests/rseq/run_syscall_errors_test.sh
 create mode 100644 tools/testing/selftests/rseq/syscall_errors_test.c
tools/testing/selftests/rseq/.gitignore +1 -0
index 16496de5f6ce..0fda241fa62b 100644
@@ -9,3 +9,4 @@ param_test_compare_twice
 param_test_mm_cid
 param_test_mm_cid_benchmark
 param_test_mm_cid_compare_twice
+syscall_errors_test
tools/testing/selftests/rseq/Makefile +7 -2
index 5a3432fceb58..0d0a5fae5954 100644
@@ -16,11 +16,12 @@ OVERRIDE_TARGETS = 1
 
 TEST_GEN_PROGS = basic_test basic_percpu_ops_test basic_percpu_ops_mm_cid_test param_test \
 		param_test_benchmark param_test_compare_twice param_test_mm_cid \
-		param_test_mm_cid_benchmark param_test_mm_cid_compare_twice
+		param_test_mm_cid_benchmark param_test_mm_cid_compare_twice \
+		syscall_errors_test
 
 TEST_GEN_PROGS_EXTENDED = librseq.so
 
-TEST_PROGS = run_param_test.sh
+TEST_PROGS = run_param_test.sh run_syscall_errors_test.sh
 
 TEST_FILES := settings
 
@@ -54,3 +55,7 @@ $(OUTPUT)/param_test_mm_cid_benchmark: param_test.c $(TEST_GEN_PROGS_EXTENDED) \
 $(OUTPUT)/param_test_mm_cid_compare_twice: param_test.c $(TEST_GEN_PROGS_EXTENDED) \
 					rseq.h rseq-*.h
 	$(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_CID -DRSEQ_COMPARE_TWICE $< $(LDLIBS) -lrseq -o $@
+
+$(OUTPUT)/syscall_errors_test: syscall_errors_test.c $(TEST_GEN_PROGS_EXTENDED) \
+					rseq.h rseq-*.h
+	$(CC) $(CFLAGS) $< $(LDLIBS) -lrseq -o $@
tools/testing/selftests/rseq/rseq.c +3 -3
index 5b9772cdf265..4c06b8f61fe5 100644
@@ -88,7 +88,7 @@ static int sys_getcpu(unsigned *cpu, unsigned *node)
 	return syscall(__NR_getcpu, cpu, node, NULL);
 }
 
-int rseq_available(void)
+bool rseq_available(void)
 {
 	int rc;
 
@@ -97,9 +97,9 @@ int rseq_available(void)
 		abort();
 	switch (errno) {
 	case ENOSYS:
-		return 0;
+		return false;
 	case EINVAL:
-		return 1;
+		return true;
 	default:
 		abort();
 	}
tools/testing/selftests/rseq/rseq.h +5 -0
index 4e217b620e0c..7c3c018d2ba0 100644
@@ -150,6 +150,11 @@ int32_t rseq_fallback_current_cpu(void);
  */
 int32_t rseq_fallback_current_node(void);
 
+/*
+ * Returns true if rseq is supported.
+ */
+bool rseq_available(void);
+
 /*
  * Values returned can be either the current CPU number, -1 (rseq is
  * uninitialized), or -2 (rseq initialization has failed).
tools/testing/selftests/rseq/run_syscall_errors_test.sh new file +5 -0
new file mode 100755
index 000000000000..9272246b39f2
@@ -0,0 +1,5 @@
+#!/bin/bash
+# SPDX-License-Identifier: MIT
+# SPDX-FileCopyrightText: 2024 Michael Jeanson <[email protected]>
+
+GLIBC_TUNABLES="${GLIBC_TUNABLES:-}:glibc.pthread.rseq=0" ./syscall_errors_test
tools/testing/selftests/rseq/syscall_errors_test.c new file +124 -0

124 lines not on this page · raw message

Signature · 1 line
2.43.0
#1 lore raw

[tip: sched/core] selftests/rseq: Add rseq syscall errors test

The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     3c27b40830cad0917c92fecf0c9cb1ec41de17cc
Gitweb:        https://git.kernel.org/tip/3c27b40830cad0917c92fecf0c9cb1ec41de17cc
Author:        Michael Jeanson <[email protected]>
AuthorDate:    Tue, 21 Jan 2025 16:33:52 -05:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Sat, 22 Feb 2025 14:13:45 +01:00

selftests/rseq: Add rseq syscall errors test

This test adds coverage of expected errors during rseq registration and unregistration, it disables glibc integration and will thus always exercise the rseq syscall explictly.

---
 tools/testing/selftests/rseq/.gitignore                 |   1 +-
 tools/testing/selftests/rseq/Makefile                   |   9 +-
 tools/testing/selftests/rseq/rseq.c                     |   6 +-
 tools/testing/selftests/rseq/rseq.h                     |   5 +-
 tools/testing/selftests/rseq/run_syscall_errors_test.sh |   5 +-
 tools/testing/selftests/rseq/syscall_errors_test.c      | 124 +++++++-
 6 files changed, 145 insertions(+), 5 deletions(-)
 create mode 100755 tools/testing/selftests/rseq/run_syscall_errors_test.sh
 create mode 100644 tools/testing/selftests/rseq/syscall_errors_test.c
tools/testing/selftests/rseq/.gitignore +1 -0
index 16496de..0fda241 100644
@@ -9,3 +9,4 @@ param_test_compare_twice
 param_test_mm_cid
 param_test_mm_cid_benchmark
 param_test_mm_cid_compare_twice
+syscall_errors_test
tools/testing/selftests/rseq/Makefile +7 -2
index 5a3432f..0d0a5fa 100644
@@ -16,11 +16,12 @@ OVERRIDE_TARGETS = 1
 
 TEST_GEN_PROGS = basic_test basic_percpu_ops_test basic_percpu_ops_mm_cid_test param_test \
 		param_test_benchmark param_test_compare_twice param_test_mm_cid \
-		param_test_mm_cid_benchmark param_test_mm_cid_compare_twice
+		param_test_mm_cid_benchmark param_test_mm_cid_compare_twice \
+		syscall_errors_test
 
 TEST_GEN_PROGS_EXTENDED = librseq.so
 
-TEST_PROGS = run_param_test.sh
+TEST_PROGS = run_param_test.sh run_syscall_errors_test.sh
 
 TEST_FILES := settings
 
@@ -54,3 +55,7 @@ $(OUTPUT)/param_test_mm_cid_benchmark: param_test.c $(TEST_GEN_PROGS_EXTENDED) \
 $(OUTPUT)/param_test_mm_cid_compare_twice: param_test.c $(TEST_GEN_PROGS_EXTENDED) \
 					rseq.h rseq-*.h
 	$(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_CID -DRSEQ_COMPARE_TWICE $< $(LDLIBS) -lrseq -o $@
+
+$(OUTPUT)/syscall_errors_test: syscall_errors_test.c $(TEST_GEN_PROGS_EXTENDED) \
+					rseq.h rseq-*.h
+	$(CC) $(CFLAGS) $< $(LDLIBS) -lrseq -o $@
tools/testing/selftests/rseq/rseq.c +3 -3
index f615679..1e29db9 100644
@@ -87,7 +87,7 @@ static int sys_getcpu(unsigned *cpu, unsigned *node)
 	return syscall(__NR_getcpu, cpu, node, NULL);
 }
 
-int rseq_available(void)
+bool rseq_available(void)
 {
 	int rc;
 
@@ -96,9 +96,9 @@ int rseq_available(void)
 		abort();
 	switch (errno) {
 	case ENOSYS:
-		return 0;
+		return false;
 	case EINVAL:
-		return 1;
+		return true;
 	default:
 		abort();
 	}
tools/testing/selftests/rseq/rseq.h +5 -0
index ba424ce..f51a5fd 100644
@@ -160,6 +160,11 @@ int32_t rseq_fallback_current_cpu(void);
 int32_t rseq_fallback_current_node(void);
 
 /*
+ * Returns true if rseq is supported.
+ */
+bool rseq_available(void);
+
+/*
  * Values returned can be either the current CPU number, -1 (rseq is
  * uninitialized), or -2 (rseq initialization has failed).
  */
tools/testing/selftests/rseq/run_syscall_errors_test.sh new file +5 -0
new file mode 100755
index 0000000..9272246
@@ -0,0 +1,5 @@
+#!/bin/bash
+# SPDX-License-Identifier: MIT
+# SPDX-FileCopyrightText: 2024 Michael Jeanson <[email protected]>
+
+GLIBC_TUNABLES="${GLIBC_TUNABLES:-}:glibc.pthread.rseq=0" ./syscall_errors_test
tools/testing/selftests/rseq/syscall_errors_test.c new file +124 -0

124 lines not on this page · raw message