tests_helpers_compile.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include <tools/ccanlint/ccanlint.h>
  2. #include <tools/tools.h>
  3. #include <ccan/str/str.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7. #include <unistd.h>
  8. #include <limits.h>
  9. #include <errno.h>
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <err.h>
  13. #include <string.h>
  14. #include <ctype.h>
  15. #include "reduce_features.h"
  16. static const char *can_run(struct manifest *m UNNEEDED)
  17. {
  18. if (safe_mode)
  19. return "Safe mode enabled";
  20. return NULL;
  21. }
  22. static bool compile(struct manifest *m,
  23. struct ccan_file *cfile,
  24. const char *flags,
  25. enum compile_type ctype,
  26. char **output)
  27. {
  28. cfile->compiled[ctype] = temp_file(m, ".o", cfile->fullname);
  29. return compile_object(m, cfile->fullname, ccan_dir, compiler, flags,
  30. cfile->compiled[ctype], output);
  31. }
  32. static void compile_test_helpers(struct manifest *m,
  33. unsigned int *timeleft UNNEEDED,
  34. struct score *score,
  35. const char *flags,
  36. enum compile_type ctype)
  37. {
  38. struct ccan_file *i;
  39. bool errors = false, warnings = false;
  40. if (list_empty(&m->other_test_c_files))
  41. score->total = 0;
  42. else
  43. score->total = 2;
  44. list_for_each(&m->other_test_c_files, i, list) {
  45. char *cmdout;
  46. if (!compile(m, i, flags, ctype, &cmdout)) {
  47. errors = true;
  48. score_file_error(score, i, 0, "Compile failed:\n%s",
  49. cmdout);
  50. } else if (!streq(cmdout, "")) {
  51. warnings = true;
  52. score_file_error(score, i, 0,
  53. "Compile gave warnings:\n%s", cmdout);
  54. }
  55. }
  56. if (!errors) {
  57. score->pass = true;
  58. score->score = score->total - warnings;
  59. }
  60. }
  61. static void do_compile_test_helpers(struct manifest *m,
  62. unsigned int *timeleft,
  63. struct score *score)
  64. {
  65. compile_test_helpers(m, timeleft, score, cflags, COMPILE_NORMAL);
  66. }
  67. struct ccanlint tests_helpers_compile = {
  68. .key = "tests_helpers_compile",
  69. .name = "Module test helper objects compile",
  70. .check = do_compile_test_helpers,
  71. .can_run = can_run,
  72. .needs = "depends_build tests_exist"
  73. };
  74. REGISTER_TEST(tests_helpers_compile);
  75. static const char *features_reduced(struct manifest *m UNNEEDED)
  76. {
  77. if (features_were_reduced)
  78. return NULL;
  79. return "No features to turn off";
  80. }
  81. static void do_compile_test_helpers_without_features(struct manifest *m,
  82. unsigned int *timeleft,
  83. struct score *score)
  84. {
  85. char *flags;
  86. flags = tal_fmt(score, "%s %s", cflags, REDUCE_FEATURES_FLAGS);
  87. compile_test_helpers(m, timeleft, score, flags, COMPILE_NOFEAT);
  88. }
  89. struct ccanlint tests_helpers_compile_without_features = {
  90. .key = "tests_helpers_compile_without_features",
  91. .name = "Module tests helpers compile (without features)",
  92. .check = do_compile_test_helpers_without_features,
  93. .can_run = features_reduced,
  94. .needs = "depends_build_without_features tests_exist"
  95. };
  96. REGISTER_TEST(tests_helpers_compile_without_features);