]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/compulsory_tests/compile_test_helpers.c
ccanlint: timeout, and implement -t option for quicker tests.
[ccan] / tools / ccanlint / compulsory_tests / compile_test_helpers.c
1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/str/str.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include <unistd.h>
9 #include <limits.h>
10 #include <errno.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <err.h>
14 #include <string.h>
15 #include <ctype.h>
16
17 static const char *can_build(struct manifest *m)
18 {
19         if (safe_mode)
20                 return "Safe mode enabled";
21         return NULL;
22 }
23
24 static char *compile(struct manifest *m, struct ccan_file *cfile)
25 {
26         char *err;
27         char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, cfile->name);
28
29         cfile->compiled = compile_object(m, fullfile, ccan_dir, &err);
30         if (cfile->compiled)
31                 return NULL;
32         return err;
33 }
34
35 static void *do_compile_test_helpers(struct manifest *m, unsigned int *timeleft)
36 {
37         char *cmdout = NULL;
38         struct ccan_file *i;
39
40         list_for_each(&m->other_test_c_files, i, list) {
41                 compile_tests.total_score++;
42                 cmdout = compile(m, i);
43                 if (cmdout)
44                         return talloc_asprintf(m,
45                                                "Failed to compile helper C"
46                                                " code file %s:\n%s",
47                                                i->name, cmdout);
48         }
49         return NULL;
50 }
51
52 static const char *describe_compile_test_helpers(struct manifest *m,
53                                                  void *check_result)
54 {
55         return check_result;
56 }
57
58 struct ccanlint compile_test_helpers = {
59         .key = "compile-helpers",
60         .name = "Module test helper objects compile",
61         .total_score = 1,
62         .check = do_compile_test_helpers,
63         .describe = describe_compile_test_helpers,
64         .can_run = can_build,
65 };
66
67 REGISTER_TEST(compile_test_helpers, &depends_built);