]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
selftests: add membarrier syscall test
authorPranith Kumar <bobby.prani@gmail.com>
Fri, 11 Sep 2015 20:07:42 +0000 (13:07 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 11 Sep 2015 22:21:34 +0000 (15:21 -0700)
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>
tools/testing/selftests/Makefile
tools/testing/selftests/membarrier/.gitignore [new file with mode: 0644]
tools/testing/selftests/membarrier/Makefile [new file with mode: 0644]
tools/testing/selftests/membarrier/membarrier_test.c [new file with mode: 0644]

index 0501511445963bd9a87540b73094456ec10987aa..89b05e2222c913ff47e12673e9850616f585dbf9 100644 (file)
@@ -6,6 +6,7 @@ TARGETS += firmware
 TARGETS += ftrace
 TARGETS += futex
 TARGETS += kcmp
+TARGETS += membarrier
 TARGETS += memfd
 TARGETS += memory-hotplug
 TARGETS += mount
diff --git a/tools/testing/selftests/membarrier/.gitignore b/tools/testing/selftests/membarrier/.gitignore
new file mode 100644 (file)
index 0000000..020c44f
--- /dev/null
@@ -0,0 +1 @@
+membarrier_test
diff --git a/tools/testing/selftests/membarrier/Makefile b/tools/testing/selftests/membarrier/Makefile
new file mode 100644 (file)
index 0000000..877a503
--- /dev/null
@@ -0,0 +1,11 @@
+CFLAGS += -g -I../../../../usr/include/
+
+all:
+       $(CC) $(CFLAGS) membarrier_test.c -o membarrier_test
+
+TEST_PROGS := membarrier_test
+
+include ../lib.mk
+
+clean:
+       $(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 (file)
index 0000000..3c9f217
--- /dev/null
@@ -0,0 +1,71 @@
+#define _GNU_SOURCE
+#define __EXPORTED_HEADERS__
+
+#include <linux/membarrier.h>
+#include <asm-generic/unistd.h>
+#include <sys/syscall.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#include "../kselftest.h"
+
+static int sys_membarrier(int cmd, int flags)
+{
+       return syscall(__NR_membarrier, cmd, flags);
+}
+
+static void test_membarrier_fail(void)
+{
+       int cmd = -1, flags = 0;
+
+       if (sys_membarrier(cmd, flags) != -1) {
+               printf("membarrier: Should fail but passed\n");
+               ksft_exit_fail();
+       }
+}
+
+static void test_membarrier_success(void)
+{
+       int flags = 0;
+
+       if (sys_membarrier(MEMBARRIER_CMD_SHARED, flags) != 0) {
+               printf("membarrier: Executing MEMBARRIER failed, %s\n",
+                               strerror(errno));
+               ksft_exit_fail();
+       }
+
+       printf("membarrier: MEMBARRIER_CMD_SHARED success\n");
+}
+
+static void test_membarrier(void)
+{
+       test_membarrier_fail();
+       test_membarrier_success();
+}
+
+static int test_membarrier_exists(void)
+{
+       int flags = 0;
+
+       if (sys_membarrier(MEMBARRIER_CMD_QUERY, flags))
+               return 0;
+
+       return 1;
+}
+
+int main(int argc, char **argv)
+{
+       printf("membarrier: MEMBARRIER_CMD_QUERY ");
+       if (test_membarrier_exists()) {
+               printf("syscall implemented\n");
+               test_membarrier();
+       } else {
+               printf("syscall not implemented!\n");
+               return ksft_exit_fail();
+       }
+
+       printf("membarrier: tests done!\n");
+
+       return ksft_exit_pass();
+}