Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753020AbbEDVA4 (ORCPT ); Mon, 4 May 2015 17:00:56 -0400 Received: from mail.efficios.com ([78.47.125.74]:37460 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752518AbbEDVAr (ORCPT ); Mon, 4 May 2015 17:00:47 -0400 From: Mathieu Desnoyers To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Pranith Kumar , Mathieu Desnoyers Subject: [PATCH 2/2] selftests: Add membarrier syscall test Date: Mon, 4 May 2015 17:00:13 -0400 Message-Id: <1430773213-8981-3-git-send-email-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1430773213-8981-1-git-send-email-mathieu.desnoyers@efficios.com> References: <1430773213-8981-1-git-send-email-mathieu.desnoyers@efficios.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3822 Lines: 137 From: Pranith Kumar This commit adds a selftest for the membarrier system call. Signed-off-by: Pranith Kumar Signed-off-by: Mathieu Desnoyers --- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/membarrier/.gitignore | 1 + tools/testing/selftests/membarrier/Makefile | 13 ++++ .../testing/selftests/membarrier/membarrier_test.c | 69 ++++++++++++++++++++ 4 files changed, 84 insertions(+), 0 deletions(-) create mode 100644 tools/testing/selftests/membarrier/.gitignore create mode 100644 tools/testing/selftests/membarrier/Makefile create mode 100644 tools/testing/selftests/membarrier/membarrier_test.c diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 95abddc..73824b1 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -5,6 +5,7 @@ TARGETS += exec TARGETS += firmware TARGETS += ftrace 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 index 0000000..020c44f4 --- /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 0000000..752b719 --- /dev/null +++ b/tools/testing/selftests/membarrier/Makefile @@ -0,0 +1,13 @@ +CFLAGS += -g -D_FILE_OFFSET_BITS=64 +CFLAGS += -I../../../../include/uapi/ +CFLAGS += -I../../../../include/ + +all: + gcc $(CFLAGS) membarrier_test.c -o membarrier_test + +run_tests: all + gcc $(CFLAGS) membarrier_test.c -o membarrier_test + @./membarrier_test || echo "membarrier_test: [FAIL]" + +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 index 0000000..ea285b0 --- /dev/null +++ b/tools/testing/selftests/membarrier/membarrier_test.c @@ -0,0 +1,69 @@ +#define _GNU_SOURCE +#define __EXPORTED_HEADERS__ + +#include +#include +#include +#include +#include +#include + +#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 ksft_exit_fail(); + + 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"); + + printf("membarrier: tests done!\n"); + + return ksft_exit_pass(); +} -- 1.7.7.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/