1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Test of linux/kconfig.h macros for SPL
4  *
5  * Copyright 2022 Google LLC
6  * Written by Simon Glass <sjg@chromium.org>
7  */
8 
9 #include <test/lib.h>
10 #include <test/test.h>
11 #include <test/ut.h>
12 
lib_test_spl_is_enabled(struct unit_test_state * uts)13 static int lib_test_spl_is_enabled(struct unit_test_state *uts)
14 {
15 	ulong val;
16 
17 	ut_asserteq(0, CONFIG_IS_ENABLED(CMDLINE));
18 	ut_asserteq(1, CONFIG_IS_ENABLED(OF_PLATDATA));
19 	ut_asserteq(0, CONFIG_IS_ENABLED(_UNDEFINED));
20 
21 	/*
22 	 * This fails if CONFIG_TEST_KCONFIG_ENABLE is not enabled, since the
23 	 * value is used.
24 	 */
25 	if (IS_ENABLED(CONFIG_TEST_KCONFIG)) {
26 		val = IF_ENABLED_INT(CONFIG_TEST_KCONFIG_ENABLE,
27 				     CONFIG_TEST_KCONFIG_VALUE);
28 		printf("value %ld\n", val);
29 	}
30 
31 	/*
32 	 * This fails if CONFIG_TEST_KCONFIG_ENABLE is not enabled, since the
33 	 * value is used.
34 	 */
35 	if (CONFIG_IS_ENABLED(TEST_KCONFIG)) {
36 		val = CONFIG_IF_ENABLED_INT(TEST_KCONFIG_ENABLE,
37 					    TEST_KCONFIG_VALUE);
38 		printf("value2 %ld\n", val);
39 	}
40 
41 	return 0;
42 }
43 LIB_TEST(lib_test_spl_is_enabled, 0);
44