diff options
author | Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | 2019-09-19 13:37:03 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2019-09-25 11:42:31 -0400 |
commit | 19a4ff534bb09686f53800564cb977bad2177c00 (patch) | |
tree | cdd7495b082279c1e6ec7e6bfd8c2ad4612ce9ab /tools/testing/selftests | |
parent | 227a4aadc75ba22fcb6c4e1c078817b8cbaae4ce (diff) |
selftests, sched/membarrier: Add multi-threaded test
membarrier commands cover very different code paths if they are in
a single-threaded vs multi-threaded process. Therefore, exercise both
scenarios in the kernel selftests to increase coverage of this selftest.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Chris Metcalf <cmetcalf@ezchip.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Kirill Tkhai <tkhai@yandex.ru>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Paul E. McKenney <paulmck@linux.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russell King - ARM Linux admin <linux@armlinux.org.uk>
Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190919173705.2181-6-mathieu.desnoyers@efficios.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/testing/selftests')
-rw-r--r-- | tools/testing/selftests/membarrier/.gitignore | 3 | ||||
-rw-r--r-- | tools/testing/selftests/membarrier/Makefile | 5 | ||||
-rw-r--r-- | tools/testing/selftests/membarrier/membarrier_test_impl.h (renamed from tools/testing/selftests/membarrier/membarrier_test.c) | 40 | ||||
-rw-r--r-- | tools/testing/selftests/membarrier/membarrier_test_multi_thread.c | 73 | ||||
-rw-r--r-- | tools/testing/selftests/membarrier/membarrier_test_single_thread.c | 24 |
5 files changed, 124 insertions, 21 deletions
diff --git a/tools/testing/selftests/membarrier/.gitignore b/tools/testing/selftests/membarrier/.gitignore index 020c44f49a9e..f2f7ec0a99b4 100644 --- a/tools/testing/selftests/membarrier/.gitignore +++ b/tools/testing/selftests/membarrier/.gitignore | |||
@@ -1 +1,2 @@ | |||
1 | membarrier_test | 1 | membarrier_test_multi_thread |
2 | membarrier_test_single_thread | ||
diff --git a/tools/testing/selftests/membarrier/Makefile b/tools/testing/selftests/membarrier/Makefile index 97e3bdf3d1e9..34d1c81a2324 100644 --- a/tools/testing/selftests/membarrier/Makefile +++ b/tools/testing/selftests/membarrier/Makefile | |||
@@ -1,7 +1,8 @@ | |||
1 | # SPDX-License-Identifier: GPL-2.0-only | 1 | # SPDX-License-Identifier: GPL-2.0-only |
2 | CFLAGS += -g -I../../../../usr/include/ | 2 | CFLAGS += -g -I../../../../usr/include/ |
3 | LDLIBS += -lpthread | ||
3 | 4 | ||
4 | TEST_GEN_PROGS := membarrier_test | 5 | TEST_GEN_PROGS := membarrier_test_single_thread \ |
6 | membarrier_test_multi_thread | ||
5 | 7 | ||
6 | include ../lib.mk | 8 | include ../lib.mk |
7 | |||
diff --git a/tools/testing/selftests/membarrier/membarrier_test.c b/tools/testing/selftests/membarrier/membarrier_test_impl.h index 70b4ddbf126b..186be69f0a59 100644 --- a/tools/testing/selftests/membarrier/membarrier_test.c +++ b/tools/testing/selftests/membarrier/membarrier_test_impl.h | |||
@@ -1,10 +1,11 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | #define _GNU_SOURCE | 2 | #define _GNU_SOURCE |
3 | #include <linux/membarrier.h> | 3 | #include <linux/membarrier.h> |
4 | #include <syscall.h> | 4 | #include <syscall.h> |
5 | #include <stdio.h> | 5 | #include <stdio.h> |
6 | #include <errno.h> | 6 | #include <errno.h> |
7 | #include <string.h> | 7 | #include <string.h> |
8 | #include <pthread.h> | ||
8 | 9 | ||
9 | #include "../kselftest.h" | 10 | #include "../kselftest.h" |
10 | 11 | ||
@@ -223,7 +224,7 @@ static int test_membarrier_global_expedited_success(void) | |||
223 | return 0; | 224 | return 0; |
224 | } | 225 | } |
225 | 226 | ||
226 | static int test_membarrier(void) | 227 | static int test_membarrier_fail(void) |
227 | { | 228 | { |
228 | int status; | 229 | int status; |
229 | 230 | ||
@@ -233,10 +234,27 @@ static int test_membarrier(void) | |||
233 | status = test_membarrier_flags_fail(); | 234 | status = test_membarrier_flags_fail(); |
234 | if (status) | 235 | if (status) |
235 | return status; | 236 | return status; |
236 | status = test_membarrier_global_success(); | 237 | status = test_membarrier_private_expedited_fail(); |
237 | if (status) | 238 | if (status) |
238 | return status; | 239 | return status; |
239 | status = test_membarrier_private_expedited_fail(); | 240 | status = sys_membarrier(MEMBARRIER_CMD_QUERY, 0); |
241 | if (status < 0) { | ||
242 | ksft_test_result_fail("sys_membarrier() failed\n"); | ||
243 | return status; | ||
244 | } | ||
245 | if (status & MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE) { | ||
246 | status = test_membarrier_private_expedited_sync_core_fail(); | ||
247 | if (status) | ||
248 | return status; | ||
249 | } | ||
250 | return 0; | ||
251 | } | ||
252 | |||
253 | static int test_membarrier_success(void) | ||
254 | { | ||
255 | int status; | ||
256 | |||
257 | status = test_membarrier_global_success(); | ||
240 | if (status) | 258 | if (status) |
241 | return status; | 259 | return status; |
242 | status = test_membarrier_register_private_expedited_success(); | 260 | status = test_membarrier_register_private_expedited_success(); |
@@ -251,9 +269,6 @@ static int test_membarrier(void) | |||
251 | return status; | 269 | return status; |
252 | } | 270 | } |
253 | if (status & MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE) { | 271 | if (status & MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE) { |
254 | status = test_membarrier_private_expedited_sync_core_fail(); | ||
255 | if (status) | ||
256 | return status; | ||
257 | status = test_membarrier_register_private_expedited_sync_core_success(); | 272 | status = test_membarrier_register_private_expedited_sync_core_success(); |
258 | if (status) | 273 | if (status) |
259 | return status; | 274 | return status; |
@@ -300,14 +315,3 @@ static int test_membarrier_query(void) | |||
300 | ksft_test_result_pass("sys_membarrier available\n"); | 315 | ksft_test_result_pass("sys_membarrier available\n"); |
301 | return 0; | 316 | return 0; |
302 | } | 317 | } |
303 | |||
304 | int main(int argc, char **argv) | ||
305 | { | ||
306 | ksft_print_header(); | ||
307 | ksft_set_plan(13); | ||
308 | |||
309 | test_membarrier_query(); | ||
310 | test_membarrier(); | ||
311 | |||
312 | return ksft_exit_pass(); | ||
313 | } | ||
diff --git a/tools/testing/selftests/membarrier/membarrier_test_multi_thread.c b/tools/testing/selftests/membarrier/membarrier_test_multi_thread.c new file mode 100644 index 000000000000..ac5613e5b0eb --- /dev/null +++ b/tools/testing/selftests/membarrier/membarrier_test_multi_thread.c | |||
@@ -0,0 +1,73 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
2 | #define _GNU_SOURCE | ||
3 | #include <linux/membarrier.h> | ||
4 | #include <syscall.h> | ||
5 | #include <stdio.h> | ||
6 | #include <errno.h> | ||
7 | #include <string.h> | ||
8 | #include <pthread.h> | ||
9 | |||
10 | #include "membarrier_test_impl.h" | ||
11 | |||
12 | static int thread_ready, thread_quit; | ||
13 | static pthread_mutex_t test_membarrier_thread_mutex = | ||
14 | PTHREAD_MUTEX_INITIALIZER; | ||
15 | static pthread_cond_t test_membarrier_thread_cond = | ||
16 | PTHREAD_COND_INITIALIZER; | ||
17 | |||
18 | void *test_membarrier_thread(void *arg) | ||
19 | { | ||
20 | pthread_mutex_lock(&test_membarrier_thread_mutex); | ||
21 | thread_ready = 1; | ||
22 | pthread_cond_broadcast(&test_membarrier_thread_cond); | ||
23 | pthread_mutex_unlock(&test_membarrier_thread_mutex); | ||
24 | |||
25 | pthread_mutex_lock(&test_membarrier_thread_mutex); | ||
26 | while (!thread_quit) | ||
27 | pthread_cond_wait(&test_membarrier_thread_cond, | ||
28 | &test_membarrier_thread_mutex); | ||
29 | pthread_mutex_unlock(&test_membarrier_thread_mutex); | ||
30 | |||
31 | return NULL; | ||
32 | } | ||
33 | |||
34 | static int test_mt_membarrier(void) | ||
35 | { | ||
36 | int i; | ||
37 | pthread_t test_thread; | ||
38 | |||
39 | pthread_create(&test_thread, NULL, | ||
40 | test_membarrier_thread, NULL); | ||
41 | |||
42 | pthread_mutex_lock(&test_membarrier_thread_mutex); | ||
43 | while (!thread_ready) | ||
44 | pthread_cond_wait(&test_membarrier_thread_cond, | ||
45 | &test_membarrier_thread_mutex); | ||
46 | pthread_mutex_unlock(&test_membarrier_thread_mutex); | ||
47 | |||
48 | test_membarrier_fail(); | ||
49 | |||
50 | test_membarrier_success(); | ||
51 | |||
52 | pthread_mutex_lock(&test_membarrier_thread_mutex); | ||
53 | thread_quit = 1; | ||
54 | pthread_cond_broadcast(&test_membarrier_thread_cond); | ||
55 | pthread_mutex_unlock(&test_membarrier_thread_mutex); | ||
56 | |||
57 | pthread_join(test_thread, NULL); | ||
58 | |||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | int main(int argc, char **argv) | ||
63 | { | ||
64 | ksft_print_header(); | ||
65 | ksft_set_plan(13); | ||
66 | |||
67 | test_membarrier_query(); | ||
68 | |||
69 | /* Multi-threaded */ | ||
70 | test_mt_membarrier(); | ||
71 | |||
72 | return ksft_exit_pass(); | ||
73 | } | ||
diff --git a/tools/testing/selftests/membarrier/membarrier_test_single_thread.c b/tools/testing/selftests/membarrier/membarrier_test_single_thread.c new file mode 100644 index 000000000000..c1c963902854 --- /dev/null +++ b/tools/testing/selftests/membarrier/membarrier_test_single_thread.c | |||
@@ -0,0 +1,24 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
2 | #define _GNU_SOURCE | ||
3 | #include <linux/membarrier.h> | ||
4 | #include <syscall.h> | ||
5 | #include <stdio.h> | ||
6 | #include <errno.h> | ||
7 | #include <string.h> | ||
8 | #include <pthread.h> | ||
9 | |||
10 | #include "membarrier_test_impl.h" | ||
11 | |||
12 | int main(int argc, char **argv) | ||
13 | { | ||
14 | ksft_print_header(); | ||
15 | ksft_set_plan(13); | ||
16 | |||
17 | test_membarrier_query(); | ||
18 | |||
19 | test_membarrier_fail(); | ||
20 | |||
21 | test_membarrier_success(); | ||
22 | |||
23 | return ksft_exit_pass(); | ||
24 | } | ||