diff options
author | Pranith Kumar <bobby.prani@gmail.com> | 2015-09-11 16:07:42 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-09-11 18:21:34 -0400 |
commit | b6d973441675222a4e6c8cad8208c2fe098a0b25 (patch) | |
tree | dc2a7ac4e7ddfb622722caf9b8ab3f5f13abd178 | |
parent | 5b25b13ab08f616efd566347d809b4ece54570d1 (diff) |
selftests: add membarrier syscall test
Add a self test for the membarrier system call.
Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Shuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | tools/testing/selftests/Makefile | 1 | ||||
-rw-r--r-- | tools/testing/selftests/membarrier/.gitignore | 1 | ||||
-rw-r--r-- | tools/testing/selftests/membarrier/Makefile | 11 | ||||
-rw-r--r-- | tools/testing/selftests/membarrier/membarrier_test.c | 71 |
4 files changed, 84 insertions, 0 deletions
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 050151144596..89b05e2222c9 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile | |||
@@ -6,6 +6,7 @@ TARGETS += firmware | |||
6 | TARGETS += ftrace | 6 | TARGETS += ftrace |
7 | TARGETS += futex | 7 | TARGETS += futex |
8 | TARGETS += kcmp | 8 | TARGETS += kcmp |
9 | TARGETS += membarrier | ||
9 | TARGETS += memfd | 10 | TARGETS += memfd |
10 | TARGETS += memory-hotplug | 11 | TARGETS += memory-hotplug |
11 | TARGETS += mount | 12 | TARGETS += mount |
diff --git a/tools/testing/selftests/membarrier/.gitignore b/tools/testing/selftests/membarrier/.gitignore new file mode 100644 index 000000000000..020c44f49a9e --- /dev/null +++ b/tools/testing/selftests/membarrier/.gitignore | |||
@@ -0,0 +1 @@ | |||
membarrier_test | |||
diff --git a/tools/testing/selftests/membarrier/Makefile b/tools/testing/selftests/membarrier/Makefile new file mode 100644 index 000000000000..877a50355d7f --- /dev/null +++ b/tools/testing/selftests/membarrier/Makefile | |||
@@ -0,0 +1,11 @@ | |||
1 | CFLAGS += -g -I../../../../usr/include/ | ||
2 | |||
3 | all: | ||
4 | $(CC) $(CFLAGS) membarrier_test.c -o membarrier_test | ||
5 | |||
6 | TEST_PROGS := membarrier_test | ||
7 | |||
8 | include ../lib.mk | ||
9 | |||
10 | clean: | ||
11 | $(RM) membarrier_test | ||
diff --git a/tools/testing/selftests/membarrier/membarrier_test.c b/tools/testing/selftests/membarrier/membarrier_test.c new file mode 100644 index 000000000000..3c9f2179acd8 --- /dev/null +++ b/tools/testing/selftests/membarrier/membarrier_test.c | |||
@@ -0,0 +1,71 @@ | |||
1 | #define _GNU_SOURCE | ||
2 | #define __EXPORTED_HEADERS__ | ||
3 | |||
4 | #include <linux/membarrier.h> | ||
5 | #include <asm-generic/unistd.h> | ||
6 | #include <sys/syscall.h> | ||
7 | #include <stdio.h> | ||
8 | #include <errno.h> | ||
9 | #include <string.h> | ||
10 | |||
11 | #include "../kselftest.h" | ||
12 | |||
13 | static int sys_membarrier(int cmd, int flags) | ||
14 | { | ||
15 | return syscall(__NR_membarrier, cmd, flags); | ||
16 | } | ||
17 | |||
18 | static void test_membarrier_fail(void) | ||
19 | { | ||
20 | int cmd = -1, flags = 0; | ||
21 | |||
22 | if (sys_membarrier(cmd, flags) != -1) { | ||
23 | printf("membarrier: Should fail but passed\n"); | ||
24 | ksft_exit_fail(); | ||
25 | } | ||
26 | } | ||
27 | |||
28 | static void test_membarrier_success(void) | ||
29 | { | ||
30 | int flags = 0; | ||
31 | |||
32 | if (sys_membarrier(MEMBARRIER_CMD_SHARED, flags) != 0) { | ||
33 | printf("membarrier: Executing MEMBARRIER failed, %s\n", | ||
34 | strerror(errno)); | ||
35 | ksft_exit_fail(); | ||
36 | } | ||
37 | |||
38 | printf("membarrier: MEMBARRIER_CMD_SHARED success\n"); | ||
39 | } | ||
40 | |||
41 | static void test_membarrier(void) | ||
42 | { | ||
43 | test_membarrier_fail(); | ||
44 | test_membarrier_success(); | ||
45 | } | ||
46 | |||
47 | static int test_membarrier_exists(void) | ||
48 | { | ||
49 | int flags = 0; | ||
50 | |||
51 | if (sys_membarrier(MEMBARRIER_CMD_QUERY, flags)) | ||
52 | return 0; | ||
53 | |||
54 | return 1; | ||
55 | } | ||
56 | |||
57 | int main(int argc, char **argv) | ||
58 | { | ||
59 | printf("membarrier: MEMBARRIER_CMD_QUERY "); | ||
60 | if (test_membarrier_exists()) { | ||
61 | printf("syscall implemented\n"); | ||
62 | test_membarrier(); | ||
63 | } else { | ||
64 | printf("syscall not implemented!\n"); | ||
65 | return ksft_exit_fail(); | ||
66 | } | ||
67 | |||
68 | printf("membarrier: tests done!\n"); | ||
69 | |||
70 | return ksft_exit_pass(); | ||
71 | } | ||