ccanlint.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. /*
  2. * ccanlint: assorted checks and advice for a ccan package
  3. * Copyright (C) 2008 Rusty Russell, Idris Soule
  4. * Copyright (C) 2010 Rusty Russell, Idris Soule
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  13. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc., 51
  18. * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include "ccanlint.h"
  21. #include "../tools.h"
  22. #include <unistd.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <err.h>
  27. #include <ctype.h>
  28. #include <ccan/btree/btree.h>
  29. #include <ccan/str/str.h>
  30. #include <ccan/str_talloc/str_talloc.h>
  31. #include <ccan/talloc/talloc.h>
  32. #include <ccan/opt/opt.h>
  33. #include <ccan/foreach/foreach.h>
  34. #include <ccan/grab_file/grab_file.h>
  35. #include <ccan/cast/cast.h>
  36. int verbose = 0;
  37. static LIST_HEAD(compulsory_tests);
  38. static LIST_HEAD(normal_tests);
  39. static LIST_HEAD(finished_tests);
  40. bool safe_mode = false;
  41. static struct btree *cmdline_exclude;
  42. static struct btree *info_exclude;
  43. static unsigned int timeout;
  44. /* These are overridden at runtime if we can find config.h */
  45. const char *compiler = NULL;
  46. const char *cflags = NULL;
  47. const char *config_header;
  48. #if 0
  49. static void indent_print(const char *string)
  50. {
  51. while (*string) {
  52. unsigned int line = strcspn(string, "\n");
  53. printf("\t%.*s", line, string);
  54. if (string[line] == '\n') {
  55. printf("\n");
  56. line++;
  57. }
  58. string += line;
  59. }
  60. }
  61. #endif
  62. bool ask(const char *question)
  63. {
  64. char reply[80];
  65. printf("%s ", question);
  66. fflush(stdout);
  67. return fgets(reply, sizeof(reply), stdin) != NULL
  68. && toupper(reply[0]) == 'Y';
  69. }
  70. static const char *should_skip(struct manifest *m, struct ccanlint *i)
  71. {
  72. if (btree_lookup(cmdline_exclude, i->key))
  73. return "excluded on command line";
  74. if (btree_lookup(info_exclude, i->key))
  75. return "excluded in _info file";
  76. if (i->skip)
  77. return i->skip;
  78. if (i->skip_fail)
  79. return "dependency failed";
  80. if (i->can_run)
  81. return i->can_run(m);
  82. return NULL;
  83. }
  84. static bool run_test(struct ccanlint *i,
  85. bool quiet,
  86. unsigned int *running_score,
  87. unsigned int *running_total,
  88. struct manifest *m)
  89. {
  90. unsigned int timeleft;
  91. const struct dependent *d;
  92. const char *skip;
  93. struct score *score;
  94. //one less test to run through
  95. list_for_each(&i->dependencies, d, node)
  96. d->dependent->num_depends--;
  97. score = talloc(m, struct score);
  98. list_head_init(&score->per_file_errors);
  99. score->error = NULL;
  100. score->pass = false;
  101. score->score = 0;
  102. score->total = 1;
  103. skip = should_skip(m, i);
  104. if (skip) {
  105. skip:
  106. if (verbose && !streq(skip, "not relevant to target"))
  107. printf("%s: skipped (%s)\n", i->name, skip);
  108. /* If we're skipping this because a prereq failed, we fail:
  109. * count it as a score of 1. */
  110. if (i->skip_fail)
  111. (*running_total)++;
  112. list_del(&i->list);
  113. list_add_tail(&finished_tests, &i->list);
  114. list_for_each(&i->dependencies, d, node) {
  115. if (d->dependent->skip)
  116. continue;
  117. d->dependent->skip = "dependency was skipped";
  118. d->dependent->skip_fail = i->skip_fail;
  119. }
  120. return i->skip_fail ? false : true;
  121. }
  122. timeleft = timeout ? timeout : default_timeout_ms;
  123. i->check(m, i->keep_results, &timeleft, score);
  124. if (timeout && timeleft == 0) {
  125. skip = "timeout";
  126. goto skip;
  127. }
  128. assert(score->score <= score->total);
  129. if ((!score->pass && !quiet)
  130. || (score->score < score->total && verbose)
  131. || verbose > 1) {
  132. printf("%s (%s): %s", i->name, i->key, score->pass ? "PASS" : "FAIL");
  133. if (score->total > 1)
  134. printf(" (+%u/%u)", score->score, score->total);
  135. printf("\n");
  136. }
  137. if ((!quiet && !score->pass) || verbose) {
  138. if (score->error) {
  139. printf("%s%s", score->error,
  140. strends(score->error, "\n") ? "" : "\n");
  141. }
  142. }
  143. if (!quiet && score->score < score->total && i->handle)
  144. i->handle(m, score);
  145. *running_score += score->score;
  146. *running_total += score->total;
  147. list_del(&i->list);
  148. list_add_tail(&finished_tests, &i->list);
  149. if (!score->pass) {
  150. /* Skip any tests which depend on this one. */
  151. list_for_each(&i->dependencies, d, node) {
  152. if (d->dependent->skip)
  153. continue;
  154. d->dependent->skip = "dependency failed";
  155. d->dependent->skip_fail = true;
  156. }
  157. }
  158. return score->pass;
  159. }
  160. static void register_test(struct list_head *h, struct ccanlint *test)
  161. {
  162. list_add(h, &test->list);
  163. test->options = talloc_array(NULL, char *, 1);
  164. test->options[0] = NULL;
  165. }
  166. /**
  167. * get_next_test - retrieves the next test to be processed
  168. **/
  169. static inline struct ccanlint *get_next_test(struct list_head *test)
  170. {
  171. struct ccanlint *i;
  172. if (list_empty(test))
  173. return NULL;
  174. list_for_each(test, i, list) {
  175. if (i->num_depends == 0)
  176. return i;
  177. }
  178. errx(1, "Can't make process; test dependency cycle");
  179. }
  180. static struct ccanlint *find_test(const char *key)
  181. {
  182. struct ccanlint *i;
  183. list_for_each(&compulsory_tests, i, list)
  184. if (streq(i->key, key))
  185. return i;
  186. list_for_each(&normal_tests, i, list)
  187. if (streq(i->key, key))
  188. return i;
  189. return NULL;
  190. }
  191. bool is_excluded(const char *name)
  192. {
  193. return btree_lookup(cmdline_exclude, name) != NULL
  194. || btree_lookup(info_exclude, name) != NULL
  195. || find_test(name)->skip != NULL;
  196. }
  197. #undef REGISTER_TEST
  198. #define REGISTER_TEST(name, ...) extern struct ccanlint name
  199. #include "generated-normal-tests"
  200. #include "generated-compulsory-tests"
  201. static void init_tests(void)
  202. {
  203. struct ccanlint *c;
  204. struct btree *keys, *names;
  205. struct list_head *list;
  206. #undef REGISTER_TEST
  207. #define REGISTER_TEST(name) register_test(&normal_tests, &name)
  208. #include "generated-normal-tests"
  209. #undef REGISTER_TEST
  210. #define REGISTER_TEST(name) register_test(&compulsory_tests, &name)
  211. #include "generated-compulsory-tests"
  212. /* Initialize dependency lists. */
  213. foreach_ptr(list, &compulsory_tests, &normal_tests) {
  214. list_for_each(list, c, list) {
  215. list_head_init(&c->dependencies);
  216. }
  217. }
  218. /* Resolve dependencies. */
  219. foreach_ptr(list, &compulsory_tests, &normal_tests) {
  220. list_for_each(list, c, list) {
  221. char **deps = strsplit(NULL, c->needs, " ");
  222. unsigned int i;
  223. for (i = 0; deps[i]; i++) {
  224. struct ccanlint *dep;
  225. struct dependent *dchild;
  226. dep = find_test(deps[i]);
  227. if (!dep)
  228. errx(1, "BUG: unknown dep '%s' for %s",
  229. deps[i], c->key);
  230. dchild = talloc(NULL, struct dependent);
  231. dchild->dependent = c;
  232. list_add_tail(&dep->dependencies,
  233. &dchild->node);
  234. c->num_depends++;
  235. }
  236. talloc_free(deps);
  237. }
  238. }
  239. /* Self-consistency check: make sure no two tests
  240. have the same key or name. */
  241. keys = btree_new(btree_strcmp);
  242. names = btree_new(btree_strcmp);
  243. foreach_ptr(list, &compulsory_tests, &normal_tests) {
  244. list_for_each(list, c, list) {
  245. if (!btree_insert(keys, c->key))
  246. errx(1, "BUG: Duplicate test key '%s'",
  247. c->key);
  248. if (!btree_insert(names, c->name))
  249. errx(1, "BUG: Duplicate test name '%s'",
  250. c->name);
  251. }
  252. }
  253. btree_delete(keys);
  254. btree_delete(names);
  255. }
  256. static void print_test_depends(void)
  257. {
  258. struct list_head *list;
  259. foreach_ptr(list, &compulsory_tests, &normal_tests) {
  260. struct ccanlint *c;
  261. printf("\%s Tests\n",
  262. list == &compulsory_tests ? "Compulsory" : "Normal");
  263. list_for_each(list, c, list) {
  264. if (!list_empty(&c->dependencies)) {
  265. const struct dependent *d;
  266. printf("These depend on %s:\n", c->key);
  267. list_for_each(&c->dependencies, d, node)
  268. printf("\t%s\n", d->dependent->key);
  269. }
  270. }
  271. }
  272. }
  273. static int show_tmpdir(const char *dir)
  274. {
  275. printf("You can find ccanlint working files in '%s'\n", dir);
  276. return 0;
  277. }
  278. static char *keep_test(const char *testname, void *unused)
  279. {
  280. struct ccanlint *i;
  281. if (streq(testname, "all")) {
  282. struct list_head *list;
  283. foreach_ptr(list, &compulsory_tests, &normal_tests) {
  284. list_for_each(list, i, list)
  285. i->keep_results = true;
  286. }
  287. } else {
  288. i = find_test(testname);
  289. if (!i)
  290. errx(1, "No test %s to --keep", testname);
  291. i->keep_results = true;
  292. }
  293. /* Don't automatically destroy temporary dir. */
  294. talloc_set_destructor(temp_dir(NULL), show_tmpdir);
  295. return NULL;
  296. }
  297. static char *skip_test(const char *testname, void *unused)
  298. {
  299. btree_insert(cmdline_exclude, testname);
  300. return NULL;
  301. }
  302. static void print_tests(struct list_head *tests, const char *type)
  303. {
  304. struct ccanlint *i;
  305. printf("%s tests:\n", type);
  306. /* This makes them print in topological order. */
  307. while ((i = get_next_test(tests)) != NULL) {
  308. const struct dependent *d;
  309. printf(" %-25s %s\n", i->key, i->name);
  310. list_del(&i->list);
  311. list_for_each(&i->dependencies, d, node)
  312. d->dependent->num_depends--;
  313. }
  314. }
  315. static char *list_tests(void *arg)
  316. {
  317. print_tests(&compulsory_tests, "Compulsory");
  318. print_tests(&normal_tests, "Normal");
  319. exit(0);
  320. }
  321. static void test_dgraph_vertices(struct list_head *tests, const char *style)
  322. {
  323. const struct ccanlint *i;
  324. list_for_each(tests, i, list) {
  325. /*
  326. * todo: escape labels in case ccanlint test keys have
  327. * characters interpreted as GraphViz syntax.
  328. */
  329. printf("\t\"%p\" [label=\"%s\"%s]\n", i, i->key, style);
  330. }
  331. }
  332. static void test_dgraph_edges(struct list_head *tests)
  333. {
  334. const struct ccanlint *i;
  335. const struct dependent *d;
  336. list_for_each(tests, i, list)
  337. list_for_each(&i->dependencies, d, node)
  338. printf("\t\"%p\" -> \"%p\"\n", d->dependent, i);
  339. }
  340. static char *test_dependency_graph(void *arg)
  341. {
  342. puts("digraph G {");
  343. test_dgraph_vertices(&compulsory_tests, ", style=filled, fillcolor=yellow");
  344. test_dgraph_vertices(&normal_tests, "");
  345. test_dgraph_edges(&compulsory_tests);
  346. test_dgraph_edges(&normal_tests);
  347. puts("}");
  348. exit(0);
  349. }
  350. /* Remove empty lines. */
  351. static char **collapse(char **lines, unsigned int *nump)
  352. {
  353. unsigned int i, j;
  354. for (i = j = 0; lines[i]; i++) {
  355. if (lines[i][0])
  356. lines[j++] = lines[i];
  357. }
  358. lines[j] = NULL;
  359. if (nump)
  360. *nump = j;
  361. return lines;
  362. }
  363. static void add_options(struct ccanlint *test, char **options,
  364. unsigned int num_options)
  365. {
  366. unsigned int num;
  367. if (!test->options)
  368. num = 0;
  369. else
  370. /* -1, because last one is NULL. */
  371. num = talloc_array_length(test->options) - 1;
  372. test->options = talloc_realloc(NULL, test->options,
  373. char *,
  374. num + num_options + 1);
  375. memcpy(&test->options[num], options, (num_options + 1)*sizeof(char *));
  376. }
  377. static void add_info_options(struct ccan_file *info, bool mark_fails)
  378. {
  379. struct doc_section *d;
  380. unsigned int i;
  381. struct ccanlint *test;
  382. list_for_each(get_ccan_file_docs(info), d, list) {
  383. if (!streq(d->type, "ccanlint"))
  384. continue;
  385. for (i = 0; i < d->num_lines; i++) {
  386. unsigned int num_words;
  387. char **words = collapse(strsplit(d, d->lines[i], " \t"),
  388. &num_words);
  389. if (num_words == 0)
  390. continue;
  391. if (strncmp(words[0], "//", 2) == 0)
  392. continue;
  393. test = find_test(words[0]);
  394. if (!test) {
  395. warnx("%s: unknown ccanlint test '%s'",
  396. info->fullname, words[0]);
  397. continue;
  398. }
  399. if (!words[1]) {
  400. warnx("%s: no argument to test '%s'",
  401. info->fullname, words[0]);
  402. continue;
  403. }
  404. /* Known failure? */
  405. if (strcasecmp(words[1], "FAIL") == 0) {
  406. if (mark_fails)
  407. btree_insert(info_exclude, words[0]);
  408. } else {
  409. if (!test->takes_options)
  410. warnx("%s: %s doesn't take options",
  411. info->fullname, words[0]);
  412. add_options(test, words+1, num_words-1);
  413. }
  414. }
  415. }
  416. }
  417. /* If options are of form "filename:<option>" they only apply to that file */
  418. char **per_file_options(const struct ccanlint *test, struct ccan_file *f)
  419. {
  420. char **ret;
  421. unsigned int i, j = 0;
  422. /* Fast path. */
  423. if (!test->options[0])
  424. return test->options;
  425. ret = talloc_array(f, char *, talloc_array_length(test->options));
  426. for (i = 0; test->options[i]; i++) {
  427. char *optname;
  428. if (!test->options[i] || !strchr(test->options[i], ':')) {
  429. optname = test->options[i];
  430. } else if (strstarts(test->options[i], f->name)
  431. && test->options[i][strlen(f->name)] == ':') {
  432. optname = test->options[i] + strlen(f->name) + 1;
  433. } else
  434. continue;
  435. /* FAIL overrides anything else. */
  436. if (streq(optname, "FAIL")) {
  437. ret = talloc_array(f, char *, 2);
  438. ret[0] = (char *)"FAIL";
  439. ret[1] = NULL;
  440. return ret;
  441. }
  442. ret[j++] = optname;
  443. }
  444. ret[j] = NULL;
  445. /* Shrink it to size so talloc_array_length() works as expected. */
  446. return talloc_realloc(NULL, ret, char *, j + 1);
  447. }
  448. static bool depends_on(struct ccanlint *i, struct ccanlint *target)
  449. {
  450. const struct dependent *d;
  451. if (i == target)
  452. return true;
  453. list_for_each(&i->dependencies, d, node) {
  454. if (depends_on(d->dependent, target))
  455. return true;
  456. }
  457. return false;
  458. }
  459. /* O(N^2), who cares? */
  460. static void skip_unrelated_tests(struct ccanlint *target)
  461. {
  462. struct ccanlint *i;
  463. struct list_head *list;
  464. foreach_ptr(list, &compulsory_tests, &normal_tests)
  465. list_for_each(list, i, list)
  466. if (!depends_on(i, target))
  467. i->skip = "not relevant to target";
  468. }
  469. static char *demangle_string(char *string)
  470. {
  471. unsigned int i;
  472. const char mapfrom[] = "abfnrtv";
  473. const char mapto[] = "\a\b\f\n\r\t\v";
  474. if (!strchr(string, '"'))
  475. return NULL;
  476. string = strchr(string, '"') + 1;
  477. if (!strrchr(string, '"'))
  478. return NULL;
  479. *strrchr(string, '"') = '\0';
  480. for (i = 0; i < strlen(string); i++) {
  481. if (string[i] == '\\') {
  482. char repl;
  483. unsigned len = 0;
  484. const char *p = strchr(mapfrom, string[i+1]);
  485. if (p) {
  486. repl = mapto[p - mapfrom];
  487. len = 1;
  488. } else if (strlen(string+i+1) >= 3) {
  489. if (string[i+1] == 'x') {
  490. repl = (string[i+2]-'0')*16
  491. + string[i+3]-'0';
  492. len = 3;
  493. } else if (cisdigit(string[i+1])) {
  494. repl = (string[i+2]-'0')*8*8
  495. + (string[i+3]-'0')*8
  496. + (string[i+4]-'0');
  497. len = 3;
  498. }
  499. }
  500. if (len == 0) {
  501. repl = string[i+1];
  502. len = 1;
  503. }
  504. string[i] = repl;
  505. memmove(string + i + 1, string + i + len + 1,
  506. strlen(string + i + len + 1) + 1);
  507. }
  508. }
  509. return string;
  510. }
  511. static void read_config_header(void)
  512. {
  513. char *fname = talloc_asprintf(NULL, "%s/config.h", ccan_dir);
  514. char **lines;
  515. unsigned int i;
  516. config_header = grab_file(NULL, fname, NULL);
  517. if (!config_header) {
  518. talloc_free(fname);
  519. return;
  520. }
  521. lines = strsplit(config_header, config_header, "\n");
  522. for (i = 0; i < talloc_array_length(lines) - 1; i++) {
  523. char *sym;
  524. const char **line = (const char **)&lines[i];
  525. if (!get_token(line, "#"))
  526. continue;
  527. if (!get_token(line, "define"))
  528. continue;
  529. sym = get_symbol_token(lines, line);
  530. if (streq(sym, "CCAN_COMPILER") && !compiler) {
  531. compiler = demangle_string(lines[i]);
  532. if (!compiler)
  533. errx(1, "%s:%u:could not parse CCAN_COMPILER",
  534. fname, i+1);
  535. if (verbose > 1)
  536. printf("%s: compiler set to '%s'\n",
  537. fname, compiler);
  538. } else if (streq(sym, "CCAN_CFLAGS") && !cflags) {
  539. cflags = demangle_string(lines[i]);
  540. if (!cflags)
  541. errx(1, "%s:%u:could not parse CCAN_CFLAGS",
  542. fname, i+1);
  543. if (verbose > 1)
  544. printf("%s: compiler flags set to '%s'\n",
  545. fname, cflags);
  546. }
  547. }
  548. if (!compiler)
  549. compiler = CCAN_COMPILER;
  550. if (!cflags)
  551. compiler = CCAN_CFLAGS;
  552. }
  553. static char *opt_set_const_charp(const char *arg, const char **p)
  554. {
  555. return opt_set_charp(arg, cast_const2(char **, p));
  556. }
  557. int main(int argc, char *argv[])
  558. {
  559. bool summary = false, pass = true;
  560. unsigned int score = 0, total_score = 0;
  561. struct manifest *m;
  562. struct ccanlint *i;
  563. const char *prefix = "";
  564. char *dir = talloc_getcwd(NULL), *base_dir = dir, *target = NULL;
  565. init_tests();
  566. cmdline_exclude = btree_new(btree_strcmp);
  567. info_exclude = btree_new(btree_strcmp);
  568. opt_register_arg("--dir|-d", opt_set_charp, opt_show_charp, &dir,
  569. "use this directory");
  570. opt_register_noarg("-n|--safe-mode", opt_set_bool, &safe_mode,
  571. "do not compile anything");
  572. opt_register_noarg("-l|--list-tests", list_tests, NULL,
  573. "list tests ccanlint performs (and exit)");
  574. opt_register_noarg("--test-dep-graph", test_dependency_graph, NULL,
  575. "print dependency graph of tests in Graphviz .dot format");
  576. opt_register_arg("-k|--keep <testname>", keep_test, NULL, NULL,
  577. "keep results of <testname>"
  578. " (can be used multiple times, or 'all')");
  579. opt_register_noarg("--summary|-s", opt_set_bool, &summary,
  580. "simply give one line summary");
  581. opt_register_noarg("--verbose|-v", opt_inc_intval, &verbose,
  582. "verbose mode (up to -vvvv)");
  583. opt_register_arg("-x|--exclude <testname>", skip_test, NULL, NULL,
  584. "exclude <testname> (can be used multiple times)");
  585. opt_register_arg("-t|--timeout <milleseconds>", opt_set_uintval,
  586. NULL, &timeout,
  587. "ignore (terminate) tests that are slower than this");
  588. opt_register_arg("--target <testname>", opt_set_charp,
  589. NULL, &target,
  590. "only run one test (and its prerequisites)");
  591. opt_register_arg("--compiler <compiler>", opt_set_const_charp,
  592. NULL, &compiler, "set the compiler");
  593. opt_register_arg("--cflags <flags>", opt_set_const_charp,
  594. NULL, &cflags, "set the compiler flags");
  595. opt_register_noarg("-?|-h|--help", opt_usage_and_exit,
  596. "\nA program for checking and guiding development"
  597. " of CCAN modules.",
  598. "This usage message");
  599. /* We move into temporary directory, so gcov dumps its files there. */
  600. if (chdir(temp_dir(talloc_autofree_context())) != 0)
  601. err(1, "Error changing to %s temporary dir", temp_dir(NULL));
  602. opt_parse(&argc, argv, opt_log_stderr_exit);
  603. if (dir[0] != '/')
  604. dir = talloc_asprintf_append(NULL, "%s/%s", base_dir, dir);
  605. while (strends(dir, "/"))
  606. dir[strlen(dir)-1] = '\0';
  607. if (dir != base_dir)
  608. prefix = talloc_append_string(talloc_basename(NULL, dir), ": ");
  609. if (verbose >= 3) {
  610. compile_verbose = true;
  611. print_test_depends();
  612. }
  613. if (verbose >= 4)
  614. tools_verbose = true;
  615. m = get_manifest(talloc_autofree_context(), dir);
  616. read_config_header();
  617. /* Create a symlink from temp dir back to src dir's test directory. */
  618. if (symlink(talloc_asprintf(m, "%s/test", dir),
  619. talloc_asprintf(m, "%s/test", temp_dir(NULL))) != 0)
  620. err(1, "Creating test symlink in %s", temp_dir(NULL));
  621. if (target) {
  622. struct ccanlint *test;
  623. test = find_test(target);
  624. if (!test)
  625. errx(1, "Unknown test to run '%s'", target);
  626. skip_unrelated_tests(test);
  627. }
  628. /* If you don't pass the compulsory tests, you get a score of 0. */
  629. while ((i = get_next_test(&compulsory_tests)) != NULL) {
  630. if (!run_test(i, summary, &score, &total_score, m)) {
  631. printf("%sTotal score: 0/%u\n", prefix, total_score);
  632. errx(1, "%s%s failed", prefix, i->name);
  633. }
  634. }
  635. /* --target overrides known FAIL from _info */
  636. if (m->info_file)
  637. add_info_options(m->info_file, !target);
  638. while ((i = get_next_test(&normal_tests)) != NULL)
  639. pass &= run_test(i, summary, &score, &total_score, m);
  640. printf("%sTotal score: %u/%u\n", prefix, score, total_score);
  641. return pass ? 0 : 1;
  642. }