compile_test_helpers.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 char *compile(struct manifest *m,
  23. bool keep,
  24. struct ccan_file *cfile)
  25. {
  26. cfile->compiled = maybe_temp_file(m, ".o", keep, cfile->fullname);
  27. return compile_object(m, cfile->fullname, ccan_dir, "",
  28. cfile->compiled);
  29. }
  30. static void do_compile_test_helpers(struct manifest *m,
  31. bool keep,
  32. unsigned int *timeleft,
  33. struct score *score)
  34. {
  35. struct ccan_file *i;
  36. if (list_empty(&m->other_test_c_files))
  37. score->total = 0;
  38. list_for_each(&m->other_test_c_files, i, list) {
  39. char *cmdout = compile(m, keep, i);
  40. if (cmdout) {
  41. score->error = "Failed to compile helper C files";
  42. score_file_error(score, i, 0, cmdout);
  43. }
  44. }
  45. if (!score->error) {
  46. score->pass = true;
  47. score->score = score->total;
  48. }
  49. }
  50. struct ccanlint compile_test_helpers = {
  51. .key = "compile-helpers",
  52. .name = "Module test helper objects compile",
  53. .check = do_compile_test_helpers,
  54. .can_run = can_run,
  55. };
  56. REGISTER_TEST(compile_test_helpers, &depends_built, &has_tests, NULL);