summaryrefslogtreecommitdiff
path: root/test/static_if.c
blob: f70f7d30c34bef0cc0b2946ef83da4f6f4819f94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Copyright 2019 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/* Test the STATIC_IF and STATIC_IF_NOT macros. */

#include "common.h"
#include "test_util.h"

#undef CONFIG_UNDEFINED
#define CONFIG_BLANK

STATIC_IF(CONFIG_UNDEFINED) int this_var_is_extern;
STATIC_IF_NOT(CONFIG_BLANK) int this_var_is_extern_too;
STATIC_IF(CONFIG_BLANK) int this_var_is_static;
STATIC_IF_NOT(CONFIG_UNDEFINED) int this_var_is_static_too;

static int test_static_if_blank(void)
{
	TEST_ASSERT(this_var_is_static == 0);
	TEST_ASSERT(this_var_is_static_too == 0);

	return EC_SUCCESS;
}

static int test_static_if_unused_no_fail(void)
{
	/*
	 * This should not cause linker errors because the variables
	 * go unused (usage is optimized away).
	 */
	if (IS_ENABLED(CONFIG_UNDEFINED))
		this_var_is_extern = 1;

	if (!IS_ENABLED(CONFIG_BLANK))
		this_var_is_extern_too = 1;

	return EC_SUCCESS;
}

void run_test(int argc, char **argv)
{
	test_reset();

	RUN_TEST(test_static_if_blank);
	RUN_TEST(test_static_if_unused_no_fail);

	test_print_result();
}