4 #include <ccan/list/list.h>
6 #include "../doc_extract.h"
8 #define REGISTER_TEST(name, ...) extern struct ccanlint name
10 /* 0 == Describe failed tests.
11 1 == Describe results for partial failures.
12 2 == One line per test, plus details of failures.
14 Mainly for debugging ccanlint:
15 3 == Describe every object built.
16 4 == Describe every action. */
21 /* The module name, ie. final element of dir name */
23 struct ccan_file *info_file;
25 /* Linked off deps. */
26 struct list_node list;
27 /* Where our final compiled output is */
30 struct list_head c_files;
31 struct list_head h_files;
33 struct list_head run_tests;
34 struct list_head api_tests;
35 struct list_head compile_ok_tests;
36 struct list_head compile_fail_tests;
37 struct list_head other_test_c_files;
38 struct list_head other_test_files;
40 struct list_head other_files;
41 struct list_head examples;
42 struct list_head mangled_examples;
44 /* From tests/check_depends_exist.c */
45 struct list_head deps;
48 /* Get the manifest for a given directory. */
49 struct manifest *get_manifest(const void *ctx, const char *dir);
51 /* Error in a particular file: stored off score->per_file_errors. */
53 struct list_node list;
54 struct ccan_file *file;
58 /* The score for an individual test. */
60 /* Starts as false: if not set to true, ccanlint exits non-zero.
61 * Thus it is usually set for compilation or other serious failures. */
63 /* Starts at 0 and 1 respectively. */
64 unsigned int score, total;
65 /* The error message to print. */
67 /* Per file errors, set by score_file_error() */
68 struct list_head per_file_errors;
72 struct list_node list;
74 /* More concise unique name of test. */
77 /* Unique name of test */
80 /* Can we run this test? Return string explaining why, if not. */
81 const char *(*can_run)(struct manifest *m);
83 /* keep is set if you should keep the results.
84 * If timeleft is set to 0, means it timed out.
85 * score is the result, and a talloc context freed after all our
86 * depends are done. */
87 void (*check)(struct manifest *m,
88 bool keep, unsigned int *timeleft, struct score *score);
90 /* Can we do something about it? (NULL if not) */
91 void (*handle)(struct manifest *m, struct score *score);
93 /* Options from _info. */
95 /* If not set, we'll give an error if they try to set options. */
98 /* Space-separated list of dependency keys. */
101 /* Internal use fields: */
102 /* Who depends on us? */
103 struct list_head dependencies;
104 /* How many things do we (still) depend on? */
105 unsigned int num_depends;
106 /* Did we skip a dependency? If so, must skip this, too. */
108 /* Did we fail a dependency? If so, skip and mark as fail. */
110 /* Did the user want to keep these results? */
114 /* Ask the user a yes/no question: the answer is NO if there's an error. */
115 bool ask(const char *question);
117 enum line_info_type {
118 PREPROC_LINE, /* Line starts with # */
119 CODE_LINE, /* Code (ie. not pure comment). */
120 DOC_LINE, /* Line with kernel-doc-style comment. */
121 COMMENT_LINE, /* (pure) comment line */
124 /* So far, only do simple #ifdef/#ifndef/#if defined/#if !defined tests,
125 * and #if <SYMBOL>/#if !<SYMBOL> */
126 struct pp_conditions {
127 /* We're inside another ifdef? */
128 struct pp_conditions *parent;
140 /* Preprocessor information about each line. */
142 enum line_info_type type;
144 /* Is this actually a continuation of line above? (which ends in \) */
147 /* Conditions for this line to be compiled. */
148 struct pp_conditions *cond;
152 struct list_node list;
154 /* Name (usually, within m->dir). */
157 /* Full path name. */
160 /* Pristine version of the original file.
161 * Use get_ccan_file_contents to fill this. */
162 const char *contents;
163 size_t contents_size;
165 /* Use get_ccan_file_lines / get_ccan_line_info to fill these. */
166 unsigned int num_lines;
168 struct line_info *line_info;
170 struct list_head *doc_sections;
172 /* If this file gets compiled (eg. .C file to .o file), result here. */
175 /* Compiled with coverage information. */
178 /* Leak output from valgrind. */
182 /* A new ccan_file, with the given name (talloc_steal onto returned value). */
183 struct ccan_file *new_ccan_file(const void *ctx, const char *dir, char *name);
185 /* Use this rather than accessing f->contents directly: loads on demand. */
186 const char *get_ccan_file_contents(struct ccan_file *f);
188 /* Use this rather than accessing f->lines directly: loads on demand. */
189 char **get_ccan_file_lines(struct ccan_file *f);
191 /* Use this rather than accessing f->lines directly: loads on demand. */
192 struct line_info *get_ccan_line_info(struct ccan_file *f);
200 /* Simple evaluator. If symbols are set this way, is this condition true?
201 * NULL values mean undefined, NULL symbol terminates. */
202 enum line_compiled get_ccan_line_pp(struct pp_conditions *cond,
204 const unsigned int *value, ...);
206 /* Get token if it's equal to token. */
207 bool get_token(const char **line, const char *token);
208 /* Talloc copy of symbol token, or NULL. Increment line. */
209 char *get_symbol_token(void *ctx, const char **line);
211 /* Similarly for ->doc_sections */
212 struct list_head *get_ccan_file_docs(struct ccan_file *f);
214 /* Append message about this file (and line, if non-zero) to the score->error */
215 void score_file_error(struct score *, struct ccan_file *f, unsigned line,
216 const char *errorfmt, ...);
219 extern struct ccanlint trailing_whitespace;
223 struct list_node node;
224 struct ccanlint *dependent;
227 /* Are we happy to compile stuff, or just non-intrusive tests? */
228 extern bool safe_mode;
230 /* Where is the ccan dir? Available after first manifest. */
231 extern const char *ccan_dir;
233 /* Compiler and CFLAGS, from config.h if available. */
234 extern const char *compiler, *cflags;
236 /* Contents of config.h (or NULL if not found) */
237 extern const char *config_header;
239 #endif /* CCAN_LINT_H */