tests_helpers_compile.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8. #include <unistd.h>
  9. #include <limits.h>
  10. #include <errno.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <err.h>
  14. #include <string.h>
  15. #include <ctype.h>
  16. static const char *can_run(struct manifest *m)
  17. {
  18. if (safe_mode)
  19. return "Safe mode enabled";
  20. return NULL;
  21. }
  22. static bool compile(struct manifest *m,
  23. bool keep,
  24. struct ccan_file *cfile,
  25. char **output)
  26. {
  27. cfile->compiled = maybe_temp_file(m, ".o", keep, cfile->fullname);
  28. return compile_object(m, cfile->fullname, ccan_dir, compiler, cflags,
  29. cfile->compiled, output);
  30. }
  31. static void do_compile_test_helpers(struct manifest *m,
  32. bool keep,
  33. unsigned int *timeleft,
  34. struct score *score)
  35. {
  36. struct ccan_file *i;
  37. bool errors = false, warnings = false;
  38. if (list_empty(&m->other_test_c_files))
  39. score->total = 0;
  40. else
  41. score->total = 2;
  42. list_for_each(&m->other_test_c_files, i, list) {
  43. char *cmdout;
  44. if (!compile(m, keep, i, &cmdout)) {
  45. errors = true;
  46. score_file_error(score, i, 0, "Compile failed:\n%s",
  47. cmdout);
  48. } else if (!streq(cmdout, "")) {
  49. warnings = true;
  50. score_file_error(score, i, 0,
  51. "Compile gave warnings:\n%s", cmdout);
  52. }
  53. }
  54. if (!errors) {
  55. score->pass = true;
  56. score->score = score->total - warnings;
  57. }
  58. }
  59. struct ccanlint tests_helpers_compile = {
  60. .key = "tests_helpers_compile",
  61. .name = "Module test helper objects compile",
  62. .check = do_compile_test_helpers,
  63. .can_run = can_run,
  64. .needs = "depends_build tests_exist"
  65. };
  66. REGISTER_TEST(tests_helpers_compile);