cmd_ut.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 <test/suites.h>
  9. #include <test/test.h>
  10. static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  11. int cmd_ut_category(const char *name, struct unit_test *tests, int n_ents,
  12. int argc, char * const argv[])
  13. {
  14. struct unit_test_state uts = { .fail_count = 0 };
  15. struct unit_test *test;
  16. if (argc == 1)
  17. printf("Running %d %s tests\n", n_ents, name);
  18. for (test = tests; test < tests + n_ents; test++) {
  19. if (argc > 1 && strcmp(argv[1], test->name))
  20. continue;
  21. printf("Test: %s\n", test->name);
  22. uts.start = mallinfo();
  23. test->func(&uts);
  24. }
  25. printf("Failures: %d\n", uts.fail_count);
  26. return uts.fail_count ? CMD_RET_FAILURE : 0;
  27. }
  28. static cmd_tbl_t cmd_ut_sub[] = {
  29. U_BOOT_CMD_MKENT(all, CONFIG_SYS_MAXARGS, 1, do_ut_all, "", ""),
  30. #if defined(CONFIG_UT_DM)
  31. U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""),
  32. #endif
  33. #if defined(CONFIG_UT_ENV)
  34. U_BOOT_CMD_MKENT(env, CONFIG_SYS_MAXARGS, 1, do_ut_env, "", ""),
  35. #endif
  36. #ifdef CONFIG_UT_OVERLAY
  37. U_BOOT_CMD_MKENT(overlay, CONFIG_SYS_MAXARGS, 1, do_ut_overlay, "", ""),
  38. #endif
  39. #ifdef CONFIG_UT_LIB
  40. U_BOOT_CMD_MKENT(lib, CONFIG_SYS_MAXARGS, 1, do_ut_lib, "", ""),
  41. #endif
  42. #ifdef CONFIG_UT_TIME
  43. U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
  44. #endif
  45. #if CONFIG_IS_ENABLED(UT_UNICODE) && !defined(API_BUILD)
  46. U_BOOT_CMD_MKENT(unicode, CONFIG_SYS_MAXARGS, 1, do_ut_unicode, "", ""),
  47. #endif
  48. #ifdef CONFIG_SANDBOX
  49. U_BOOT_CMD_MKENT(compression, CONFIG_SYS_MAXARGS, 1, do_ut_compression,
  50. "", ""),
  51. U_BOOT_CMD_MKENT(bloblist, CONFIG_SYS_MAXARGS, 1, do_ut_bloblist,
  52. "", ""),
  53. #endif
  54. };
  55. static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  56. {
  57. int i;
  58. int retval;
  59. int any_fail = 0;
  60. for (i = 1; i < ARRAY_SIZE(cmd_ut_sub); i++) {
  61. printf("----Running %s tests----\n", cmd_ut_sub[i].name);
  62. retval = cmd_ut_sub[i].cmd(cmdtp, flag, 1, &cmd_ut_sub[i].name);
  63. if (!any_fail)
  64. any_fail = retval;
  65. }
  66. return any_fail;
  67. }
  68. static int do_ut(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  69. {
  70. cmd_tbl_t *cp;
  71. if (argc < 2)
  72. return CMD_RET_USAGE;
  73. /* drop initial "ut" arg */
  74. argc--;
  75. argv++;
  76. cp = find_cmd_tbl(argv[0], cmd_ut_sub, ARRAY_SIZE(cmd_ut_sub));
  77. if (cp)
  78. return cp->cmd(cmdtp, flag, argc, argv);
  79. return CMD_RET_USAGE;
  80. }
  81. #ifdef CONFIG_SYS_LONGHELP
  82. static char ut_help_text[] =
  83. "all - execute all enabled tests\n"
  84. #ifdef CONFIG_SANDBOX
  85. "ut bloblist - Test bloblist implementation\n"
  86. "ut compression - Test compressors and bootm decompression\n"
  87. #endif
  88. #ifdef CONFIG_UT_DM
  89. "ut dm [test-name]\n"
  90. #endif
  91. #ifdef CONFIG_UT_ENV
  92. "ut env [test-name]\n"
  93. #endif
  94. #ifdef CONFIG_UT_LIB
  95. "ut lib [test-name] - test library functions\n"
  96. #endif
  97. #ifdef CONFIG_UT_OVERLAY
  98. "ut overlay [test-name]\n"
  99. #endif
  100. #ifdef CONFIG_UT_TIME
  101. "ut time - Very basic test of time functions\n"
  102. #endif
  103. #if defined(CONFIG_UT_UNICODE) && \
  104. !defined(CONFIG_SPL_BUILD) && !defined(API_BUILD)
  105. "ut unicode [test-name] - test Unicode functions\n"
  106. #endif
  107. ;
  108. #endif /* CONFIG_SYS_LONGHELP */
  109. U_BOOT_CMD(
  110. ut, CONFIG_SYS_MAXARGS, 1, do_ut,
  111. "unit tests", ut_help_text
  112. );