]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/ccanlint.c
73a315722e7b2d3bbe434daab4906cfa12a372a4
[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/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
37 int verbose = 0;
38 static struct list_head compulsory_tests;
39 static struct list_head normal_tests;
40 bool safe_mode = false;
41 static struct btree *cmdline_exclude;
42 static struct btree *info_exclude;
43 static unsigned int timeout;
44
45 /* These are overridden at runtime if we can find config.h */
46 const char *compiler = NULL;
47 const char *cflags = NULL;
48
49 const char *config_header;
50
51 #if 0
52 static void indent_print(const char *string)
53 {
54         while (*string) {
55                 unsigned int line = strcspn(string, "\n");
56                 printf("\t%.*s", line, string);
57                 if (string[line] == '\n') {
58                         printf("\n");
59                         line++;
60                 }
61                 string += line;
62         }
63 }
64 #endif
65
66 bool ask(const char *question)
67 {
68         char reply[80];
69
70         printf("%s ", question);
71         fflush(stdout);
72
73         return fgets(reply, sizeof(reply), stdin) != NULL
74                 && toupper(reply[0]) == 'Y';
75 }
76
77 static const char *should_skip(struct manifest *m, struct ccanlint *i)
78 {
79         if (btree_lookup(cmdline_exclude, i->key))
80                 return "excluded on command line";
81
82         if (btree_lookup(info_exclude, i->key))
83                 return "excluded in _info file";
84         
85         if (i->skip)
86                 return i->skip;
87
88         if (i->skip_fail)
89                 return "dependency failed";
90
91         if (i->can_run)
92                 return i->can_run(m);
93         return NULL;
94 }
95
96 static bool run_test(struct ccanlint *i,
97                      bool quiet,
98                      unsigned int *running_score,
99                      unsigned int *running_total,
100                      struct manifest *m,
101                      const char *prefix)
102 {
103         unsigned int timeleft;
104         const struct dependent *d;
105         const char *skip;
106         struct score *score;
107
108         //one less test to run through
109         list_for_each(&i->dependencies, d, node)
110                 d->dependent->num_depends--;
111
112         score = talloc(m, struct score);
113         list_head_init(&score->per_file_errors);
114         score->error = NULL;
115         score->pass = false;
116         score->score = 0;
117         score->total = 1;
118
119         skip = should_skip(m, i);
120
121         if (skip) {
122         skip:
123                 if (verbose && !streq(skip, "not relevant to target"))
124                         printf("%s%s: skipped (%s)\n", prefix, i->name, skip);
125
126                 /* If we're skipping this because a prereq failed, we fail:
127                  * count it as a score of 1. */
128                 if (i->skip_fail)
129                         (*running_total)++;
130                         
131                 list_del(&i->list);
132                 list_for_each(&i->dependencies, d, node) {
133                         if (d->dependent->skip)
134                                 continue;
135                         d->dependent->skip = "dependency was skipped";
136                         d->dependent->skip_fail = i->skip_fail;
137                 }
138                 return i->skip_fail ? false : true;
139         }
140
141         timeleft = timeout ? timeout : default_timeout_ms;
142         i->check(m, i->keep_results, &timeleft, score);
143         if (timeout && timeleft == 0) {
144                 skip = "timeout";
145                 goto skip;
146         }
147
148         assert(score->score <= score->total);
149         if ((!score->pass && !quiet)
150             || (score->score < score->total && verbose)
151             || verbose > 1) {
152                 printf("%s%s (%s): %s",
153                        prefix, i->name, i->key, score->pass ? "PASS" : "FAIL");
154                 if (score->total > 1)
155                         printf(" (+%u/%u)", score->score, score->total);
156                 printf("\n");
157         }
158
159         if ((!quiet && !score->pass) || verbose) {
160                 if (score->error) {
161                         printf("%s%s", score->error,
162                                strends(score->error, "\n") ? "" : "\n");
163                 }
164         }
165         if (!quiet && score->score < score->total && i->handle)
166                 i->handle(m, score);
167
168         *running_score += score->score;
169         *running_total += score->total;
170
171         list_del(&i->list);
172
173         if (!score->pass) {
174                 /* Skip any tests which depend on this one. */
175                 list_for_each(&i->dependencies, d, node) {
176                         if (d->dependent->skip)
177                                 continue;
178                         d->dependent->skip = "dependency failed";
179                         d->dependent->skip_fail = true;
180                 }
181         }
182         return score->pass;
183 }
184
185 static void register_test(struct list_head *h, struct ccanlint *test)
186 {
187         list_add(h, &test->list);
188         test->options = talloc_array(NULL, char *, 1);
189         test->options[0] = NULL;
190         test->skip = NULL;
191         test->skip_fail = false;
192 }
193
194 /**
195  * get_next_test - retrieves the next test to be processed
196  **/
197 static inline struct ccanlint *get_next_test(struct list_head *test)
198 {
199         struct ccanlint *i;
200
201         if (list_empty(test))
202                 return NULL;
203
204         list_for_each(test, i, list) {
205                 if (i->num_depends == 0)
206                         return i;
207         }
208         errx(1, "Can't make process; test dependency cycle");
209 }
210
211 static struct ccanlint *find_test(const char *key)
212 {
213         struct ccanlint *i;
214
215         list_for_each(&compulsory_tests, i, list)
216                 if (streq(i->key, key))
217                         return i;
218
219         list_for_each(&normal_tests, i, list)
220                 if (streq(i->key, key))
221                         return i;
222
223         return NULL;
224 }
225
226 bool is_excluded(const char *name)
227 {
228         return btree_lookup(cmdline_exclude, name) != NULL
229                 || btree_lookup(info_exclude, name) != NULL
230                 || find_test(name)->skip != NULL;
231 }
232
233 #undef REGISTER_TEST
234 #define REGISTER_TEST(name, ...) extern struct ccanlint name
235 #include "generated-normal-tests"
236 #include "generated-compulsory-tests"
237
238 static void init_tests(void)
239 {
240         struct ccanlint *c;
241         struct btree *keys, *names;
242         struct list_head *list;
243
244         list_head_init(&normal_tests);
245         list_head_init(&compulsory_tests);
246
247 #undef REGISTER_TEST
248 #define REGISTER_TEST(name) register_test(&normal_tests, &name)
249 #include "generated-normal-tests"
250 #undef REGISTER_TEST
251 #define REGISTER_TEST(name) register_test(&compulsory_tests, &name)
252 #include "generated-compulsory-tests"
253
254         /* Initialize dependency lists. */
255         foreach_ptr(list, &compulsory_tests, &normal_tests) {
256                 list_for_each(list, c, list) {
257                         list_head_init(&c->dependencies);
258                         c->num_depends = 0;
259                 }
260         }
261
262         /* Resolve dependencies. */
263         foreach_ptr(list, &compulsory_tests, &normal_tests) {
264                 list_for_each(list, c, list) {
265                         char **deps = strsplit(NULL, c->needs, " ");
266                         unsigned int i;
267
268                         for (i = 0; deps[i]; i++) {
269                                 struct ccanlint *dep;
270                                 struct dependent *dchild;
271
272                                 dep = find_test(deps[i]);
273                                 if (!dep)
274                                         errx(1, "BUG: unknown dep '%s' for %s",
275                                              deps[i], c->key);
276                                 dchild = talloc(NULL, struct dependent);
277                                 dchild->dependent = c;
278                                 list_add_tail(&dep->dependencies,
279                                               &dchild->node);
280                                 c->num_depends++;
281                         }
282                         talloc_free(deps);
283                 }
284         }
285
286         /* Self-consistency check: make sure no two tests
287            have the same key or name. */
288         keys = btree_new(btree_strcmp);
289         names = btree_new(btree_strcmp);
290         foreach_ptr(list, &compulsory_tests, &normal_tests) {
291                 list_for_each(list, c, list) {
292                         if (!btree_insert(keys, c->key))
293                                 errx(1, "BUG: Duplicate test key '%s'",
294                                      c->key);
295                         if (!btree_insert(names, c->name))
296                                 errx(1, "BUG: Duplicate test name '%s'",
297                                      c->name);
298                 }
299         }
300         btree_delete(keys);
301         btree_delete(names);
302 }
303
304 static void print_test_depends(void)
305 {
306         struct list_head *list;
307
308         foreach_ptr(list, &compulsory_tests, &normal_tests) {
309                 struct ccanlint *c;
310                 printf("\%s Tests\n",
311                        list == &compulsory_tests ? "Compulsory" : "Normal");
312
313                 list_for_each(list, c, list) {
314                         if (!list_empty(&c->dependencies)) {
315                                 const struct dependent *d;
316                                 printf("These depend on %s:\n", c->key);
317                                 list_for_each(&c->dependencies, d, node)
318                                         printf("\t%s\n", d->dependent->key);
319                         }
320                 }
321         }
322 }
323
324 static int show_tmpdir(const char *dir)
325 {
326         printf("You can find ccanlint working files in '%s'\n", dir);
327         return 0;
328 }
329
330 static char *keep_test(const char *testname, void *unused)
331 {
332         struct ccanlint *i;
333
334         if (streq(testname, "all")) {
335                 struct list_head *list;
336                 foreach_ptr(list, &compulsory_tests, &normal_tests) {
337                         list_for_each(list, i, list)
338                                 i->keep_results = true;
339                 }
340         } else {
341                 i = find_test(testname);
342                 if (!i)
343                         errx(1, "No test %s to --keep", testname);
344                 i->keep_results = true;
345         }
346
347         /* Don't automatically destroy temporary dir. */
348         talloc_set_destructor(temp_dir(NULL), show_tmpdir);
349         return NULL;
350 }
351
352 static char *skip_test(const char *testname, void *unused)
353 {
354         btree_insert(cmdline_exclude, testname);
355         return NULL;
356 }
357
358 static void print_tests(struct list_head *tests, const char *type)
359 {
360         struct ccanlint *i;
361
362         printf("%s tests:\n", type);
363         /* This makes them print in topological order. */
364         while ((i = get_next_test(tests)) != NULL) {
365                 const struct dependent *d;
366                 printf("   %-25s %s\n", i->key, i->name);
367                 list_del(&i->list);
368                 list_for_each(&i->dependencies, d, node)
369                         d->dependent->num_depends--;
370         }
371 }
372
373 static char *list_tests(void *arg)
374 {
375         print_tests(&compulsory_tests, "Compulsory");
376         print_tests(&normal_tests, "Normal");
377         exit(0);
378 }
379
380 static void test_dgraph_vertices(struct list_head *tests, const char *style)
381 {
382         const struct ccanlint *i;
383
384         list_for_each(tests, i, list) {
385                 /*
386                  * todo: escape labels in case ccanlint test keys have
387                  *       characters interpreted as GraphViz syntax.
388                  */
389                 printf("\t\"%p\" [label=\"%s\"%s]\n", i, i->key, style);
390         }
391 }
392
393 static void test_dgraph_edges(struct list_head *tests)
394 {
395         const struct ccanlint *i;
396         const struct dependent *d;
397
398         list_for_each(tests, i, list)
399                 list_for_each(&i->dependencies, d, node)
400                         printf("\t\"%p\" -> \"%p\"\n", d->dependent, i);
401 }
402
403 static char *test_dependency_graph(void *arg)
404 {
405         puts("digraph G {");
406
407         test_dgraph_vertices(&compulsory_tests, ", style=filled, fillcolor=yellow");
408         test_dgraph_vertices(&normal_tests,     "");
409
410         test_dgraph_edges(&compulsory_tests);
411         test_dgraph_edges(&normal_tests);
412
413         puts("}");
414
415         exit(0);
416 }
417
418 /* Remove empty lines. */
419 static char **collapse(char **lines, unsigned int *nump)
420 {
421         unsigned int i, j;
422         for (i = j = 0; lines[i]; i++) {
423                 if (lines[i][0])
424                         lines[j++] = lines[i];
425         }
426         lines[j] = NULL;
427         if (nump)
428                 *nump = j;
429         return lines;
430 }
431
432
433 static void add_options(struct ccanlint *test, char **options,
434                         unsigned int num_options)
435 {
436         unsigned int num;
437
438         if (!test->options)
439                 num = 0;
440         else
441                 /* -1, because last one is NULL. */
442                 num = talloc_array_length(test->options) - 1;
443
444         test->options = talloc_realloc(NULL, test->options,
445                                        char *,
446                                        num + num_options + 1);
447         memcpy(&test->options[num], options, (num_options + 1)*sizeof(char *));
448 }
449
450 static void add_info_options(struct ccan_file *info, bool mark_fails)
451 {
452         struct doc_section *d;
453         unsigned int i;
454         struct ccanlint *test;
455
456         list_for_each(get_ccan_file_docs(info), d, list) {
457                 if (!streq(d->type, "ccanlint"))
458                         continue;
459
460                 for (i = 0; i < d->num_lines; i++) {
461                         unsigned int num_words;
462                         char **words = collapse(strsplit(d, d->lines[i], " \t"),
463                                                 &num_words);
464                         if (num_words == 0)
465                                 continue;
466
467                         if (strncmp(words[0], "//", 2) == 0)
468                                 continue;
469
470                         test = find_test(words[0]);
471                         if (!test) {
472                                 warnx("%s: unknown ccanlint test '%s'",
473                                       info->fullname, words[0]);
474                                 continue;
475                         }
476
477                         if (!words[1]) {
478                                 warnx("%s: no argument to test '%s'",
479                                       info->fullname, words[0]);
480                                 continue;
481                         }
482
483                         /* Known failure? */
484                         if (strcasecmp(words[1], "FAIL") == 0) {
485                                 if (mark_fails)
486                                         btree_insert(info_exclude, words[0]);
487                         } else {
488                                 if (!test->takes_options)
489                                         warnx("%s: %s doesn't take options",
490                                               info->fullname, words[0]);
491                                 add_options(test, words+1, num_words-1);
492                         }
493                 }
494         }
495 }
496
497 /* If options are of form "filename:<option>" they only apply to that file */
498 char **per_file_options(const struct ccanlint *test, struct ccan_file *f)
499 {
500         char **ret;
501         unsigned int i, j = 0;
502
503         /* Fast path. */
504         if (!test->options[0])
505                 return test->options;
506
507         ret = talloc_array(f, char *, talloc_array_length(test->options));
508         for (i = 0; test->options[i]; i++) {
509                 char *optname;
510
511                 if (!test->options[i] || !strchr(test->options[i], ':')) {
512                         optname = test->options[i];
513                 } else if (strstarts(test->options[i], f->name)
514                            && test->options[i][strlen(f->name)] == ':') {
515                         optname = test->options[i] + strlen(f->name) + 1;
516                 } else
517                         continue;
518
519                 /* FAIL overrides anything else. */
520                 if (streq(optname, "FAIL")) {
521                         ret = talloc_array(f, char *, 2);
522                         ret[0] = (char *)"FAIL";
523                         ret[1] = NULL;
524                         return ret;
525                 }
526                 ret[j++] = optname;
527         }
528         ret[j] = NULL;
529
530         /* Shrink it to size so talloc_array_length() works as expected. */
531         return talloc_realloc(NULL, ret, char *, j + 1);
532 }
533
534 static bool depends_on(struct ccanlint *i, struct ccanlint *target)
535 {
536         const struct dependent *d;
537
538         if (i == target)
539                 return true;
540
541         list_for_each(&i->dependencies, d, node) {
542                 if (depends_on(d->dependent, target))
543                         return true;
544         }
545         return false;
546 }
547
548 /* O(N^2), who cares? */
549 static void skip_unrelated_tests(struct ccanlint *target)
550 {
551         struct ccanlint *i;
552         struct list_head *list;
553
554         foreach_ptr(list, &compulsory_tests, &normal_tests)
555                 list_for_each(list, i, list)
556                         if (!depends_on(i, target))
557                                 i->skip = "not relevant to target";
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 int main(int argc, char *argv[])
660 {
661         bool summary = false, pass = true;
662         unsigned int i;
663         struct manifest *m;
664         struct ccanlint *t;
665         const char *prefix = "";
666         char *dir = talloc_getcwd(NULL), *base_dir = dir, *target = NULL,
667                 *testlink;
668         
669         cmdline_exclude = btree_new(btree_strcmp);
670         info_exclude = btree_new(btree_strcmp);
671
672         opt_register_noarg("-n|--safe-mode", opt_set_bool, &safe_mode,
673                          "do not compile anything");
674         opt_register_noarg("-l|--list-tests", list_tests, NULL,
675                          "list tests ccanlint performs (and exit)");
676         opt_register_noarg("--test-dep-graph", test_dependency_graph, NULL,
677                          "print dependency graph of tests in Graphviz .dot format");
678         opt_register_arg("-k|--keep <testname>", keep_test, NULL, NULL,
679                          "keep results of <testname>"
680                          " (can be used multiple times, or 'all')");
681         opt_register_noarg("--summary|-s", opt_set_bool, &summary,
682                            "simply give one line summary");
683         opt_register_noarg("--verbose|-v", opt_inc_intval, &verbose,
684                            "verbose mode (up to -vvvv)");
685         opt_register_arg("-x|--exclude <testname>", skip_test, NULL, NULL,
686                          "exclude <testname> (can be used multiple times)");
687         opt_register_arg("-t|--timeout <milleseconds>", opt_set_uintval,
688                          NULL, &timeout,
689                          "ignore (terminate) tests that are slower than this");
690         opt_register_arg("--target <testname>", opt_set_charp,
691                          NULL, &target,
692                          "only run one test (and its prerequisites)");
693         opt_register_arg("--compiler <compiler>", opt_set_const_charp,
694                          NULL, &compiler, "set the compiler");
695         opt_register_arg("--cflags <flags>", opt_set_const_charp,
696                          NULL, &cflags, "set the compiler flags");
697         opt_register_noarg("-?|-h|--help", opt_usage_and_exit,
698                            "\nA program for checking and guiding development"
699                            " of CCAN modules.",
700                            "This usage message");
701
702         /* We move into temporary directory, so gcov dumps its files there. */
703         if (chdir(temp_dir(talloc_autofree_context())) != 0)
704                 err(1, "Error changing to %s temporary dir", temp_dir(NULL));
705
706         opt_parse(&argc, argv, opt_log_stderr_exit);
707
708         if (verbose >= 3) {
709                 compile_verbose = true;
710                 print_test_depends();
711         }
712         if (verbose >= 4)
713                 tools_verbose = true;
714
715         /* Defaults to pwd. */
716         if (argc == 1) {
717                 i = 1;
718                 goto got_dir;
719         }
720
721         /* This links back to the module's test dir. */
722         testlink = talloc_asprintf(NULL, "%s/test", temp_dir(NULL));
723
724         for (i = 1; i < argc; i++) {
725                 unsigned int score, total_score;
726                 dir = argv[i];
727
728                 if (dir[0] != '/')
729                         dir = talloc_asprintf_append(NULL, "%s/%s",
730                                                      base_dir, dir);
731                 while (strends(dir, "/"))
732                         dir[strlen(dir)-1] = '\0';
733
734         got_dir:
735                 if (dir != base_dir)
736                         prefix = talloc_append_string(talloc_basename(NULL,dir),
737                                                       ": ");
738
739                 init_tests();
740
741                 if (target) {
742                         struct ccanlint *test;
743
744                         test = find_test(target);
745                         if (!test)
746                                 errx(1, "Unknown test to run '%s'", target);
747                         skip_unrelated_tests(test);
748                 }
749
750                 m = get_manifest(talloc_autofree_context(), dir);
751
752                 /* FIXME: This has to come after we've got manifest. */
753                 if (i == 1)
754                         read_config_header();
755
756                 /* Create a symlink from temp dir back to src dir's
757                  * test directory. */
758                 unlink(testlink);
759                 if (symlink(talloc_asprintf(m, "%s/test", dir), testlink) != 0)
760                         err(1, "Creating test symlink in %s", temp_dir(NULL));
761
762                 /* If you don't pass the compulsory tests, score is 0. */
763                 score = total_score = 0;
764                 while ((t = get_next_test(&compulsory_tests)) != NULL) {
765                         if (!run_test(t, summary, &score, &total_score, m,
766                                       prefix)) {
767                                 warnx("%s%s failed", prefix, t->name);
768                                 printf("%sTotal score: 0/%u\n",
769                                        prefix, total_score);
770                                 pass = false;
771                                 goto next;
772                         }
773                 }
774
775                 /* --target overrides known FAIL from _info */
776                 if (m->info_file)
777                         add_info_options(m->info_file, !target);
778
779                 while ((t = get_next_test(&normal_tests)) != NULL)
780                         pass &= run_test(t, summary, &score, &total_score, m,
781                                          prefix);
782
783                 printf("%sTotal score: %u/%u\n", prefix, score, total_score);
784         next: ;
785         }
786         return pass ? 0 : 1;
787 }