mirror of https://gitee.com/openkylin/linux.git
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@osg.samsung.com>
This commit is contained in:
parent
0732d06ee5
commit
e67f85fb96
|
@ -7,62 +7,63 @@
|
||||||
|
|
||||||
#include "../kselftest.h"
|
#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)
|
static int sys_membarrier(int cmd, int flags)
|
||||||
{
|
{
|
||||||
return syscall(__NR_membarrier, cmd, 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;
|
int cmd = -1, flags = 0;
|
||||||
const char *test_name = "membarrier command cmd=-1. Wrong command should fail";
|
|
||||||
|
|
||||||
if (sys_membarrier(cmd, flags) != -1) {
|
if (sys_membarrier(cmd, flags) != -1) {
|
||||||
ksft_test_result_fail(test_name);
|
ksft_exit_fail_msg(
|
||||||
return TEST_MEMBARRIER_FAIL;
|
"sys membarrier invalid command test: command = %d, flags = %d. Should fail, but passed\n",
|
||||||
|
cmd, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
ksft_test_result_pass(test_name);
|
ksft_test_result_pass(
|
||||||
return TEST_MEMBARRIER_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;
|
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) {
|
if (sys_membarrier(cmd, flags) != -1) {
|
||||||
ksft_test_result_fail(test_name);
|
ksft_exit_fail_msg(
|
||||||
return TEST_MEMBARRIER_FAIL;
|
"sys membarrier MEMBARRIER_CMD_QUERY invalid flags test: flags = %d. Should fail, but passed\n",
|
||||||
|
flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
ksft_test_result_pass(test_name);
|
ksft_test_result_pass(
|
||||||
return TEST_MEMBARRIER_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;
|
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) {
|
if (sys_membarrier(cmd, flags) != 0) {
|
||||||
ksft_test_result_fail(test_name);
|
ksft_exit_fail_msg(
|
||||||
return TEST_MEMBARRIER_FAIL;
|
"sys membarrier MEMBARRIER_CMD_SHARED test: flags = %d\n",
|
||||||
|
flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
ksft_test_result_pass(test_name);
|
ksft_test_result_pass(
|
||||||
return TEST_MEMBARRIER_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();
|
status = test_membarrier_cmd_fail();
|
||||||
if (status)
|
if (status)
|
||||||
|
@ -73,10 +74,10 @@ static enum test_membarrier_status test_membarrier(void)
|
||||||
status = test_membarrier_success();
|
status = test_membarrier_success();
|
||||||
if (status)
|
if (status)
|
||||||
return 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;
|
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
|
* It is valid to build a kernel with
|
||||||
* CONFIG_MEMBARRIER=n. However, this skips the tests.
|
* 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");
|
ksft_exit_fail_msg("sys_membarrier() failed\n");
|
||||||
return TEST_MEMBARRIER_FAIL;
|
|
||||||
}
|
}
|
||||||
if (!(ret & MEMBARRIER_CMD_SHARED)) {
|
if (!(ret & MEMBARRIER_CMD_SHARED))
|
||||||
ksft_test_result_fail("command MEMBARRIER_CMD_SHARED is not supported.\n");
|
ksft_exit_fail_msg("sys_membarrier is not supported.\n");
|
||||||
return TEST_MEMBARRIER_FAIL;
|
|
||||||
}
|
ksft_test_result_pass("sys_membarrier available\n");
|
||||||
ksft_test_result_pass("sys_membarrier available");
|
return 0;
|
||||||
return TEST_MEMBARRIER_PASS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
ksft_print_header();
|
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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue