kconfig.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #include <common.h>
  9. #include <test/lib.h>
  10. #include <test/test.h>
  11. #include <test/ut.h>
  12. static int lib_test_is_enabled(struct unit_test_state *uts)
  13. {
  14. ulong val;
  15. ut_asserteq(1, IS_ENABLED(CONFIG_CMDLINE));
  16. ut_asserteq(0, IS_ENABLED(CONFIG__UNDEFINED));
  17. ut_asserteq(1, CONFIG_IS_ENABLED(CMDLINE));
  18. ut_asserteq(0, CONFIG_IS_ENABLED(OF_PLATDATA));
  19. ut_asserteq(0, CONFIG_IS_ENABLED(_UNDEFINED));
  20. ut_asserteq(0xc000,
  21. IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED, CONFIG_BLOBLIST_ADDR));
  22. ut_asserteq(0xc000,
  23. CONFIG_IF_ENABLED_INT(BLOBLIST_FIXED, BLOBLIST_ADDR));
  24. /*
  25. * This fails if CONFIG_TEST_KCONFIG_ENABLE is not enabled, since the
  26. * value is used. Disable for SPL so that the errors in kconfig_spl.c
  27. * are detected, since otherwise a build error when building U-Boot may
  28. * cause SPL to not be built.
  29. */
  30. if (!IS_ENABLED(CONFIG_SANDBOX_SPL) &&
  31. IS_ENABLED(CONFIG_TEST_KCONFIG)) {
  32. val = IF_ENABLED_INT(CONFIG_TEST_KCONFIG_ENABLE,
  33. CONFIG_TEST_KCONFIG_VALUE);
  34. printf("value %ld\n", val);
  35. }
  36. /*
  37. * This fails if CONFIG_TEST_KCONFIG_ENABLE is not enabled, since the
  38. * value is used. Disable for SPL so that the errors in kconfig_spl.c
  39. * are detected, since otherwise a build error when building U-Boot may
  40. * cause SPL to not be built.
  41. */
  42. if (!IS_ENABLED(CONFIG_SANDBOX_SPL) &&
  43. CONFIG_IS_ENABLED(TEST_KCONFIG)) {
  44. val = CONFIG_IF_ENABLED_INT(TEST_KCONFIG_ENABLE,
  45. TEST_KCONFIG_VALUE);
  46. printf("value2 %ld\n", val);
  47. }
  48. return 0;
  49. }
  50. LIB_TEST(lib_test_is_enabled, 0);