ccanlint.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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. #undef REGISTER_TEST
  192. #define REGISTER_TEST(name, ...) extern struct ccanlint name
  193. #include "generated-normal-tests"
  194. #include "generated-compulsory-tests"
  195. static void init_tests(void)
  196. {
  197. struct ccanlint *c;
  198. struct btree *keys, *names;
  199. struct list_head *list;
  200. #undef REGISTER_TEST
  201. #define REGISTER_TEST(name) register_test(&normal_tests, &name)
  202. #include "generated-normal-tests"
  203. #undef REGISTER_TEST
  204. #define REGISTER_TEST(name) register_test(&compulsory_tests, &name)
  205. #include "generated-compulsory-tests"
  206. /* Initialize dependency lists. */
  207. foreach_ptr(list, &compulsory_tests, &normal_tests) {
  208. list_for_each(list, c, list) {
  209. list_head_init(&c->dependencies);
  210. }
  211. }
  212. /* Resolve dependencies. */
  213. foreach_ptr(list, &compulsory_tests, &normal_tests) {
  214. list_for_each(list, c, list) {
  215. char **deps = strsplit(NULL, c->needs, " ");
  216. unsigned int i;
  217. for (i = 0; deps[i]; i++) {
  218. struct ccanlint *dep;
  219. struct dependent *dchild;
  220. dep = find_test(deps[i]);
  221. if (!dep)
  222. errx(1, "BUG: unknown dep '%s' for %s",
  223. deps[i], c->key);
  224. dchild = talloc(NULL, struct dependent);
  225. dchild->dependent = c;
  226. list_add_tail(&dep->dependencies,
  227. &dchild->node);
  228. c->num_depends++;
  229. }
  230. talloc_free(deps);
  231. }
  232. }
  233. /* Self-consistency check: make sure no two tests
  234. have the same key or name. */
  235. keys = btree_new(btree_strcmp);
  236. names = btree_new(btree_strcmp);
  237. foreach_ptr(list, &compulsory_tests, &normal_tests) {
  238. list_for_each(list, c, list) {
  239. if (!btree_insert(keys, c->key))
  240. errx(1, "BUG: Duplicate test key '%s'",
  241. c->key);
  242. if (!btree_insert(names, c->name))
  243. errx(1, "BUG: Duplicate test name '%s'",
  244. c->name);
  245. }
  246. }
  247. btree_delete(keys);
  248. btree_delete(names);
  249. }
  250. static void print_test_depends(void)
  251. {
  252. struct list_head *list;
  253. foreach_ptr(list, &compulsory_tests, &normal_tests) {
  254. struct ccanlint *c;
  255. printf("\%s Tests\n",
  256. list == &compulsory_tests ? "Compulsory" : "Normal");
  257. list_for_each(list, c, list) {
  258. if (!list_empty(&c->dependencies)) {
  259. const struct dependent *d;
  260. printf("These depend on %s:\n", c->key);
  261. list_for_each(&c->dependencies, d, node)
  262. printf("\t%s\n", d->dependent->key);
  263. }
  264. }
  265. }
  266. }
  267. static int show_tmpdir(const char *dir)
  268. {
  269. printf("You can find ccanlint working files in '%s'\n", dir);
  270. return 0;
  271. }
  272. static char *keep_test(const char *testname, void *unused)
  273. {
  274. struct ccanlint *i;
  275. if (streq(testname, "all")) {
  276. struct list_head *list;
  277. foreach_ptr(list, &compulsory_tests, &normal_tests) {
  278. list_for_each(list, i, list)
  279. i->keep_results = true;
  280. }
  281. } else {
  282. i = find_test(testname);
  283. if (!i)
  284. errx(1, "No test %s to --keep", testname);
  285. i->keep_results = true;
  286. }
  287. /* Don't automatically destroy temporary dir. */
  288. talloc_set_destructor(temp_dir(NULL), show_tmpdir);
  289. return NULL;
  290. }
  291. static char *skip_test(const char *testname, void *unused)
  292. {
  293. btree_insert(cmdline_exclude, testname);
  294. return NULL;
  295. }
  296. static void print_tests(struct list_head *tests, const char *type)
  297. {
  298. struct ccanlint *i;
  299. printf("%s tests:\n", type);
  300. /* This makes them print in topological order. */
  301. while ((i = get_next_test(tests)) != NULL) {
  302. const struct dependent *d;
  303. printf(" %-25s %s\n", i->key, i->name);
  304. list_del(&i->list);
  305. list_for_each(&i->dependencies, d, node)
  306. d->dependent->num_depends--;
  307. }
  308. }
  309. static char *list_tests(void *arg)
  310. {
  311. print_tests(&compulsory_tests, "Compulsory");
  312. print_tests(&normal_tests, "Normal");
  313. exit(0);
  314. }
  315. static void test_dgraph_vertices(struct list_head *tests, const char *style)
  316. {
  317. const struct ccanlint *i;
  318. list_for_each(tests, i, list) {
  319. /*
  320. * todo: escape labels in case ccanlint test keys have
  321. * characters interpreted as GraphViz syntax.
  322. */
  323. printf("\t\"%p\" [label=\"%s\"%s]\n", i, i->key, style);
  324. }
  325. }
  326. static void test_dgraph_edges(struct list_head *tests)
  327. {
  328. const struct ccanlint *i;
  329. const struct dependent *d;
  330. list_for_each(tests, i, list)
  331. list_for_each(&i->dependencies, d, node)
  332. printf("\t\"%p\" -> \"%p\"\n", d->dependent, i);
  333. }
  334. static char *test_dependency_graph(void *arg)
  335. {
  336. puts("digraph G {");
  337. test_dgraph_vertices(&compulsory_tests, ", style=filled, fillcolor=yellow");
  338. test_dgraph_vertices(&normal_tests, "");
  339. test_dgraph_edges(&compulsory_tests);
  340. test_dgraph_edges(&normal_tests);
  341. puts("}");
  342. exit(0);
  343. }
  344. /* Remove empty lines. */
  345. static char **collapse(char **lines, unsigned int *nump)
  346. {
  347. unsigned int i, j;
  348. for (i = j = 0; lines[i]; i++) {
  349. if (lines[i][0])
  350. lines[j++] = lines[i];
  351. }
  352. lines[j] = NULL;
  353. if (nump)
  354. *nump = j;
  355. return lines;
  356. }
  357. static void add_options(struct ccanlint *test, char **options,
  358. unsigned int num_options)
  359. {
  360. unsigned int num;
  361. if (!test->options)
  362. num = 0;
  363. else
  364. /* -1, because last one is NULL. */
  365. num = talloc_array_length(test->options) - 1;
  366. test->options = talloc_realloc(NULL, test->options,
  367. char *,
  368. num + num_options + 1);
  369. memcpy(&test->options[num], options, (num_options + 1)*sizeof(char *));
  370. }
  371. static void add_info_options(struct ccan_file *info, bool mark_fails)
  372. {
  373. struct doc_section *d;
  374. unsigned int i;
  375. struct ccanlint *test;
  376. list_for_each(get_ccan_file_docs(info), d, list) {
  377. if (!streq(d->type, "ccanlint"))
  378. continue;
  379. for (i = 0; i < d->num_lines; i++) {
  380. unsigned int num_words;
  381. char **words = collapse(strsplit(d, d->lines[i], " \t"),
  382. &num_words);
  383. if (num_words == 0)
  384. continue;
  385. if (strncmp(words[0], "//", 2) == 0)
  386. continue;
  387. test = find_test(words[0]);
  388. if (!test) {
  389. warnx("%s: unknown ccanlint test '%s'",
  390. info->fullname, words[0]);
  391. continue;
  392. }
  393. if (!words[1]) {
  394. warnx("%s: no argument to test '%s'",
  395. info->fullname, words[0]);
  396. continue;
  397. }
  398. /* Known failure? */
  399. if (strcasecmp(words[1], "FAIL") == 0) {
  400. if (mark_fails)
  401. btree_insert(info_exclude, words[0]);
  402. } else {
  403. if (!test->takes_options)
  404. warnx("%s: %s doesn't take options",
  405. info->fullname, words[0]);
  406. add_options(test, words+1, num_words-1);
  407. }
  408. }
  409. }
  410. }
  411. /* If options are of form "filename:<option>" they only apply to that file */
  412. char **per_file_options(const struct ccanlint *test, struct ccan_file *f)
  413. {
  414. char **ret;
  415. unsigned int i, j = 0;
  416. /* Fast path. */
  417. if (!test->options[0])
  418. return test->options;
  419. ret = talloc_array(f, char *, talloc_array_length(test->options));
  420. for (i = 0; test->options[i]; i++) {
  421. char *optname;
  422. if (!test->options[i] || !strchr(test->options[i], ':')) {
  423. optname = test->options[i];
  424. } else if (strstarts(test->options[i], f->name)
  425. && test->options[i][strlen(f->name)] == ':') {
  426. optname = test->options[i] + strlen(f->name) + 1;
  427. } else
  428. continue;
  429. /* FAIL overrides anything else. */
  430. if (streq(optname, "FAIL")) {
  431. ret = talloc_array(f, char *, 2);
  432. ret[0] = (char *)"FAIL";
  433. ret[1] = NULL;
  434. return ret;
  435. }
  436. ret[j++] = optname;
  437. }
  438. ret[j] = NULL;
  439. /* Shrink it to size so talloc_array_length() works as expected. */
  440. return talloc_realloc(NULL, ret, char *, j + 1);
  441. }
  442. static bool depends_on(struct ccanlint *i, struct ccanlint *target)
  443. {
  444. const struct dependent *d;
  445. if (i == target)
  446. return true;
  447. list_for_each(&i->dependencies, d, node) {
  448. if (depends_on(d->dependent, target))
  449. return true;
  450. }
  451. return false;
  452. }
  453. /* O(N^2), who cares? */
  454. static void skip_unrelated_tests(struct ccanlint *target)
  455. {
  456. struct ccanlint *i;
  457. struct list_head *list;
  458. foreach_ptr(list, &compulsory_tests, &normal_tests)
  459. list_for_each(list, i, list)
  460. if (!depends_on(i, target))
  461. i->skip = "not relevant to target";
  462. }
  463. static char *demangle_string(char *string)
  464. {
  465. unsigned int i;
  466. const char mapfrom[] = "abfnrtv";
  467. const char mapto[] = "\a\b\f\n\r\t\v";
  468. if (!strchr(string, '"'))
  469. return NULL;
  470. string = strchr(string, '"') + 1;
  471. if (!strrchr(string, '"'))
  472. return NULL;
  473. *strrchr(string, '"') = '\0';
  474. for (i = 0; i < strlen(string); i++) {
  475. if (string[i] == '\\') {
  476. char repl;
  477. unsigned len = 0;
  478. const char *p = strchr(mapfrom, string[i+1]);
  479. if (p) {
  480. repl = mapto[p - mapfrom];
  481. len = 1;
  482. } else if (strlen(string+i+1) >= 3) {
  483. if (string[i+1] == 'x') {
  484. repl = (string[i+2]-'0')*16
  485. + string[i+3]-'0';
  486. len = 3;
  487. } else if (cisdigit(string[i+1])) {
  488. repl = (string[i+2]-'0')*8*8
  489. + (string[i+3]-'0')*8
  490. + (string[i+4]-'0');
  491. len = 3;
  492. }
  493. }
  494. if (len == 0) {
  495. repl = string[i+1];
  496. len = 1;
  497. }
  498. string[i] = repl;
  499. memmove(string + i + 1, string + i + len + 1,
  500. strlen(string + i + len + 1) + 1);
  501. }
  502. }
  503. return string;
  504. }
  505. static void read_config_header(void)
  506. {
  507. char *fname = talloc_asprintf(NULL, "%s/config.h", ccan_dir);
  508. char **lines;
  509. unsigned int i;
  510. config_header = grab_file(NULL, fname, NULL);
  511. if (!config_header) {
  512. talloc_free(fname);
  513. return;
  514. }
  515. lines = strsplit(config_header, config_header, "\n");
  516. for (i = 0; i < talloc_array_length(lines) - 1; i++) {
  517. char *sym;
  518. const char **line = (const char **)&lines[i];
  519. if (!get_token(line, "#"))
  520. continue;
  521. if (!get_token(line, "define"))
  522. continue;
  523. sym = get_symbol_token(lines, line);
  524. if (streq(sym, "CCAN_COMPILER") && !compiler) {
  525. compiler = demangle_string(lines[i]);
  526. if (!compiler)
  527. errx(1, "%s:%u:could not parse CCAN_COMPILER",
  528. fname, i+1);
  529. if (verbose > 1)
  530. printf("%s: compiler set to '%s'\n",
  531. fname, compiler);
  532. } else if (streq(sym, "CCAN_CFLAGS") && !cflags) {
  533. cflags = demangle_string(lines[i]);
  534. if (!cflags)
  535. errx(1, "%s:%u:could not parse CCAN_CFLAGS",
  536. fname, i+1);
  537. if (verbose > 1)
  538. printf("%s: compiler flags set to '%s'\n",
  539. fname, cflags);
  540. }
  541. }
  542. if (!compiler)
  543. compiler = CCAN_COMPILER;
  544. if (!cflags)
  545. compiler = CCAN_CFLAGS;
  546. }
  547. static char *opt_set_const_charp(const char *arg, const char **p)
  548. {
  549. return opt_set_charp(arg, cast_const2(char **, p));
  550. }
  551. int main(int argc, char *argv[])
  552. {
  553. bool summary = false, pass = true;
  554. unsigned int score = 0, total_score = 0;
  555. struct manifest *m;
  556. struct ccanlint *i;
  557. const char *prefix = "";
  558. char *dir = talloc_getcwd(NULL), *base_dir = dir, *target = NULL;
  559. init_tests();
  560. cmdline_exclude = btree_new(btree_strcmp);
  561. info_exclude = btree_new(btree_strcmp);
  562. opt_register_arg("--dir|-d", opt_set_charp, opt_show_charp, &dir,
  563. "use this directory");
  564. opt_register_noarg("-n|--safe-mode", opt_set_bool, &safe_mode,
  565. "do not compile anything");
  566. opt_register_noarg("-l|--list-tests", list_tests, NULL,
  567. "list tests ccanlint performs (and exit)");
  568. opt_register_noarg("--test-dep-graph", test_dependency_graph, NULL,
  569. "print dependency graph of tests in Graphviz .dot format");
  570. opt_register_arg("-k|--keep <testname>", keep_test, NULL, NULL,
  571. "keep results of <testname>"
  572. " (can be used multiple times, or 'all')");
  573. opt_register_noarg("--summary|-s", opt_set_bool, &summary,
  574. "simply give one line summary");
  575. opt_register_noarg("--verbose|-v", opt_inc_intval, &verbose,
  576. "verbose mode (up to -vvvv)");
  577. opt_register_arg("-x|--exclude <testname>", skip_test, NULL, NULL,
  578. "exclude <testname> (can be used multiple times)");
  579. opt_register_arg("-t|--timeout <milleseconds>", opt_set_uintval,
  580. NULL, &timeout,
  581. "ignore (terminate) tests that are slower than this");
  582. opt_register_arg("--target <testname>", opt_set_charp,
  583. NULL, &target,
  584. "only run one test (and its prerequisites)");
  585. opt_register_arg("--compiler <compiler>", opt_set_const_charp,
  586. NULL, &compiler, "set the compiler");
  587. opt_register_arg("--cflags <flags>", opt_set_const_charp,
  588. NULL, &cflags, "set the compiler flags");
  589. opt_register_noarg("-?|-h|--help", opt_usage_and_exit,
  590. "\nA program for checking and guiding development"
  591. " of CCAN modules.",
  592. "This usage message");
  593. /* We move into temporary directory, so gcov dumps its files there. */
  594. if (chdir(temp_dir(talloc_autofree_context())) != 0)
  595. err(1, "Error changing to %s temporary dir", temp_dir(NULL));
  596. opt_parse(&argc, argv, opt_log_stderr_exit);
  597. if (dir[0] != '/')
  598. dir = talloc_asprintf_append(NULL, "%s/%s", base_dir, dir);
  599. while (strends(dir, "/"))
  600. dir[strlen(dir)-1] = '\0';
  601. if (dir != base_dir)
  602. prefix = talloc_append_string(talloc_basename(NULL, dir), ": ");
  603. if (verbose >= 3) {
  604. compile_verbose = true;
  605. print_test_depends();
  606. }
  607. if (verbose >= 4)
  608. tools_verbose = true;
  609. m = get_manifest(talloc_autofree_context(), dir);
  610. read_config_header();
  611. /* Create a symlink from temp dir back to src dir's test directory. */
  612. if (symlink(talloc_asprintf(m, "%s/test", dir),
  613. talloc_asprintf(m, "%s/test", temp_dir(NULL))) != 0)
  614. err(1, "Creating test symlink in %s", temp_dir(NULL));
  615. if (target) {
  616. struct ccanlint *test;
  617. test = find_test(target);
  618. if (!test)
  619. errx(1, "Unknown test to run '%s'", target);
  620. skip_unrelated_tests(test);
  621. }
  622. /* If you don't pass the compulsory tests, you get a score of 0. */
  623. while ((i = get_next_test(&compulsory_tests)) != NULL) {
  624. if (!run_test(i, summary, &score, &total_score, m)) {
  625. printf("%sTotal score: 0/%u\n", prefix, total_score);
  626. errx(1, "%s%s failed", prefix, i->name);
  627. }
  628. }
  629. /* --target overrides known FAIL from _info */
  630. if (m->info_file)
  631. add_info_options(m->info_file, !target);
  632. while ((i = get_next_test(&normal_tests)) != NULL)
  633. pass &= run_test(i, summary, &score, &total_score, m);
  634. printf("%sTotal score: %u/%u\n", prefix, score, total_score);
  635. return pass ? 0 : 1;
  636. }