compile_test_helpers.c 1.6 KB

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