tests_pass.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include <tools/ccanlint/ccanlint.h>
  2. #include <tools/tools.h>
  3. #include <ccan/talloc/talloc.h>
  4. #include <ccan/str/str.h>
  5. #include <ccan/foreach/foreach.h>
  6. #include <sys/types.h>
  7. #include <sys/stat.h>
  8. #include <fcntl.h>
  9. #include <unistd.h>
  10. #include <limits.h>
  11. #include <errno.h>
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14. #include <err.h>
  15. #include <string.h>
  16. #include <ctype.h>
  17. static const char *can_run(struct manifest *m)
  18. {
  19. if (safe_mode)
  20. return "Safe mode enabled";
  21. return NULL;
  22. }
  23. static void do_run_tests(struct manifest *m,
  24. bool keep,
  25. unsigned int *timeleft,
  26. struct score *score)
  27. {
  28. struct list_head *list;
  29. struct ccan_file *i;
  30. char *cmdout;
  31. score->total = 0;
  32. foreach_ptr(list, &m->run_tests, &m->api_tests) {
  33. list_for_each(list, i, list) {
  34. score->total++;
  35. if (run_command(m, timeleft, &cmdout, "%s",
  36. i->compiled))
  37. score->score++;
  38. else
  39. score_file_error(score, i, 0, "%s", cmdout);
  40. }
  41. }
  42. if (score->score == score->total)
  43. score->pass = true;
  44. }
  45. /* Gcc's warn_unused_result is fascist bullshit. */
  46. #define doesnt_matter()
  47. static void run_under_debugger(struct manifest *m, struct score *score)
  48. {
  49. char *command;
  50. struct file_error *first;
  51. if (!ask("Should I run the first failing test under the debugger?"))
  52. return;
  53. first = list_top(&score->per_file_errors, struct file_error, list);
  54. command = talloc_asprintf(m, "gdb -ex 'break tap.c:136' -ex 'run' %s",
  55. first->file->compiled);
  56. if (system(command))
  57. doesnt_matter();
  58. }
  59. struct ccanlint tests_pass = {
  60. .key = "tests_pass",
  61. .name = "Module's run and api tests pass",
  62. .check = do_run_tests,
  63. .handle = run_under_debugger,
  64. .can_run = can_run,
  65. .needs = "tests_compile"
  66. };
  67. REGISTER_TEST(tests_pass);
  68. struct ccanlint tests_pass_without_features = {
  69. .key = "tests_pass_without_features",
  70. .name = "Module's run and api tests pass (without features)",
  71. .check = do_run_tests,
  72. .handle = run_under_debugger,
  73. .needs = "tests_pass reduce_features"
  74. };
  75. REGISTER_TEST(tests_pass_without_features);