diff options
author | Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | 2018-06-02 08:44:05 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2018-06-06 05:58:35 -0400 |
commit | 1badac4f80c3d325d6d1b9fc3b6344120aa799be (patch) | |
tree | fcc20a8a7d77c304863ce07b13986a088d0af941 | |
parent | 2e155fb7d605d37c423ad0076f82feca572efdce (diff) |
rseq/selftests: Provide basic test
"basic_test" only asserts that RSEQ works moderately correctly. E.g.
that the CPUID pointer works.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Joel Fernandes <joelaf@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Watson <davejwatson@fb.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: linux-kselftest@vger.kernel.org
Cc: "H . Peter Anvin" <hpa@zytor.com>
Cc: Chris Lameter <cl@linux.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Andrew Hunter <ahh@google.com>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>
Cc: "Paul E . McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Paul Turner <pjt@google.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ben Maurer <bmaurer@fb.com>
Cc: linux-api@vger.kernel.org
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lkml.kernel.org/r/20180602124408.8430-14-mathieu.desnoyers@efficios.com
-rw-r--r-- | tools/testing/selftests/rseq/basic_test.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/testing/selftests/rseq/basic_test.c b/tools/testing/selftests/rseq/basic_test.c new file mode 100644 index 000000000000..d8efbfb89193 --- /dev/null +++ b/tools/testing/selftests/rseq/basic_test.c | |||
@@ -0,0 +1,56 @@ | |||
1 | // SPDX-License-Identifier: LGPL-2.1 | ||
2 | /* | ||
3 | * Basic test coverage for critical regions and rseq_current_cpu(). | ||
4 | */ | ||
5 | |||
6 | #define _GNU_SOURCE | ||
7 | #include <assert.h> | ||
8 | #include <sched.h> | ||
9 | #include <signal.h> | ||
10 | #include <stdio.h> | ||
11 | #include <string.h> | ||
12 | #include <sys/time.h> | ||
13 | |||
14 | #include "rseq.h" | ||
15 | |||
16 | void test_cpu_pointer(void) | ||
17 | { | ||
18 | cpu_set_t affinity, test_affinity; | ||
19 | int i; | ||
20 | |||
21 | sched_getaffinity(0, sizeof(affinity), &affinity); | ||
22 | CPU_ZERO(&test_affinity); | ||
23 | for (i = 0; i < CPU_SETSIZE; i++) { | ||
24 | if (CPU_ISSET(i, &affinity)) { | ||
25 | CPU_SET(i, &test_affinity); | ||
26 | sched_setaffinity(0, sizeof(test_affinity), | ||
27 | &test_affinity); | ||
28 | assert(sched_getcpu() == i); | ||
29 | assert(rseq_current_cpu() == i); | ||
30 | assert(rseq_current_cpu_raw() == i); | ||
31 | assert(rseq_cpu_start() == i); | ||
32 | CPU_CLR(i, &test_affinity); | ||
33 | } | ||
34 | } | ||
35 | sched_setaffinity(0, sizeof(affinity), &affinity); | ||
36 | } | ||
37 | |||
38 | int main(int argc, char **argv) | ||
39 | { | ||
40 | if (rseq_register_current_thread()) { | ||
41 | fprintf(stderr, "Error: rseq_register_current_thread(...) failed(%d): %s\n", | ||
42 | errno, strerror(errno)); | ||
43 | goto init_thread_error; | ||
44 | } | ||
45 | printf("testing current cpu\n"); | ||
46 | test_cpu_pointer(); | ||
47 | if (rseq_unregister_current_thread()) { | ||
48 | fprintf(stderr, "Error: rseq_unregister_current_thread(...) failed(%d): %s\n", | ||
49 | errno, strerror(errno)); | ||
50 | goto init_thread_error; | ||
51 | } | ||
52 | return 0; | ||
53 | |||
54 | init_thread_error: | ||
55 | return -1; | ||
56 | } | ||