1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
4 */
5
6 /*
7 * Test TST_EXP_FD and TST_EXP_FD_SILENT macro.
8 */
9
10 #include "tst_test.h"
11
fail_fd(void)12 static int fail_fd(void)
13 {
14 errno = EINVAL;
15 return -1;
16 }
17
pass_fd(void)18 static int pass_fd(void)
19 {
20 return 42;
21 }
22
inval_val(void)23 static int inval_val(void)
24 {
25 return -42;
26 }
27
zero_val(void)28 static int zero_val(void)
29 {
30 return 0;
31 }
32
do_test(void)33 static void do_test(void)
34 {
35 tst_res(TINFO, "Testing TST_EXP_FD macro");
36 TST_EXP_FD(fail_fd(), "fail_fd()");
37 tst_res(TINFO, "TST_PASS = %i", TST_PASS);
38 TST_EXP_FD(pass_fd(), "pass_fd()");
39 tst_res(TINFO, "TST_PASS = %i", TST_PASS);
40 TST_EXP_FD(inval_val(), "inval_val()");
41 tst_res(TINFO, "TST_PASS = %i", TST_PASS);
42 TST_EXP_FD(zero_val(), "zero_val()");
43 tst_res(TINFO, "TST_PASS = %i", TST_PASS);
44
45 tst_res(TINFO, "Testing TST_EXP_FD_SILENT macro");
46 TST_EXP_FD_SILENT(fail_fd(), "fail_fd()");
47 tst_res(TINFO, "TST_PASS = %i", TST_PASS);
48 TST_EXP_FD_SILENT(pass_fd(), "%s", "pass_fd()");
49 tst_res(TINFO, "TST_PASS = %i from TST_EXP_FD_SILENT(pass_fd, ...)", TST_PASS);
50 TST_EXP_FD_SILENT(inval_val(), "inval_val()");
51 tst_res(TINFO, "TST_PASS = %i", TST_PASS);
52 TST_EXP_FD_SILENT(zero_val(), "zero_val()");
53 tst_res(TINFO, "TST_PASS = %i from TST_EXP_FD_SILENT(zero_val, ...)", TST_PASS);
54 }
55
56 static struct tst_test test = {
57 .test_all = do_test,
58 };
59