All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rafael David Tinoco <rafael.tinoco@linaro.org>
To: shuah@kernel.org
Cc: rafael.tinoco@linaro.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3] membarrier_test: work in progress
Date: Sun,  2 Sep 2018 23:12:23 -0300	[thread overview]
Message-ID: <20180903021223.8216-1-rafael.tinoco@linaro.org> (raw)
In-Reply-To: <1a86c3c5-66f5-24d8-4fcc-367302ecec35@kernel.org>

Shuah,

This is a draft only. I will remove summary from the top, run checkers,
etc. Im thinking in replacing membarrier_test entirely with this code
(compatible to existing one). Right now, this code:

 - allows each test to succeed, fail or be skipped independently
 - allows each test to be tested even when not supported (force option)
 - considers false negatives and false positives on every case
 - can be extended easily

Right now, just to show as an example, it gives us:

TAP version 13
ok 1 sys_membarrier(): cmd_query succeeded.
ok 2 sys_membarrier(): bad_cmd failed as expected.
ok 3 sys_membarrier(): cmd_with_flags_set failed as expected.
ok 4 sys_membarrier(): cmd_global succeeded.
Pass 4 Fail 0 Xfail 0 Xpass 0 Skip 0 Error 0
1..4

Are you okay with such move ? Only big TODO here is adding all covered
tests in the test array (easy move), testing all combinations with all
supported kernel versions (lab already ready) and suggesting it to you,
replacing membarrier_test.c.

PS: This is pretty close to how a LTP test would be, using their new
API, but, since it addresses your concerns and seems like a
simple/clean, code, I decided to suggest it as a replacement here (and
it also fixes the issue with this test and LTS kernels).
---
 tools/testing/selftests/membarrier/Makefile   |   2 +-
 .../selftests/membarrier/membarrier_test2.c   | 180 ++++++++++++++++++
 2 files changed, 181 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/membarrier/membarrier_test2.c

diff --git a/tools/testing/selftests/membarrier/Makefile b/tools/testing/selftests/membarrier/Makefile
index 02845532b059..3d44d4cd3a9d 100644
--- a/tools/testing/selftests/membarrier/Makefile
+++ b/tools/testing/selftests/membarrier/Makefile
@@ -1,6 +1,6 @@
 CFLAGS += -g -I../../../../usr/include/
 
-TEST_GEN_PROGS := membarrier_test
+TEST_GEN_PROGS := membarrier_test membarrier_test2
 
 include ../lib.mk
 
diff --git a/tools/testing/selftests/membarrier/membarrier_test2.c b/tools/testing/selftests/membarrier/membarrier_test2.c
new file mode 100644
index 000000000000..8fa1be6156fb
--- /dev/null
+++ b/tools/testing/selftests/membarrier/membarrier_test2.c
@@ -0,0 +1,180 @@
+// SPDX-License-Identifier: GPL-2.0
+#define _GNU_SOURCE
+#include <linux/membarrier.h>
+#include <syscall.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#include "../kselftest.h"
+/*
+	MEMBARRIER_CMD_QUERY
+		returns membarrier_cmd with supported features
+	MEMBARRIER_CMD_GLOBAL
+		returns 0
+		EINVAL = if nohz_full is enabled
+	MEMBARRIER_CMD_GLOBAL_EXPEDITED
+		returns 0
+	MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED
+		returns 0
+	MEMBARRIER_CMD_PRIVATE_EXPEDITED
+		returns 0
+		EINVAL = if CONFIG_ARCH_HAS_MEMBARRIER_SYNC_CORE is not enabled
+		EPERM  = if process did not register for PRIVATE_EXPEDITED
+	MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED
+		returns 0
+		EINVAL = if CONFIG_ARCH_HAS_MEMBARRIER_SYNC_CORE is not enabled
+	MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE
+		returns 0
+		EINVAL = if CONFIG_ARCH_HAS_MEMBARRIER_SYNC_CORE is not enabled
+		EPERM = if process did not register for PRIVATE_EXPEDITED
+	MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE
+		returns 0
+		EINVAL = if CONFIG_ARCH_HAS_MEMBARRIER_SYNC_CORE is not enabled
+*/
+
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
+struct memb_tests {
+	char testname[80];
+	int command;
+	int flags;
+	int exp_ret;
+	int exp_errno;
+	int supported;
+	int force;
+};
+
+struct memb_tests mbt[] = {
+	{
+	 .testname = "bad_cmd\0",
+	 .command = -1,
+	 .exp_ret = -1,
+	 .exp_errno = EINVAL,
+	 .supported = 1,
+	 },
+	{
+	 .testname = "cmd_with_flags_set\0",
+	 .command = MEMBARRIER_CMD_QUERY,
+	 .flags = 1,
+	 .exp_ret = -1,
+	 .exp_errno = EINVAL,
+	 .supported = 1,
+	 },
+	{
+	 .testname = "cmd_global\0",
+	 .command = MEMBARRIER_CMD_GLOBAL,
+	 .flags = 0,
+	 .exp_ret = 0,
+	 },
+};
+
+static void info_passed_ok(struct memb_tests test)
+{
+	ksft_test_result_pass("sys_membarrier(): %s succeeded.\n",
+			test.testname);
+}
+
+static void info_passed_unexpectedly(struct memb_tests test)
+{
+	ksft_test_result_fail("sys_membarrier(): %s passed unexpectedly. "
+			"ret = %d with errno %d were expected.\n",
+			test.testname, test.exp_ret, test.exp_errno);
+}
+
+static void info_failed_ok(struct memb_tests test)
+{
+	ksft_test_result_pass("sys_membarrier(): %s failed as expected.\n",
+			test.testname);
+}
+
+static void info_failed_not_ok(struct memb_tests test, int gotret, int goterr)
+{
+	ksft_test_result_fail("sys_membarrier(): %s failed as expected. "
+			"ret = %d when expected was %d. "
+			"errno = %d when expected was %d.\n",
+			test.testname, gotret, test.exp_ret, goterr,
+			test.exp_errno);
+}
+
+static void info_failed_unexpectedly(struct memb_tests test, int gotret, int goterr)
+{
+	ksft_test_result_fail("sys_membarrier(): %s failed unexpectedly. "
+			"Got ret = %d with errno %d.\n",
+			test.testname, gotret, goterr);
+}
+
+static void info_skipped(struct memb_tests test)
+{
+	ksft_test_result_skip("sys_membarrier(): %s unsupported, test skipped.\n",
+			test.testname);
+}
+
+static int sys_membarrier(int cmd, int flags)
+{
+	return syscall(__NR_membarrier, cmd, flags);
+}
+
+static void test_membarrier_tests(void)
+{
+	int i, ret;
+
+	for (i = 0; i < ARRAY_SIZE(mbt); i++) {
+
+		if (mbt[i].supported != 1 && mbt[i].force != 1) {
+			info_skipped(mbt[i]);
+			continue;
+		}
+
+		/* membarrier command should be evaluated */
+		ret = sys_membarrier(mbt[i].command, mbt[i].flags);
+
+		if (ret == mbt[i].exp_ret) {
+
+			if (ret >= 0)
+				info_passed_ok(mbt[i]);
+			else {
+				if (errno != mbt[i].exp_errno)
+					info_failed_not_ok(mbt[i], ret, errno);
+				else
+					info_failed_ok(mbt[i]);
+			}
+
+		} else {
+			if (ret >= 0)
+				info_passed_unexpectedly(mbt[i]);
+			else
+				info_failed_unexpectedly(mbt[i], ret, errno);
+		}
+	}
+}
+
+static int test_membarrier_prepare(void)
+{
+	int i, ret;
+
+	ret = sys_membarrier(MEMBARRIER_CMD_QUERY, 0);
+	if (ret < 0) {
+		if (errno == ENOSYS)
+			ksft_exit_skip("sys_membarrier(): CONFIG_MEMBARRIER is disabled.\n");
+
+		ksft_exit_fail_msg("sys_membarrier(): cmd_query failed.\n");
+	}
+
+	for (i = 0; i < ARRAY_SIZE(mbt); i++) {
+		if ((mbt[i].command > 0) && (ret & mbt[i].command))
+			mbt[i].supported = 1;
+	}
+
+	ksft_test_result_pass("sys_membarrier(): cmd_query succeeded.\n");
+}
+
+int main(int argc, char **argv)
+{
+	ksft_print_header();
+
+	test_membarrier_prepare();
+	test_membarrier_tests();
+
+	return ksft_exit_pass();
+}
-- 
2.19.0.rc1


  reply	other threads:[~2018-09-03  2:12 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-30 16:05 [PATCH] selftests: membarrier: fix test by checking supported commands Rafael David Tinoco
2018-07-30 16:05 ` Rafael David Tinoco
2018-07-30 16:05 ` rafael.tinoco
2018-07-30 16:13 ` Mathieu Desnoyers
2018-07-30 16:13   ` Mathieu Desnoyers
2018-07-30 16:13   ` mathieu.desnoyers
2018-07-30 23:32 ` Shuah Khan
2018-07-30 23:32   ` Shuah Khan
2018-07-30 23:32   ` shuah
2018-07-31  3:15   ` Rafael David Tinoco
2018-07-31  3:15     ` Rafael David Tinoco
2018-07-31  3:15     ` rafael.tinoco
2018-08-08 14:09     ` Rafael David Tinoco
2018-08-08 14:09       ` Rafael David Tinoco
2018-08-08 14:09       ` rafael.tinoco
2018-08-09 20:21   ` [PATCH v2] " Rafael David Tinoco
2018-08-09 20:21     ` Rafael David Tinoco
2018-08-09 20:21     ` rafael.tinoco
2018-08-27 22:52     ` Shuah Khan
2018-08-27 22:52       ` Shuah Khan
2018-08-27 22:52       ` shuah
2018-09-03  2:12       ` Rafael David Tinoco [this message]
2018-09-21 22:48         ` [PATCH v3] membarrier_test: work in progress Shuah Khan
2018-09-21 22:48           ` Shuah Khan
2018-09-21 22:48           ` shuah
2018-09-03 19:04       ` [PATCH v4] selftests: membarrier: reorganized test for LTS supportability Rafael David Tinoco
2018-09-03 19:11         ` Rafael David Tinoco
2018-09-21 22:53         ` Shuah Khan
2018-09-21 22:53           ` Shuah Khan
2018-09-21 22:53           ` shuah
2018-11-09 15:49           ` [PATCH v5] selftests: membarrier: re-organize test Rafael David Tinoco
2018-11-09 15:49             ` Rafael David Tinoco
2018-11-09 15:49             ` rafael.tinoco
2018-11-18 20:44             ` Rafael David Tinoco
2018-11-18 20:44               ` Rafael David Tinoco
2018-11-18 20:44               ` rafael.tinoco

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180903021223.8216-1-rafael.tinoco@linaro.org \
    --to=rafael.tinoco@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.