The patch titled Subject: selftests: add membarrier syscall test has been added to the -mm tree. Its filename is selftests-add-membarrier-syscall-test.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/selftests-add-membarrier-syscall-test.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/selftests-add-membarrier-syscall-test.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Pranith Kumar <bobby.prani@xxxxxxxxx> Subject: selftests: add membarrier syscall test Add a self test for the membarrier system call. Signed-off-by: Pranith Kumar <bobby.prani@xxxxxxxxx> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx> Cc: Michael Ellerman <mpe@xxxxxxxxxxxxxx> Cc: Shuah Khan <shuahkh@xxxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- tools/testing/selftests/Makefile | 1 tools/testing/selftests/membarrier/.gitignore | 1 tools/testing/selftests/membarrier/Makefile | 11 + tools/testing/selftests/membarrier/membarrier_test.c | 71 ++++++++++ 4 files changed, 84 insertions(+) diff -puN tools/testing/selftests/Makefile~selftests-add-membarrier-syscall-test tools/testing/selftests/Makefile --- a/tools/testing/selftests/Makefile~selftests-add-membarrier-syscall-test +++ a/tools/testing/selftests/Makefile @@ -7,6 +7,7 @@ TARGETS += ftrace TARGETS += futex TARGETS += kcmp TARGETS += kdbus +TARGETS += membarrier TARGETS += memfd TARGETS += memory-hotplug TARGETS += mount diff -puN /dev/null tools/testing/selftests/membarrier/.gitignore --- /dev/null +++ a/tools/testing/selftests/membarrier/.gitignore @@ -0,0 +1 @@ +membarrier_test diff -puN /dev/null tools/testing/selftests/membarrier/Makefile --- /dev/null +++ a/tools/testing/selftests/membarrier/Makefile @@ -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 -puN /dev/null tools/testing/selftests/membarrier/membarrier_test.c --- /dev/null +++ a/tools/testing/selftests/membarrier/membarrier_test.c @@ -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(); +} _ Patches currently in -mm which might be from bobby.prani@xxxxxxxxx are linux-next.patch sys_membarrier-system-wide-memory-barrier-generic-x86.patch selftests-add-membarrier-syscall-test.patch selftests-enhance-membarrier-syscall-test.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html