cmd_ut.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  11. static cmd_tbl_t cmd_ut_sub[] = {
  12. U_BOOT_CMD_MKENT(all, CONFIG_SYS_MAXARGS, 1, do_ut_all, "", ""),
  13. #if defined(CONFIG_UT_DM)
  14. U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""),
  15. #endif
  16. #if defined(CONFIG_UT_ENV)
  17. U_BOOT_CMD_MKENT(env, CONFIG_SYS_MAXARGS, 1, do_ut_env, "", ""),
  18. #endif
  19. #ifdef CONFIG_UT_TIME
  20. U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
  21. #endif
  22. };
  23. static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  24. {
  25. int i;
  26. int retval;
  27. int any_fail = 0;
  28. for (i = 1; i < ARRAY_SIZE(cmd_ut_sub); i++) {
  29. printf("----Running %s tests----\n", cmd_ut_sub[i].name);
  30. retval = cmd_ut_sub[i].cmd(cmdtp, flag, 1, &cmd_ut_sub[i].name);
  31. if (!any_fail)
  32. any_fail = retval;
  33. }
  34. return any_fail;
  35. }
  36. static int do_ut(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  37. {
  38. cmd_tbl_t *cp;
  39. if (argc < 2)
  40. return CMD_RET_USAGE;
  41. /* drop initial "ut" arg */
  42. argc--;
  43. argv++;
  44. cp = find_cmd_tbl(argv[0], cmd_ut_sub, ARRAY_SIZE(cmd_ut_sub));
  45. if (cp)
  46. return cp->cmd(cmdtp, flag, argc, argv);
  47. return CMD_RET_USAGE;
  48. }
  49. #ifdef CONFIG_SYS_LONGHELP
  50. static char ut_help_text[] =
  51. "all - execute all enabled tests\n"
  52. #ifdef CONFIG_UT_DM
  53. "ut dm [test-name]\n"
  54. #endif
  55. #ifdef CONFIG_UT_ENV
  56. "ut env [test-name]\n"
  57. #endif
  58. #ifdef CONFIG_UT_TIME
  59. "ut time - Very basic test of time functions\n"
  60. #endif
  61. ;
  62. #endif
  63. U_BOOT_CMD(
  64. ut, CONFIG_SYS_MAXARGS, 1, do_ut,
  65. "unit tests", ut_help_text
  66. );