1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Test of linux/kconfig.h macros
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_is_enabled(struct unit_test_state * uts)13 static int lib_test_is_enabled(struct unit_test_state *uts)
14 {
15 	ulong val;
16 
17 	ut_asserteq(1, IS_ENABLED(CONFIG_CMDLINE));
18 	ut_asserteq(0, IS_ENABLED(CONFIG__UNDEFINED));
19 
20 	ut_asserteq(1, CONFIG_IS_ENABLED(CMDLINE));
21 	ut_asserteq(0, CONFIG_IS_ENABLED(OF_PLATDATA));
22 	ut_asserteq(0, CONFIG_IS_ENABLED(_UNDEFINED));
23 
24 	if (IS_ENABLED(CONFIG_BLOBLIST)) {
25 		ut_asserteq(0x100, IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED,
26 						  CONFIG_BLOBLIST_ADDR));
27 		ut_asserteq(0x100, CONFIG_IF_ENABLED_INT(BLOBLIST_FIXED,
28 							 BLOBLIST_ADDR));
29 	}
30 
31 	/*
32 	 * This fails if CONFIG_TEST_KCONFIG_ENABLE is not enabled, since the
33 	 * value is used. Disable for SPL so that the errors in kconfig_spl.c
34 	 * are detected, since otherwise a build error when building U-Boot may
35 	 * cause SPL to not be built.
36 	 */
37 	if (!IS_ENABLED(CONFIG_SANDBOX_SPL) &&
38 	    IS_ENABLED(CONFIG_TEST_KCONFIG)) {
39 		val = IF_ENABLED_INT(CONFIG_TEST_KCONFIG_ENABLE,
40 				     CONFIG_TEST_KCONFIG_VALUE);
41 		printf("value %ld\n", val);
42 	}
43 
44 	/*
45 	 * This fails if CONFIG_TEST_KCONFIG_ENABLE is not enabled, since the
46 	 * value is used. Disable for SPL so that the errors in kconfig_spl.c
47 	 * are detected, since otherwise a build error when building U-Boot may
48 	 * cause SPL to not be built.
49 	 */
50 	if (!IS_ENABLED(CONFIG_SANDBOX_SPL) &&
51 	    CONFIG_IS_ENABLED(TEST_KCONFIG)) {
52 		val = CONFIG_IF_ENABLED_INT(TEST_KCONFIG_ENABLE,
53 					    TEST_KCONFIG_VALUE);
54 		printf("value2 %ld\n", val);
55 	}
56 
57 	return 0;
58 }
59 LIB_TEST(lib_test_is_enabled, 0);
60