compile_test_helpers.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_build(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, "", 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. {
  34. char *cmdout = NULL;
  35. struct ccan_file *i;
  36. list_for_each(&m->other_test_c_files, i, list) {
  37. compile_tests.total_score++;
  38. cmdout = compile(m, keep, i);
  39. if (cmdout)
  40. return talloc_asprintf(m,
  41. "Failed to compile helper C"
  42. " code file %s:\n%s",
  43. i->name, cmdout);
  44. }
  45. return NULL;
  46. }
  47. static const char *describe_compile_test_helpers(struct manifest *m,
  48. void *check_result)
  49. {
  50. return check_result;
  51. }
  52. struct ccanlint compile_test_helpers = {
  53. .key = "compile-helpers",
  54. .name = "Module test helper objects compile",
  55. .total_score = 1,
  56. .check = do_compile_test_helpers,
  57. .describe = describe_compile_test_helpers,
  58. .can_run = can_build,
  59. };
  60. REGISTER_TEST(compile_test_helpers, &depends_built);