cmd_ut.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_ut_print, "", ""),
  49. #ifdef CONFIG_UT_TIME
  50. U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
  51. #endif
  52. #if CONFIG_IS_ENABLED(UT_UNICODE) && !defined(API_BUILD)
  53. U_BOOT_CMD_MKENT(unicode, CONFIG_SYS_MAXARGS, 1, do_ut_unicode, "", ""),
  54. #endif
  55. #ifdef CONFIG_SANDBOX
  56. U_BOOT_CMD_MKENT(compression, CONFIG_SYS_MAXARGS, 1, do_ut_compression,
  57. "", ""),
  58. U_BOOT_CMD_MKENT(bloblist, CONFIG_SYS_MAXARGS, 1, do_ut_bloblist,
  59. "", ""),
  60. U_BOOT_CMD_MKENT(bootm, CONFIG_SYS_MAXARGS, 1, do_ut_bootm, "", ""),
  61. #endif
  62. U_BOOT_CMD_MKENT(str, CONFIG_SYS_MAXARGS, 1, do_ut_str, "", ""),
  63. #ifdef CONFIG_CMD_ADDRMAP
  64. U_BOOT_CMD_MKENT(addrmap, CONFIG_SYS_MAXARGS, 1, do_ut_addrmap, "", ""),
  65. #endif
  66. };
  67. static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
  68. char *const argv[])
  69. {
  70. int i;
  71. int retval;
  72. int any_fail = 0;
  73. for (i = 1; i < ARRAY_SIZE(cmd_ut_sub); i++) {
  74. printf("----Running %s tests----\n", cmd_ut_sub[i].name);
  75. retval = cmd_ut_sub[i].cmd(cmdtp, flag, 1, &cmd_ut_sub[i].name);
  76. if (!any_fail)
  77. any_fail = retval;
  78. }
  79. return any_fail;
  80. }
  81. static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  82. {
  83. struct cmd_tbl *cp;
  84. if (argc < 2)
  85. return CMD_RET_USAGE;
  86. /* drop initial "ut" arg */
  87. argc--;
  88. argv++;
  89. cp = find_cmd_tbl(argv[0], cmd_ut_sub, ARRAY_SIZE(cmd_ut_sub));
  90. if (cp)
  91. return cp->cmd(cmdtp, flag, argc, argv);
  92. return CMD_RET_USAGE;
  93. }
  94. #ifdef CONFIG_SYS_LONGHELP
  95. static char ut_help_text[] =
  96. "all - execute all enabled tests\n"
  97. #ifdef CONFIG_SANDBOX
  98. "ut bloblist - Test bloblist implementation\n"
  99. "ut compression - Test compressors and bootm decompression\n"
  100. #endif
  101. #ifdef CONFIG_UT_DM
  102. "ut dm [test-name]\n"
  103. #endif
  104. #ifdef CONFIG_UT_ENV
  105. "ut env [test-name]\n"
  106. #endif
  107. #ifdef CONFIG_UT_LIB
  108. "ut lib [test-name] - test library functions\n"
  109. #endif
  110. #ifdef CONFIG_UT_LOG
  111. "ut log [test-name] - test logging functions\n"
  112. #endif
  113. "ut mem [test-name] - test memory-related commands\n"
  114. #ifdef CONFIG_UT_OPTEE
  115. "ut optee [test-name]\n"
  116. #endif
  117. #ifdef CONFIG_UT_OVERLAY
  118. "ut overlay [test-name]\n"
  119. #endif
  120. "ut print [test-name] - test printing\n"
  121. "ut setexpr [test-name] - test setexpr command\n"
  122. #ifdef CONFIG_SANDBOX
  123. "ut str - Basic test of string functions\n"
  124. #endif
  125. #ifdef CONFIG_UT_TIME
  126. "ut time - Very basic test of time functions\n"
  127. #endif
  128. #if defined(CONFIG_UT_UNICODE) && \
  129. !defined(CONFIG_SPL_BUILD) && !defined(API_BUILD)
  130. "ut unicode [test-name] - test Unicode functions\n"
  131. #endif
  132. #ifdef CONFIG_CMD_ADDRMAP
  133. "ut addrmap - Very basic test of addrmap command\n"
  134. #endif
  135. ;
  136. #endif /* CONFIG_SYS_LONGHELP */
  137. U_BOOT_CMD(
  138. ut, CONFIG_SYS_MAXARGS, 1, do_ut,
  139. "unit tests", ut_help_text
  140. );