1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) 2021 Cyril Hrubis <chrubis@suse.cz>
4 */
5
6/*
7 * Tests various corner conditions:
8 *
9 * - default message, i.e. first argument stringification
10 * - macro indirection, i.e. we have to stringify early
11 *
12 * The output should include the MACRO_FAIL() as the either fail of pass
13 * message. If it's missing or if it has been replaced by the function name
14 * there is a bug in the TST_EXP_*() macro.
15 */
16
17#include "tst_test.h"
18
19static int fail_fn_should_not_be_seen_in_output(void)
20{
21	errno = EINVAL;
22	return -1;
23}
24
25#define MACRO_FAIL() fail_fn_should_not_be_seen_in_output()
26
27static void do_test(void)
28{
29	TST_EXP_VAL(MACRO_FAIL(), -2);
30	TST_EXP_VAL_SILENT(MACRO_FAIL(), -2);
31
32	TST_EXP_FAIL(MACRO_FAIL(), EINVAL);
33	TST_EXP_FAIL2(MACRO_FAIL(), EINVAL);
34
35	TST_EXP_PASS(MACRO_FAIL());
36	TST_EXP_PASS_SILENT(MACRO_FAIL());
37
38	TST_EXP_PID(MACRO_FAIL());
39	TST_EXP_PID_SILENT(MACRO_FAIL());
40
41	TST_EXP_FD(MACRO_FAIL());
42	TST_EXP_FD_SILENT(MACRO_FAIL());
43
44	TST_EXP_POSITIVE(MACRO_FAIL());
45}
46
47static struct tst_test test = {
48	.test_all = do_test,
49};
50