Commit 667ca1ec authored by Mathieu Desnoyers's avatar Mathieu Desnoyers Committed by Ingo Molnar

membarrier/selftest: Test private expedited command

Test the new MEMBARRIER_CMD_PRIVATE_EXPEDITED and
MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED commands.

Add checks expecting specific error values on system calls expected to
fail.
Signed-off-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Acked-by: default avatarThomas Gleixner <tglx@linutronix.de>
Acked-by: default avatarShuah Khan <shuahkh@osg.samsung.com>
Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Alice Ferrazzi <alice.ferrazzi@gmail.com>
Cc: Andrea Parri <parri.andrea@gmail.com>
Cc: Andrew Hunter <ahh@google.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Avi Kivity <avi@scylladb.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Dave Watson <davejwatson@fb.com>
Cc: David Sehr <sehr@google.com>
Cc: Greg Hackmann <ghackmann@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Maged Michael <maged.michael@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Paul Elder <paul.elder@pitt.edu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Will Deacon <will.deacon@arm.com>
Cc: linux-api@vger.kernel.org
Cc: linux-arch@vger.kernel.org
Cc: linux-kselftest@vger.kernel.org
Link: http://lkml.kernel.org/r/20180129202020.8515-2-mathieu.desnoyers@efficios.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 72906f38
......@@ -16,49 +16,119 @@ static int sys_membarrier(int cmd, int flags)
static int test_membarrier_cmd_fail(void)
{
int cmd = -1, flags = 0;
const char *test_name = "sys membarrier invalid command";
if (sys_membarrier(cmd, flags) != -1) {
ksft_exit_fail_msg(
"sys membarrier invalid command test: command = %d, flags = %d. Should fail, but passed\n",
cmd, flags);
"%s test: command = %d, flags = %d. Should fail, but passed\n",
test_name, cmd, flags);
}
if (errno != EINVAL) {
ksft_exit_fail_msg(
"%s test: flags = %d. Should return (%d: \"%s\"), but returned (%d: \"%s\").\n",
test_name, flags, EINVAL, strerror(EINVAL),
errno, strerror(errno));
}
ksft_test_result_pass(
"sys membarrier invalid command test: command = %d, flags = %d. Failed as expected\n",
cmd, flags);
"%s test: command = %d, flags = %d, errno = %d. Failed as expected\n",
test_name, cmd, flags, errno);
return 0;
}
static int test_membarrier_flags_fail(void)
{
int cmd = MEMBARRIER_CMD_QUERY, flags = 1;
const char *test_name = "sys membarrier MEMBARRIER_CMD_QUERY invalid flags";
if (sys_membarrier(cmd, flags) != -1) {
ksft_exit_fail_msg(
"sys membarrier MEMBARRIER_CMD_QUERY invalid flags test: flags = %d. Should fail, but passed\n",
flags);
"%s test: flags = %d. Should fail, but passed\n",
test_name, flags);
}
if (errno != EINVAL) {
ksft_exit_fail_msg(
"%s test: flags = %d. Should return (%d: \"%s\"), but returned (%d: \"%s\").\n",
test_name, flags, EINVAL, strerror(EINVAL),
errno, strerror(errno));
}
ksft_test_result_pass(
"sys membarrier MEMBARRIER_CMD_QUERY invalid flags test: flags = %d. Failed as expected\n",
flags);
"%s test: flags = %d, errno = %d. Failed as expected\n",
test_name, flags, errno);
return 0;
}
static int test_membarrier_success(void)
static int test_membarrier_shared_success(void)
{
int cmd = MEMBARRIER_CMD_SHARED, flags = 0;
const char *test_name = "sys membarrier MEMBARRIER_CMD_SHARED\n";
const char *test_name = "sys membarrier MEMBARRIER_CMD_SHARED";
if (sys_membarrier(cmd, flags) != 0) {
ksft_exit_fail_msg(
"%s test: flags = %d, errno = %d\n",
test_name, flags, errno);
}
ksft_test_result_pass(
"%s test: flags = %d\n", test_name, flags);
return 0;
}
static int test_membarrier_private_expedited_fail(void)
{
int cmd = MEMBARRIER_CMD_PRIVATE_EXPEDITED, flags = 0;
const char *test_name = "sys membarrier MEMBARRIER_CMD_PRIVATE_EXPEDITED not registered failure";
if (sys_membarrier(cmd, flags) != -1) {
ksft_exit_fail_msg(
"%s test: flags = %d. Should fail, but passed\n",
test_name, flags);
}
if (errno != EPERM) {
ksft_exit_fail_msg(
"%s test: flags = %d. Should return (%d: \"%s\"), but returned (%d: \"%s\").\n",
test_name, flags, EPERM, strerror(EPERM),
errno, strerror(errno));
}
ksft_test_result_pass(
"%s test: flags = %d, errno = %d\n",
test_name, flags, errno);
return 0;
}
static int test_membarrier_register_private_expedited_success(void)
{
int cmd = MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED, flags = 0;
const char *test_name = "sys membarrier MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED";
if (sys_membarrier(cmd, flags) != 0) {
ksft_exit_fail_msg(
"sys membarrier MEMBARRIER_CMD_SHARED test: flags = %d\n",
flags);
"%s test: flags = %d, errno = %d\n",
test_name, flags, errno);
}
ksft_test_result_pass(
"sys membarrier MEMBARRIER_CMD_SHARED test: flags = %d\n",
flags);
"%s test: flags = %d\n",
test_name, flags);
return 0;
}
static int test_membarrier_private_expedited_success(void)
{
int cmd = MEMBARRIER_CMD_PRIVATE_EXPEDITED, flags = 0;
const char *test_name = "sys membarrier MEMBARRIER_CMD_PRIVATE_EXPEDITED";
if (sys_membarrier(cmd, flags) != 0) {
ksft_exit_fail_msg(
"%s test: flags = %d, errno = %d\n",
test_name, flags, errno);
}
ksft_test_result_pass(
"%s test: flags = %d\n",
test_name, flags);
return 0;
}
......@@ -72,7 +142,16 @@ static int test_membarrier(void)
status = test_membarrier_flags_fail();
if (status)
return status;
status = test_membarrier_success();
status = test_membarrier_shared_success();
if (status)
return status;
status = test_membarrier_private_expedited_fail();
if (status)
return status;
status = test_membarrier_register_private_expedited_success();
if (status)
return status;
status = test_membarrier_private_expedited_success();
if (status)
return status;
return 0;
......@@ -108,5 +187,5 @@ int main(int argc, char **argv)
test_membarrier_query();
test_membarrier();
ksft_exit_pass();
return ksft_exit_pass();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment