tests_pass_without_features.c 1.8 KB

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