thermal: use %d to print S32 parameters
[linux/fpc-iii.git] / tools / testing / selftests / membarrier / membarrier_test.c
blob535f0fef4d0bb524f638774ffc199fde10c97497
1 #define _GNU_SOURCE
2 #include <linux/membarrier.h>
3 #include <syscall.h>
4 #include <stdio.h>
5 #include <errno.h>
6 #include <string.h>
8 #include "../kselftest.h"
10 enum test_membarrier_status {
11 TEST_MEMBARRIER_PASS = 0,
12 TEST_MEMBARRIER_FAIL,
13 TEST_MEMBARRIER_SKIP,
16 static int sys_membarrier(int cmd, int flags)
18 return syscall(__NR_membarrier, cmd, flags);
21 static enum test_membarrier_status test_membarrier_cmd_fail(void)
23 int cmd = -1, flags = 0;
25 if (sys_membarrier(cmd, flags) != -1) {
26 printf("membarrier: Wrong command should fail but passed.\n");
27 return TEST_MEMBARRIER_FAIL;
29 return TEST_MEMBARRIER_PASS;
32 static enum test_membarrier_status test_membarrier_flags_fail(void)
34 int cmd = MEMBARRIER_CMD_QUERY, flags = 1;
36 if (sys_membarrier(cmd, flags) != -1) {
37 printf("membarrier: Wrong flags should fail but passed.\n");
38 return TEST_MEMBARRIER_FAIL;
40 return TEST_MEMBARRIER_PASS;
43 static enum test_membarrier_status test_membarrier_success(void)
45 int cmd = MEMBARRIER_CMD_SHARED, flags = 0;
47 if (sys_membarrier(cmd, flags) != 0) {
48 printf("membarrier: Executing MEMBARRIER_CMD_SHARED failed. %s.\n",
49 strerror(errno));
50 return TEST_MEMBARRIER_FAIL;
53 printf("membarrier: MEMBARRIER_CMD_SHARED success.\n");
54 return TEST_MEMBARRIER_PASS;
57 static enum test_membarrier_status test_membarrier(void)
59 enum test_membarrier_status status;
61 status = test_membarrier_cmd_fail();
62 if (status)
63 return status;
64 status = test_membarrier_flags_fail();
65 if (status)
66 return status;
67 status = test_membarrier_success();
68 if (status)
69 return status;
70 return TEST_MEMBARRIER_PASS;
73 static enum test_membarrier_status test_membarrier_query(void)
75 int flags = 0, ret;
77 printf("membarrier MEMBARRIER_CMD_QUERY ");
78 ret = sys_membarrier(MEMBARRIER_CMD_QUERY, flags);
79 if (ret < 0) {
80 printf("failed. %s.\n", strerror(errno));
81 switch (errno) {
82 case ENOSYS:
84 * It is valid to build a kernel with
85 * CONFIG_MEMBARRIER=n. However, this skips the tests.
87 return TEST_MEMBARRIER_SKIP;
88 case EINVAL:
89 default:
90 return TEST_MEMBARRIER_FAIL;
93 if (!(ret & MEMBARRIER_CMD_SHARED)) {
94 printf("command MEMBARRIER_CMD_SHARED is not supported.\n");
95 return TEST_MEMBARRIER_FAIL;
97 printf("syscall available.\n");
98 return TEST_MEMBARRIER_PASS;
101 int main(int argc, char **argv)
103 switch (test_membarrier_query()) {
104 case TEST_MEMBARRIER_FAIL:
105 return ksft_exit_fail();
106 case TEST_MEMBARRIER_SKIP:
107 return ksft_exit_skip();
109 switch (test_membarrier()) {
110 case TEST_MEMBARRIER_FAIL:
111 return ksft_exit_fail();
112 case TEST_MEMBARRIER_SKIP:
113 return ksft_exit_skip();
116 printf("membarrier: tests done!\n");
117 return ksft_exit_pass();