diff options
Diffstat (limited to 'test/static_if.c')
-rw-r--r-- | test/static_if.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/static_if.c b/test/static_if.c new file mode 100644 index 0000000000..46e8057d7f --- /dev/null +++ b/test/static_if.c @@ -0,0 +1,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(void) +{ + test_reset(); + + RUN_TEST(test_static_if_blank); + RUN_TEST(test_static_if_unused_no_fail); + + test_print_result(); +} |