functional_test.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2010 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <grub/mm.h>
  19. #include <grub/misc.h>
  20. #include <grub/extcmd.h>
  21. #include <grub/test.h>
  22. #include <grub/dl.h>
  23. GRUB_MOD_LICENSE ("GPLv3+");
  24. static grub_err_t
  25. grub_functional_test (grub_extcmd_context_t ctxt __attribute__ ((unused)),
  26. int argc,
  27. char **args)
  28. {
  29. grub_test_t test;
  30. int ok = 1;
  31. int i;
  32. FOR_LIST_ELEMENTS (test, grub_test_list)
  33. {
  34. if (argc != 0)
  35. {
  36. for (i = 0; i < argc; i++)
  37. if (grub_strcmp(args[i], test->name) == 0)
  38. break;
  39. if (i == argc)
  40. continue;
  41. }
  42. grub_errno = 0;
  43. ok = ok && !grub_test_run (test);
  44. grub_errno = 0;
  45. }
  46. if (ok)
  47. grub_printf ("ALL TESTS PASSED\n");
  48. else
  49. grub_printf ("TEST FAILURE\n");
  50. return GRUB_ERR_NONE;
  51. }
  52. static grub_err_t
  53. grub_functional_all_tests (grub_extcmd_context_t ctxt __attribute__ ((unused)),
  54. int argc __attribute__ ((unused)),
  55. char **args __attribute__ ((unused)))
  56. {
  57. grub_test_t test;
  58. int ok = 1;
  59. grub_dl_load ("legacy_password_test");
  60. grub_errno = GRUB_ERR_NONE;
  61. grub_dl_load ("exfctest");
  62. grub_dl_load ("videotest_checksum");
  63. grub_dl_load ("gfxterm_menu");
  64. grub_dl_load ("setjmp_test");
  65. grub_dl_load ("cmdline_cat_test");
  66. grub_dl_load ("div_test");
  67. grub_dl_load ("xnu_uuid_test");
  68. grub_dl_load ("pbkdf2_test");
  69. grub_dl_load ("signature_test");
  70. grub_dl_load ("sleep_test");
  71. grub_dl_load ("bswap_test");
  72. grub_dl_load ("ctz_test");
  73. grub_dl_load ("cmp_test");
  74. grub_dl_load ("mul_test");
  75. grub_dl_load ("shift_test");
  76. grub_dl_load ("asn1_test");
  77. FOR_LIST_ELEMENTS (test, grub_test_list)
  78. ok = !grub_test_run (test) && ok;
  79. if (ok)
  80. grub_printf ("ALL TESTS PASSED\n");
  81. else
  82. grub_printf ("TEST FAILURE\n");
  83. return GRUB_ERR_NONE;
  84. }
  85. static grub_extcmd_t cmd;
  86. GRUB_MOD_INIT (functional_test)
  87. {
  88. cmd = grub_register_extcmd ("functional_test", grub_functional_test, 0, 0,
  89. "Run all loaded functional tests.", 0);
  90. cmd = grub_register_extcmd ("all_functional_test", grub_functional_all_tests, 0, 0,
  91. "Run all functional tests.", 0);
  92. }
  93. GRUB_MOD_FINI (functional_test)
  94. {
  95. grub_unregister_extcmd (cmd);
  96. }