cmd_ut.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * (C) Copyright 2015
  3. * Joe Hershberger, National Instruments, joe.hershberger@ni.com
  4. *
  5. * SPDX-License-Identifier: GPL-2.0
  6. */
  7. #include <common.h>
  8. #include <command.h>
  9. #include <test/suites.h>
  10. #include <test/test.h>
  11. static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  12. int cmd_ut_category(const char *name, struct unit_test *tests, int n_ents,
  13. int argc, char * const argv[])
  14. {
  15. struct unit_test_state uts = { .fail_count = 0 };
  16. struct unit_test *test;
  17. if (argc == 1)
  18. printf("Running %d %s tests\n", n_ents, name);
  19. for (test = tests; test < tests + n_ents; test++) {
  20. if (argc > 1 && strcmp(argv[1], test->name))
  21. continue;
  22. printf("Test: %s\n", test->name);
  23. uts.start = mallinfo();
  24. test->func(&uts);
  25. }
  26. printf("Failures: %d\n", uts.fail_count);
  27. return uts.fail_count ? CMD_RET_FAILURE : 0;
  28. }
  29. static cmd_tbl_t cmd_ut_sub[] = {
  30. U_BOOT_CMD_MKENT(all, CONFIG_SYS_MAXARGS, 1, do_ut_all, "", ""),
  31. #if defined(CONFIG_UT_DM)
  32. U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""),
  33. #endif
  34. #if defined(CONFIG_UT_ENV)
  35. U_BOOT_CMD_MKENT(env, CONFIG_SYS_MAXARGS, 1, do_ut_env, "", ""),
  36. #endif
  37. #ifdef CONFIG_UT_OVERLAY
  38. U_BOOT_CMD_MKENT(overlay, CONFIG_SYS_MAXARGS, 1, do_ut_overlay, "", ""),
  39. #endif
  40. #ifdef CONFIG_UT_TIME
  41. U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
  42. #endif
  43. #ifdef CONFIG_SANDBOX
  44. U_BOOT_CMD_MKENT(compression, CONFIG_SYS_MAXARGS, 1, do_ut_compression,
  45. "", ""),
  46. #endif
  47. };
  48. static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  49. {
  50. int i;
  51. int retval;
  52. int any_fail = 0;
  53. for (i = 1; i < ARRAY_SIZE(cmd_ut_sub); i++) {
  54. printf("----Running %s tests----\n", cmd_ut_sub[i].name);
  55. retval = cmd_ut_sub[i].cmd(cmdtp, flag, 1, &cmd_ut_sub[i].name);
  56. if (!any_fail)
  57. any_fail = retval;
  58. }
  59. return any_fail;
  60. }
  61. static int do_ut(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  62. {
  63. cmd_tbl_t *cp;
  64. if (argc < 2)
  65. return CMD_RET_USAGE;
  66. /* drop initial "ut" arg */
  67. argc--;
  68. argv++;
  69. cp = find_cmd_tbl(argv[0], cmd_ut_sub, ARRAY_SIZE(cmd_ut_sub));
  70. if (cp)
  71. return cp->cmd(cmdtp, flag, argc, argv);
  72. return CMD_RET_USAGE;
  73. }
  74. #ifdef CONFIG_SYS_LONGHELP
  75. static char ut_help_text[] =
  76. "all - execute all enabled tests\n"
  77. #ifdef CONFIG_UT_DM
  78. "ut dm [test-name]\n"
  79. #endif
  80. #ifdef CONFIG_UT_ENV
  81. "ut env [test-name]\n"
  82. #endif
  83. #ifdef CONFIG_UT_OVERLAY
  84. "ut overlay [test-name]\n"
  85. #endif
  86. #ifdef CONFIG_UT_TIME
  87. "ut time - Very basic test of time functions\n"
  88. #endif
  89. #ifdef CONFIG_SANDBOX
  90. "ut compression - Test compressors and bootm decompression\n"
  91. #endif
  92. ;
  93. #endif
  94. U_BOOT_CMD(
  95. ut, CONFIG_SYS_MAXARGS, 1, do_ut,
  96. "unit tests", ut_help_text
  97. );