tests_pass_without_features.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. /* We don't do these under valgrind: too slow! */
  18. static void do_run_tests_no_features(struct manifest *m,
  19. unsigned int *timeleft,
  20. struct score *score)
  21. {
  22. struct list_head *list;
  23. struct ccan_file *i;
  24. char *cmdout;
  25. score->total = 0;
  26. foreach_ptr(list, &m->run_tests, &m->api_tests) {
  27. list_for_each(list, i, list) {
  28. score->total++;
  29. if (verbose >= 2)
  30. printf(" %s\n", i->name);
  31. if (run_command(m, timeleft, &cmdout, "%s",
  32. i->compiled[COMPILE_NOFEAT]))
  33. score->score++;
  34. else
  35. score_file_error(score, i, 0, "%s", cmdout);
  36. }
  37. }
  38. if (score->score == score->total)
  39. score->pass = true;
  40. }
  41. /* Gcc's warn_unused_result is fascist bullshit. */
  42. #define doesnt_matter()
  43. static void run_under_debugger(struct manifest *m, struct score *score)
  44. {
  45. char *command;
  46. struct file_error *first;
  47. first = list_top(&score->per_file_errors, struct file_error, list);
  48. if (!ask("Should I run the first failing test under the debugger?"))
  49. return;
  50. command = talloc_asprintf(m, "gdb -ex 'break tap.c:139' -ex 'run' %s",
  51. first->file->compiled
  52. [COMPILE_NOFEAT]);
  53. if (system(command))
  54. doesnt_matter();
  55. }
  56. struct ccanlint tests_pass_without_features = {
  57. .key = "tests_pass_without_features",
  58. .name = "Module's run and api tests pass (without features)",
  59. .check = do_run_tests_no_features,
  60. .handle = run_under_debugger,
  61. .needs = "tests_compile_without_features"
  62. };
  63. REGISTER_TEST(tests_pass_without_features);