]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/ccanlint.c
ccanlint: use ccan/autodata
[ccan] / tools / ccanlint / ccanlint.c
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/str/str.h>
29 #include <ccan/str_talloc/str_talloc.h>
30 #include <ccan/talloc/talloc.h>
31 #include <ccan/opt/opt.h>
32 #include <ccan/foreach/foreach.h>
33 #include <ccan/grab_file/grab_file.h>
34 #include <ccan/cast/cast.h>
35 #include <ccan/tlist/tlist.h>
36 #include <ccan/strmap/strmap.h>
37
38 struct ccanlint_map {
39         STRMAP_MEMBERS(struct ccanlint *);
40 };
41
42 int verbose = 0;
43 static struct ccanlint_map tests;
44 bool safe_mode = false;
45 bool keep_results = false;
46 static bool targeting = false;
47 static unsigned int timeout;
48
49 /* These are overridden at runtime if we can find config.h */
50 const char *compiler = NULL;
51 const char *cflags = NULL;
52
53 const char *config_header;
54
55 #if 0
56 static void indent_print(const char *string)
57 {
58         while (*string) {
59                 unsigned int line = strcspn(string, "\n");
60                 printf("\t%.*s", line, string);
61                 if (string[line] == '\n') {
62                         printf("\n");
63                         line++;
64                 }
65                 string += line;
66         }
67 }
68 #endif
69
70 bool ask(const char *question)
71 {
72         char reply[80];
73
74         printf("%s ", question);
75         fflush(stdout);
76
77         return fgets(reply, sizeof(reply), stdin) != NULL
78                 && toupper(reply[0]) == 'Y';
79 }
80
81 /* Skip, but don't remove. */
82 static bool skip_test(struct dgraph_node *node, const char *why)
83 {
84         struct ccanlint *c = container_of(node, struct ccanlint, node);
85         c->skip = why;
86         return true;
87 }
88
89 static const char *dep_failed(struct manifest *m)
90 {
91         return "dependency couldn't run";
92 }
93
94 static bool cannot_run(struct dgraph_node *node, void *unused)
95 {
96         struct ccanlint *c = container_of(node, struct ccanlint, node);
97         c->can_run = dep_failed;
98         return true;
99 }
100
101 struct run_info {
102         bool quiet;
103         unsigned int score, total;
104         struct manifest *m;
105         const char *prefix;
106         bool pass;
107 };
108
109 static bool run_test(struct dgraph_node *n, struct run_info *run)
110 {
111         struct ccanlint *i = container_of(n, struct ccanlint, node);
112         unsigned int timeleft;
113         struct score *score;
114
115         if (i->done)
116                 return true;
117
118         score = talloc(run->m, struct score);
119         list_head_init(&score->per_file_errors);
120         score->error = NULL;
121         score->pass = false;
122         score->score = 0;
123         score->total = 1;
124
125         /* We can see skipped things in two cases:
126          * (1) _info excluded them (presumably because they fail).
127          * (2) A prerequisite failed.
128          */
129         if (i->skip) {
130                 if (verbose)
131                         printf("%s%s: skipped (%s)\n",
132                                run->prefix, i->name, i->skip);
133                 /* Pass us up to the test which failed, not us. */
134                 score->pass = true;
135                 goto out;
136         }
137
138         if (i->can_run) {
139                 i->skip = i->can_run(run->m);
140                 if (i->skip) {
141                         /* Test doesn't apply, or can't run?  That's OK. */
142                         if (verbose > 1)
143                                 printf("%s%s: skipped (%s)\n",
144                                        run->prefix, i->name, i->skip);
145                         /* Mark our dependencies to skip. */
146                         dgraph_traverse_from(&i->node, cannot_run, NULL);
147                         score->pass = true;
148                         score->total = 0;
149                         goto out;
150                 }
151         }
152
153         timeleft = timeout ? timeout : default_timeout_ms;
154         i->check(run->m, &timeleft, score);
155         if (timeout && timeleft == 0) {
156                 i->skip = "timeout";
157                 if (verbose)
158                         printf("%s%s: skipped (%s)\n",
159                                run->prefix, i->name, i->skip);
160                 /* Mark our dependencies to skip. */
161                 dgraph_traverse_from(&i->node, skip_test,
162                                      "dependency timed out");
163                 score->pass = true;
164                 score->total = 0;
165                 goto out;
166         }
167
168         assert(score->score <= score->total);
169         if ((!score->pass && !run->quiet)
170             || (score->score < score->total && verbose)
171             || verbose > 1) {
172                 printf("%s%s (%s): %s",
173                        run->prefix, i->name, i->key,
174                        score->pass ? "PASS" : "FAIL");
175                 if (score->total > 1)
176                         printf(" (+%u/%u)", score->score, score->total);
177                 printf("\n");
178         }
179
180         if ((!run->quiet && !score->pass) || verbose) {
181                 if (score->error) {
182                         printf("%s%s", score->error,
183                                strends(score->error, "\n") ? "" : "\n");
184                 }
185         }
186         if (!run->quiet && score->score < score->total && i->handle)
187                 i->handle(run->m, score);
188
189         if (!score->pass) {
190                 /* Skip any tests which depend on this one. */
191                 dgraph_traverse_from(&i->node, skip_test, "dependency failed");
192         }
193
194 out:
195         run->score += score->score;
196         run->total += score->total;
197
198         /* FIXME: Free score. */
199         run->pass &= score->pass;
200         i->done = true;
201
202         if (!score->pass && i->compulsory) {
203                 warnx("%s%s failed", run->prefix, i->name);
204                 run->score = 0;
205                 return false;
206         }
207         return true;
208 }
209
210 static void register_test(struct ccanlint *test)
211 {
212         if (!strmap_add(&tests, test->key, test))
213                 err(1, "Adding test %s", test->key);
214         test->options = talloc_array(NULL, char *, 1);
215         test->options[0] = NULL;
216         dgraph_init_node(&test->node);
217 }
218
219 static bool get_test(const char *member, struct ccanlint *i,
220                      struct ccanlint **ret)
221 {
222         if (tlist_empty(&i->node.edge[DGRAPH_TO])) {
223                 *ret = i;
224                 return false;
225         }
226         return true;
227 }
228
229 /**
230  * get_next_test - retrieves the next test to be processed
231  **/
232 static inline struct ccanlint *get_next_test(void)
233 {
234         struct ccanlint *i = NULL;
235
236         strmap_iterate(&tests, get_test, &i);
237         if (i)
238                 return i;
239
240         if (strmap_empty(&tests))
241                 return NULL;
242
243         errx(1, "Can't make process; test dependency cycle");
244 }
245
246 static struct ccanlint *find_test(const char *key)
247 {
248         return strmap_get(&tests, key);
249 }
250
251 bool is_excluded(const char *name)
252 {
253         return find_test(name)->skip != NULL;
254 }
255
256 static bool init_deps(const char *member, struct ccanlint *c, void *unused)
257 {
258         char **deps = strsplit(NULL, c->needs, " ");
259         unsigned int i;
260
261         for (i = 0; deps[i]; i++) {
262                 struct ccanlint *dep;
263
264                 dep = find_test(deps[i]);
265                 if (!dep)
266                         errx(1, "BUG: unknown dep '%s' for %s",
267                              deps[i], c->key);
268                 dgraph_add_edge(&dep->node, &c->node);
269         }
270         talloc_free(deps);
271         return true;
272 }
273
274 static bool check_names(const char *member, struct ccanlint *c,
275                         struct ccanlint_map *names)
276 {
277         if (!strmap_add(names, c->name, c))
278                 err(1, "Duplicate name %s", c->name);
279         return true;
280 }
281
282 static void init_tests(void)
283 {
284         struct ccanlint_map names;
285         struct ccanlint **table;
286         size_t i, num;
287
288         strmap_init(&tests);
289
290         table = autodata_get(ccanlint_tests, &num);
291         for (i = 0; i < num; i++)
292                 register_test(table[i]);
293         autodata_free(table);
294
295         strmap_iterate(&tests, init_deps, NULL);
296
297         /* Check for duplicate names. */
298         strmap_init(&names);
299         strmap_iterate(&tests, check_names, &names);
300         strmap_clear(&names);
301 }
302
303 static bool reset_test(struct dgraph_node *node, void *unused)
304 {
305         struct ccanlint *c = container_of(node, struct ccanlint, node);
306         c->skip = NULL;
307         c->done = false;
308         return true;
309 }
310
311 static void reset_tests(struct dgraph_node *all)
312 {
313         dgraph_traverse_to(all, reset_test, NULL);
314 }
315
316 static bool print_deps(const char *member, struct ccanlint *c, void *unused)
317 {
318         if (!tlist_empty(&c->node.edge[DGRAPH_FROM])) {
319                 struct dgraph_edge *e;
320
321                 printf("These depend on %s:\n", c->key);
322                 dgraph_for_each_edge(&c->node, e, DGRAPH_FROM) {
323                         struct ccanlint *to = container_of(e->n[DGRAPH_TO],
324                                                            struct ccanlint,
325                                                            node);
326                         printf("\t%s\n", to->key);
327                 }
328         }
329         return true;
330 }
331
332 static void print_test_depends(void)
333 {
334         printf("Tests:\n");
335
336         strmap_iterate(&tests, print_deps, NULL);
337 }
338
339
340 static int show_tmpdir(const char *dir)
341 {
342         printf("You can find ccanlint working files in '%s'\n", dir);
343         return 0;
344 }
345
346 static char *keep_tests(void *unused)
347 {
348         keep_results = true;
349
350         /* Don't automatically destroy temporary dir. */
351         talloc_set_destructor(temp_dir(NULL), show_tmpdir);
352         return NULL;
353 }
354
355 static bool remove_test(struct dgraph_node *node, const char *why)
356 {
357         struct ccanlint *c = container_of(node, struct ccanlint, node);
358         c->skip = why;
359         dgraph_clear_node(node);
360         return true;
361 }
362
363 static char *exclude_test(const char *testname, void *unused)
364 {
365         struct ccanlint *i = find_test(testname);
366         if (!i)
367                 return talloc_asprintf(NULL, "No test %s to --exclude",
368                                        testname);
369
370         /* Remove this, and everything which depends on it. */
371         dgraph_traverse_from(&i->node, remove_test, "excluded on command line");
372         remove_test(&i->node, "excluded on command line");
373         return NULL;
374 }
375
376 static void skip_test_and_deps(struct ccanlint *c, const char *why)
377 {
378         /* Skip this, and everything which depends on us. */
379         dgraph_traverse_from(&c->node, skip_test, why);
380         skip_test(&c->node, why);
381 }
382
383 static char *list_tests(void *arg)
384 {
385         struct ccanlint *i;
386
387         printf("Tests:\n");
388         /* This makes them print in topological order. */
389         while ((i = get_next_test()) != NULL) {
390                 printf("   %-25s %s\n", i->key, i->name);
391                 dgraph_clear_node(&i->node);
392                 strmap_del(&tests, i->key, NULL);
393         }
394         exit(0);
395 }
396
397 static bool draw_test(const char *member, struct ccanlint *c, const char *style)
398 {
399         /*
400          * todo: escape labels in case ccanlint test keys have
401          *       characters interpreted as GraphViz syntax.
402          */
403         printf("\t\"%p\" [label=\"%s\"%s]\n", c, c->key, style);
404         return true;
405 }
406
407 static void test_dgraph_vertices(const char *style)
408 {
409         strmap_iterate(&tests, draw_test, style);
410 }
411
412 static bool draw_edges(const char *member, struct ccanlint *c, void *unused)
413 {
414         struct dgraph_edge *e;
415
416         dgraph_for_each_edge(&c->node, e, DGRAPH_FROM) {
417                 struct ccanlint *to = container_of(e->n[DGRAPH_TO],
418                                                    struct ccanlint,
419                                                    node);
420                 printf("\t\"%p\" -> \"%p\"\n", c->name, to->name);
421         }
422         return true;
423 }
424
425 static void test_dgraph_edges(void)
426 {
427         strmap_iterate(&tests, draw_edges, NULL);
428 }
429
430 static char *test_dependency_graph(void *arg)
431 {
432         puts("digraph G {");
433
434         test_dgraph_vertices("");
435         test_dgraph_edges();
436
437         puts("}");
438
439         exit(0);
440 }
441
442 /* Remove empty lines. */
443 static char **collapse(char **lines, unsigned int *nump)
444 {
445         unsigned int i, j;
446         for (i = j = 0; lines[i]; i++) {
447                 if (lines[i][0])
448                         lines[j++] = lines[i];
449         }
450         lines[j] = NULL;
451         if (nump)
452                 *nump = j;
453         return lines;
454 }
455
456
457 static void add_options(struct ccanlint *test, char **options,
458                         unsigned int num_options)
459 {
460         unsigned int num;
461
462         if (!test->options)
463                 num = 0;
464         else
465                 /* -1, because last one is NULL. */
466                 num = talloc_array_length(test->options) - 1;
467
468         test->options = talloc_realloc(NULL, test->options,
469                                        char *,
470                                        num + num_options + 1);
471         memcpy(&test->options[num], options, (num_options + 1)*sizeof(char *));
472 }
473
474 void add_info_options(struct ccan_file *info)
475 {
476         struct doc_section *d;
477         unsigned int i;
478         struct ccanlint *test;
479
480         list_for_each(get_ccan_file_docs(info), d, list) {
481                 if (!streq(d->type, "ccanlint"))
482                         continue;
483
484                 for (i = 0; i < d->num_lines; i++) {
485                         unsigned int num_words;
486                         char **words = collapse(strsplit(d, d->lines[i], " \t"),
487                                                 &num_words);
488                         if (num_words == 0)
489                                 continue;
490
491                         if (strncmp(words[0], "//", 2) == 0)
492                                 continue;
493
494                         test = find_test(words[0]);
495                         if (!test) {
496                                 warnx("%s: unknown ccanlint test '%s'",
497                                       info->fullname, words[0]);
498                                 continue;
499                         }
500
501                         if (!words[1]) {
502                                 warnx("%s: no argument to test '%s'",
503                                       info->fullname, words[0]);
504                                 continue;
505                         }
506
507                         /* Known failure? */
508                         if (strcasecmp(words[1], "FAIL") == 0) {
509                                 if (!targeting)
510                                         skip_test_and_deps(test,
511                                                            "excluded in _info"
512                                                            " file");
513                         } else {
514                                 if (!test->takes_options)
515                                         warnx("%s: %s doesn't take options",
516                                               info->fullname, words[0]);
517                                 add_options(test, words+1, num_words-1);
518                         }
519                 }
520         }
521 }
522
523 /* If options are of form "filename:<option>" they only apply to that file */
524 char **per_file_options(const struct ccanlint *test, struct ccan_file *f)
525 {
526         char **ret;
527         unsigned int i, j = 0;
528
529         /* Fast path. */
530         if (!test->options[0])
531                 return test->options;
532
533         ret = talloc_array(f, char *, talloc_array_length(test->options));
534         for (i = 0; test->options[i]; i++) {
535                 char *optname;
536
537                 if (!test->options[i] || !strchr(test->options[i], ':')) {
538                         optname = test->options[i];
539                 } else if (strstarts(test->options[i], f->name)
540                            && test->options[i][strlen(f->name)] == ':') {
541                         optname = test->options[i] + strlen(f->name) + 1;
542                 } else
543                         continue;
544
545                 /* FAIL overrides anything else. */
546                 if (streq(optname, "FAIL")) {
547                         ret = talloc_array(f, char *, 2);
548                         ret[0] = (char *)"FAIL";
549                         ret[1] = NULL;
550                         return ret;
551                 }
552                 ret[j++] = optname;
553         }
554         ret[j] = NULL;
555
556         /* Shrink it to size so talloc_array_length() works as expected. */
557         return talloc_realloc(NULL, ret, char *, j + 1);
558 }
559
560 static char *demangle_string(char *string)
561 {
562         unsigned int i;
563         const char mapfrom[] = "abfnrtv";
564         const char mapto[] = "\a\b\f\n\r\t\v";
565
566         if (!strchr(string, '"'))
567                 return NULL;
568         string = strchr(string, '"') + 1;
569         if (!strrchr(string, '"'))
570                 return NULL;
571         *strrchr(string, '"') = '\0';
572
573         for (i = 0; i < strlen(string); i++) {
574                 if (string[i] == '\\') {
575                         char repl;
576                         unsigned len = 0;
577                         const char *p = strchr(mapfrom, string[i+1]);
578                         if (p) {
579                                 repl = mapto[p - mapfrom];
580                                 len = 1;
581                         } else if (strlen(string+i+1) >= 3) {
582                                 if (string[i+1] == 'x') {
583                                         repl = (string[i+2]-'0')*16
584                                                 + string[i+3]-'0';
585                                         len = 3;
586                                 } else if (cisdigit(string[i+1])) {
587                                         repl = (string[i+2]-'0')*8*8
588                                                 + (string[i+3]-'0')*8
589                                                 + (string[i+4]-'0');
590                                         len = 3;
591                                 }
592                         }
593                         if (len == 0) {
594                                 repl = string[i+1];
595                                 len = 1;
596                         }
597
598                         string[i] = repl;
599                         memmove(string + i + 1, string + i + len + 1,
600                                 strlen(string + i + len + 1) + 1);
601                 }
602         }
603
604         return string;
605 }
606
607
608 static void read_config_header(void)
609 {
610         char *fname = talloc_asprintf(NULL, "%s/config.h", ccan_dir);
611         char **lines;
612         unsigned int i;
613
614         config_header = grab_file(NULL, fname, NULL);
615         if (!config_header) {
616                 talloc_free(fname);
617                 return;
618         }
619
620         lines = strsplit(config_header, config_header, "\n");
621         for (i = 0; i < talloc_array_length(lines) - 1; i++) {
622                 char *sym;
623                 const char **line = (const char **)&lines[i];
624
625                 if (!get_token(line, "#"))
626                         continue;
627                 if (!get_token(line, "define"))
628                         continue;
629                 sym = get_symbol_token(lines, line);
630                 if (streq(sym, "CCAN_COMPILER") && !compiler) {
631                         compiler = demangle_string(lines[i]);
632                         if (!compiler)
633                                 errx(1, "%s:%u:could not parse CCAN_COMPILER",
634                                      fname, i+1);
635                         if (verbose > 1)
636                                 printf("%s: compiler set to '%s'\n",
637                                        fname, compiler);
638                 } else if (streq(sym, "CCAN_CFLAGS") && !cflags) {
639                         cflags = demangle_string(lines[i]);
640                         if (!cflags)
641                                 errx(1, "%s:%u:could not parse CCAN_CFLAGS",
642                                      fname, i+1);
643                         if (verbose > 1)
644                                 printf("%s: compiler flags set to '%s'\n",
645                                        fname, cflags);
646                 }
647         }
648         if (!compiler)
649                 compiler = CCAN_COMPILER;
650         if (!cflags)
651                 compiler = CCAN_CFLAGS;
652 }
653
654 static char *opt_set_const_charp(const char *arg, const char **p)
655 {
656         return opt_set_charp(arg, cast_const2(char **, p));
657 }
658
659 static char *opt_set_target(const char *arg, struct dgraph_node *all)
660 {
661         struct ccanlint *t = find_test(arg);
662         if (!t)
663                 return talloc_asprintf(NULL, "unknown --target %s", arg);
664
665         targeting = true;
666         dgraph_add_edge(&t->node, all);
667         return NULL;
668 }
669
670 static bool run_tests(struct dgraph_node *all,
671                       bool summary,
672                       struct manifest *m,
673                       const char *prefix)
674 {
675         struct run_info run;
676
677         run.quiet = summary;
678         run.m = m;
679         run.prefix = prefix;
680         run.score = run.total = 0;
681         run.pass = true;
682
683         dgraph_traverse_to(all, run_test, &run);
684
685         printf("%sTotal score: %u/%u\n", prefix, run.score, run.total);
686         return run.pass;
687 }
688
689 static bool add_to_all(const char *member, struct ccanlint *c,
690                        struct dgraph_node *all)
691 {
692         dgraph_add_edge(&c->node, all);
693         return true;
694 }
695
696 int main(int argc, char *argv[])
697 {
698         bool summary = false, pass = true;
699         unsigned int i;
700         struct manifest *m;
701         const char *prefix = "";
702         char *dir = talloc_getcwd(NULL), *base_dir = dir, *testlink;
703         struct dgraph_node all;
704         
705         /* Empty graph node to which we attach everything else. */
706         dgraph_init_node(&all);
707
708         opt_register_early_noarg("--verbose|-v", opt_inc_intval, &verbose,
709                                  "verbose mode (up to -vvvv)");
710         opt_register_noarg("-n|--safe-mode", opt_set_bool, &safe_mode,
711                          "do not compile anything");
712         opt_register_noarg("-l|--list-tests", list_tests, NULL,
713                          "list tests ccanlint performs (and exit)");
714         opt_register_noarg("--test-dep-graph", test_dependency_graph, NULL,
715                          "print dependency graph of tests in Graphviz .dot format");
716         opt_register_noarg("-k|--keep", keep_tests, NULL,
717                          "do not delete ccanlint working files");
718         opt_register_noarg("--summary|-s", opt_set_bool, &summary,
719                            "simply give one line summary");
720         opt_register_arg("-x|--exclude <testname>", exclude_test, NULL, NULL,
721                          "exclude <testname> (can be used multiple times)");
722         opt_register_arg("--timeout <milleseconds>", opt_set_uintval,
723                          NULL, &timeout,
724                          "ignore (terminate) tests that are slower than this");
725         opt_register_arg("-t|--target <testname>", opt_set_target, NULL, &all,
726                          "only run one test (and its prerequisites)");
727         opt_register_arg("--compiler <compiler>", opt_set_const_charp,
728                          NULL, &compiler, "set the compiler");
729         opt_register_arg("--cflags <flags>", opt_set_const_charp,
730                          NULL, &cflags, "set the compiler flags");
731         opt_register_noarg("-?|-h|--help", opt_usage_and_exit,
732                            "\nA program for checking and guiding development"
733                            " of CCAN modules.",
734                            "This usage message");
735
736         /* Do verbose before anything else... */
737         opt_early_parse(argc, argv, opt_log_stderr_exit);
738
739         /* We move into temporary directory, so gcov dumps its files there. */
740         if (chdir(temp_dir(talloc_autofree_context())) != 0)
741                 err(1, "Error changing to %s temporary dir", temp_dir(NULL));
742
743         init_tests();
744
745         if (verbose >= 3) {
746                 compile_verbose = true;
747                 print_test_depends();
748         }
749         if (verbose >= 4)
750                 tools_verbose = true;
751
752         opt_parse(&argc, argv, opt_log_stderr_exit);
753
754         if (!targeting)
755                 strmap_iterate(&tests, add_to_all, &all);
756
757         /* This links back to the module's test dir. */
758         testlink = talloc_asprintf(NULL, "%s/test", temp_dir(NULL));
759
760         /* Defaults to pwd. */
761         if (argc == 1) {
762                 i = 1;
763                 goto got_dir;
764         }
765
766         for (i = 1; i < argc; i++) {
767                 unsigned int score, total_score;
768
769                 dir = argv[i];
770
771                 if (dir[0] != '/')
772                         dir = talloc_asprintf_append(NULL, "%s/%s",
773                                                      base_dir, dir);
774                 while (strends(dir, "/"))
775                         dir[strlen(dir)-1] = '\0';
776
777         got_dir:
778                 if (dir != base_dir)
779                         prefix = talloc_append_string(talloc_basename(NULL,dir),
780                                                       ": ");
781
782                 m = get_manifest(talloc_autofree_context(), dir);
783
784                 /* FIXME: This has to come after we've got manifest. */
785                 if (i == 1)
786                         read_config_header();
787
788                 /* Create a symlink from temp dir back to src dir's
789                  * test directory. */
790                 unlink(testlink);
791                 if (symlink(talloc_asprintf(m, "%s/test", dir), testlink) != 0)
792                         err(1, "Creating test symlink in %s", temp_dir(NULL));
793
794                 score = total_score = 0;
795                 if (!run_tests(&all, summary, m, prefix))
796                         pass = false;
797
798                 reset_tests(&all);
799         }
800         return pass ? 0 : 1;
801 }