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