lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <f9ac780a9c2a8f106a4b69eeca3106d95998100f.1498777889.git.shuahkh@osg.samsung.com>
Date:   Thu, 29 Jun 2017 17:18:17 -0600
From:   Shuah Khan <shuahkh@....samsung.com>
To:     shuah@...nel.org, alice.ferrazzi@...il.com,
        gregkh@...uxfoundation.org, paul.elder@...t.edu, labath@...gle.com,
        panand@...hat.com, will.deacon@....com
Cc:     Shuah Khan <shuahkh@....samsung.com>,
        linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 4/4] selftests: membarrier: use ksft_* var arg msg api

Use ksft_* var arg msg to include strerror() info. in test output. Remove
redundant SKIP/FAIL/PASS logic as it is no longer needed with ksft_ api.
Improve test output to be consistent and clear.

Signed-off-by: Shuah Khan <shuahkh@....samsung.com>
---
 .../testing/selftests/membarrier/membarrier_test.c | 91 ++++++++++------------
 1 file changed, 41 insertions(+), 50 deletions(-)

diff --git a/tools/testing/selftests/membarrier/membarrier_test.c b/tools/testing/selftests/membarrier/membarrier_test.c
index 74a712eab2e6..21399fcf1a59 100644
--- a/tools/testing/selftests/membarrier/membarrier_test.c
+++ b/tools/testing/selftests/membarrier/membarrier_test.c
@@ -7,62 +7,63 @@
 
 #include "../kselftest.h"
 
-enum test_membarrier_status {
-	TEST_MEMBARRIER_PASS = 0,
-	TEST_MEMBARRIER_FAIL,
-	TEST_MEMBARRIER_SKIP,
-};
-
 static int sys_membarrier(int cmd, int flags)
 {
 	return syscall(__NR_membarrier, cmd, flags);
 }
 
-static enum test_membarrier_status test_membarrier_cmd_fail(void)
+static int test_membarrier_cmd_fail(void)
 {
 	int cmd = -1, flags = 0;
-	const char *test_name = "membarrier command cmd=-1. Wrong command should fail";
 
 	if (sys_membarrier(cmd, flags) != -1) {
-		ksft_test_result_fail(test_name);
-		return TEST_MEMBARRIER_FAIL;
+		ksft_exit_fail_msg(
+			"sys membarrier invalid command test: command = %d, flags = %d. Should fail, but passed\n",
+			cmd, flags);
 	}
 
-	ksft_test_result_pass(test_name);
-	return TEST_MEMBARRIER_PASS;
+	ksft_test_result_pass(
+		"sys membarrier invalid command test: command = %d, flags = %d. Failed as expected\n",
+		cmd, flags);
+	return 0;
 }
 
-static enum test_membarrier_status test_membarrier_flags_fail(void)
+static int test_membarrier_flags_fail(void)
 {
 	int cmd = MEMBARRIER_CMD_QUERY, flags = 1;
-	const char *test_name = "MEMBARRIER_CMD_QUERY, flags=1, Wrong flags should fail";
 
 	if (sys_membarrier(cmd, flags) != -1) {
-		ksft_test_result_fail(test_name);
-		return TEST_MEMBARRIER_FAIL;
+		ksft_exit_fail_msg(
+			"sys membarrier MEMBARRIER_CMD_QUERY invalid flags test: flags = %d. Should fail, but passed\n",
+			flags);
 	}
 
-	ksft_test_result_pass(test_name);
-	return TEST_MEMBARRIER_PASS;
+	ksft_test_result_pass(
+		"sys membarrier MEMBARRIER_CMD_QUERY invalid flags test: flags = %d. Failed as expected\n",
+		flags);
+	return 0;
 }
 
-static enum test_membarrier_status test_membarrier_success(void)
+static int test_membarrier_success(void)
 {
 	int cmd = MEMBARRIER_CMD_SHARED, flags = 0;
-	const char *test_name = "execute MEMBARRIER_CMD_SHARED";
+	const char *test_name = "sys membarrier MEMBARRIER_CMD_SHARED\n";
 
 	if (sys_membarrier(cmd, flags) != 0) {
-		ksft_test_result_fail(test_name);
-		return TEST_MEMBARRIER_FAIL;
+		ksft_exit_fail_msg(
+			"sys membarrier MEMBARRIER_CMD_SHARED test: flags = %d\n",
+			flags);
 	}
 
-	ksft_test_result_pass(test_name);
-	return TEST_MEMBARRIER_PASS;
+	ksft_test_result_pass(
+		"sys membarrier MEMBARRIER_CMD_SHARED test: flags = %d\n",
+		flags);
+	return 0;
 }
 
-static enum test_membarrier_status test_membarrier(void)
+static int test_membarrier(void)
 {
-	enum test_membarrier_status status;
+	int status;
 
 	status = test_membarrier_cmd_fail();
 	if (status)
@@ -73,10 +74,10 @@ static enum test_membarrier_status test_membarrier(void)
 	status = test_membarrier_success();
 	if (status)
 		return status;
-	return TEST_MEMBARRIER_PASS;
+	return 0;
 }
 
-static enum test_membarrier_status test_membarrier_query(void)
+static int test_membarrier_query(void)
 {
 	int flags = 0, ret;
 
@@ -87,34 +88,24 @@ static enum test_membarrier_status test_membarrier_query(void)
 			 * It is valid to build a kernel with
 			 * CONFIG_MEMBARRIER=n. However, this skips the tests.
 			 */
-			ksft_exit_skip("CONFIG_MEMBARRIER is not enabled\n");
+			ksft_exit_skip(
+				"sys membarrier (CONFIG_MEMBARRIER) is disabled.\n");
 		}
-		ksft_test_result_fail("sys_membarrier() failed\n");
-		return TEST_MEMBARRIER_FAIL;
-	}
-	if (!(ret & MEMBARRIER_CMD_SHARED)) {
-		ksft_test_result_fail("command MEMBARRIER_CMD_SHARED is not supported.\n");
-		return TEST_MEMBARRIER_FAIL;
+		ksft_exit_fail_msg("sys_membarrier() failed\n");
 	}
-	ksft_test_result_pass("sys_membarrier available");
-	return TEST_MEMBARRIER_PASS;
+	if (!(ret & MEMBARRIER_CMD_SHARED))
+		ksft_exit_fail_msg("sys_membarrier is not supported.\n");
+
+	ksft_test_result_pass("sys_membarrier available\n");
+	return 0;
 }
 
 int main(int argc, char **argv)
 {
 	ksft_print_header();
-	switch (test_membarrier_query()) {
-	case TEST_MEMBARRIER_FAIL:
-		return ksft_exit_fail();
-	case TEST_MEMBARRIER_SKIP:
-		return ksft_exit_skip(NULL);
-	}
-	switch (test_membarrier()) {
-	case TEST_MEMBARRIER_FAIL:
-		return ksft_exit_fail();
-	case TEST_MEMBARRIER_SKIP:
-		return ksft_exit_skip(NULL);
-	}
 
-	return ksft_exit_pass();
+	test_membarrier_query();
+	test_membarrier();
+
+	ksft_exit_pass();
 }
-- 
2.11.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ