cmd_ut.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * (C) Copyright 2015
  4. * Joe Hershberger, National Instruments, joe.hershberger@ni.com
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <console.h>
  9. #include <test/suites.h>
  10. #include <test/test.h>
  11. #include <test/ut.h>
  12. static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
  13. char *const argv[]);
  14. int cmd_ut_category(const char *name, const char *prefix,
  15. struct unit_test *tests, int n_ents,
  16. int argc, char *const argv[])
  17. {
  18. int ret;
  19. ret = ut_run_list(name, prefix, tests, n_ents,
  20. argc > 1 ? argv[1] : NULL);
  21. return ret ? CMD_RET_FAILURE : 0;
  22. }
  23. static struct cmd_tbl cmd_ut_sub[] = {
  24. U_BOOT_CMD_MKENT(all, CONFIG_SYS_MAXARGS, 1, do_ut_all, "", ""),
  25. #if defined(CONFIG_UT_DM)
  26. U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""),
  27. #endif
  28. #if defined(CONFIG_UT_ENV)
  29. U_BOOT_CMD_MKENT(env, CONFIG_SYS_MAXARGS, 1, do_ut_env, "", ""),
  30. #endif
  31. #ifdef CONFIG_UT_OPTEE
  32. U_BOOT_CMD_MKENT(optee, CONFIG_SYS_MAXARGS, 1, do_ut_optee, "", ""),
  33. #endif
  34. #ifdef CONFIG_UT_OVERLAY
  35. U_BOOT_CMD_MKENT(overlay, CONFIG_SYS_MAXARGS, 1, do_ut_overlay, "", ""),
  36. #endif
  37. #ifdef CONFIG_UT_LIB
  38. U_BOOT_CMD_MKENT(lib, CONFIG_SYS_MAXARGS, 1, do_ut_lib, "", ""),
  39. #endif
  40. #ifdef CONFIG_UT_LOG
  41. U_BOOT_CMD_MKENT(log, CONFIG_SYS_MAXARGS, 1, do_ut_log, "", ""),
  42. #endif
  43. U_BOOT_CMD_MKENT(mem, CONFIG_SYS_MAXARGS, 1, do_ut_mem, "", ""),
  44. #ifdef CONFIG_CMD_SETEXPR
  45. U_BOOT_CMD_MKENT(setexpr, CONFIG_SYS_MAXARGS, 1, do_ut_setexpr, "",
  46. ""),
  47. #endif
  48. #ifdef CONFIG_UT_TIME
  49. U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
  50. #endif
  51. #if CONFIG_IS_ENABLED(UT_UNICODE) && !defined(API_BUILD)
  52. U_BOOT_CMD_MKENT(unicode, CONFIG_SYS_MAXARGS, 1, do_ut_unicode, "", ""),
  53. #endif
  54. #ifdef CONFIG_SANDBOX
  55. U_BOOT_CMD_MKENT(compression, CONFIG_SYS_MAXARGS, 1, do_ut_compression,
  56. "", ""),
  57. U_BOOT_CMD_MKENT(bloblist, CONFIG_SYS_MAXARGS, 1, do_ut_bloblist,
  58. "", ""),
  59. U_BOOT_CMD_MKENT(bootm, CONFIG_SYS_MAXARGS, 1, do_ut_bootm, "", ""),
  60. #endif
  61. U_BOOT_CMD_MKENT(str, CONFIG_SYS_MAXARGS, 1, do_ut_str, "", ""),
  62. #ifdef CONFIG_CMD_ADDRMAP
  63. U_BOOT_CMD_MKENT(addrmap, CONFIG_SYS_MAXARGS, 1, do_ut_addrmap, "", ""),
  64. #endif
  65. };
  66. static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
  67. char *const argv[])
  68. {
  69. int i;
  70. int retval;
  71. int any_fail = 0;
  72. for (i = 1; i < ARRAY_SIZE(cmd_ut_sub); i++) {
  73. printf("----Running %s tests----\n", cmd_ut_sub[i].name);
  74. retval = cmd_ut_sub[i].cmd(cmdtp, flag, 1, &cmd_ut_sub[i].name);
  75. if (!any_fail)
  76. any_fail = retval;
  77. }
  78. return any_fail;
  79. }
  80. static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  81. {
  82. struct cmd_tbl *cp;
  83. if (argc < 2)
  84. return CMD_RET_USAGE;
  85. /* drop initial "ut" arg */
  86. argc--;
  87. argv++;
  88. cp = find_cmd_tbl(argv[0], cmd_ut_sub, ARRAY_SIZE(cmd_ut_sub));
  89. if (cp)
  90. return cp->cmd(cmdtp, flag, argc, argv);
  91. return CMD_RET_USAGE;
  92. }
  93. #ifdef CONFIG_SYS_LONGHELP
  94. static char ut_help_text[] =
  95. "all - execute all enabled tests\n"
  96. #ifdef CONFIG_SANDBOX
  97. "ut bloblist - Test bloblist implementation\n"
  98. "ut compression - Test compressors and bootm decompression\n"
  99. #endif
  100. #ifdef CONFIG_UT_DM
  101. "ut dm [test-name]\n"
  102. #endif
  103. #ifdef CONFIG_UT_ENV
  104. "ut env [test-name]\n"
  105. #endif
  106. #ifdef CONFIG_UT_LIB
  107. "ut lib [test-name] - test library functions\n"
  108. #endif
  109. #ifdef CONFIG_UT_LOG
  110. "ut log [test-name] - test logging functions\n"
  111. #endif
  112. "ut mem [test-name] - test memory-related commands\n"
  113. #ifdef CONFIG_UT_OPTEE
  114. "ut optee [test-name]\n"
  115. #endif
  116. #ifdef CONFIG_UT_OVERLAY
  117. "ut overlay [test-name]\n"
  118. #endif
  119. "ut setexpr [test-name] - test setexpr command\n"
  120. #ifdef CONFIG_SANDBOX
  121. "ut str - Basic test of string functions\n"
  122. #endif
  123. #ifdef CONFIG_UT_TIME
  124. "ut time - Very basic test of time functions\n"
  125. #endif
  126. #if defined(CONFIG_UT_UNICODE) && \
  127. !defined(CONFIG_SPL_BUILD) && !defined(API_BUILD)
  128. "ut unicode [test-name] - test Unicode functions\n"
  129. #endif
  130. #ifdef CONFIG_CMD_ADDRMAP
  131. "ut addrmap - Very basic test of addrmap command\n"
  132. #endif
  133. ;
  134. #endif /* CONFIG_SYS_LONGHELP */
  135. U_BOOT_CMD(
  136. ut, CONFIG_SYS_MAXARGS, 1, do_ut,
  137. "unit tests", ut_help_text
  138. );