4 #include <ccan/list/list.h>
6 #include "../doc_extract.h"
9 #define REGISTER_TEST(name, ...) extern struct ccanlint name
11 /* 0 == Describe failed tests.
12 1 == Describe results for partial failures.
13 2 == One line per test, plus details of failures.
15 Mainly for debugging ccanlint:
16 3 == Describe every object built.
17 4 == Describe every action. */
29 /* The module name, ie. final element of dir name */
31 struct ccan_file *info_file;
33 /* Linked off deps. */
34 struct list_node list;
35 /* Where our final compiled output is */
36 char *compiled[COMPILE_TYPES];
38 struct list_head c_files;
39 struct list_head h_files;
41 struct list_head run_tests;
42 struct list_head api_tests;
43 struct list_head compile_ok_tests;
44 struct list_head compile_fail_tests;
45 struct list_head other_test_c_files;
46 struct list_head other_test_files;
48 struct list_head other_files;
49 struct list_head examples;
50 struct list_head mangled_examples;
52 /* From tests/check_depends_exist.c */
53 struct list_head deps;
55 /* From tests/license_exists.c */
59 /* Get the manifest for a given directory. */
60 struct manifest *get_manifest(const void *ctx, const char *dir);
62 /* Error in a particular file: stored off score->per_file_errors. */
64 struct list_node list;
65 struct ccan_file *file;
69 /* The score for an individual test. */
71 /* Starts as false: if not set to true, ccanlint exits non-zero.
72 * Thus it is usually set for compilation or other serious failures. */
74 /* Starts at 0 and 1 respectively. */
75 unsigned int score, total;
76 /* The error message to print. */
78 /* Per file errors, set by score_file_error() */
79 struct list_head per_file_errors;
83 struct list_node list;
85 /* More concise unique name of test. */
88 /* Unique name of test */
91 /* Can we run this test? Return string explaining why, if not. */
92 const char *(*can_run)(struct manifest *m);
94 /* keep is set if you should keep the results.
95 * If timeleft is set to 0, means it timed out.
96 * score is the result, and a talloc context freed after all our
97 * depends are done. */
98 void (*check)(struct manifest *m,
99 bool keep, unsigned int *timeleft, struct score *score);
101 /* Can we do something about it? (NULL if not) */
102 void (*handle)(struct manifest *m, struct score *score);
104 /* Options from _info. */
106 /* If not set, we'll give an error if they try to set options. */
109 /* Space-separated list of dependency keys. */
112 /* Internal use fields: */
113 /* Who depends on us? */
114 struct list_head dependencies;
115 /* How many things do we (still) depend on? */
116 unsigned int num_depends;
117 /* Did we skip a dependency? If so, must skip this, too. */
119 /* Did we fail a dependency? If so, skip and mark as fail. */
121 /* Did the user want to keep these results? */
125 /* Ask the user a yes/no question: the answer is NO if there's an error. */
126 bool ask(const char *question);
128 enum line_info_type {
129 PREPROC_LINE, /* Line starts with # */
130 CODE_LINE, /* Code (ie. not pure comment). */
131 DOC_LINE, /* Line with kernel-doc-style comment. */
132 COMMENT_LINE, /* (pure) comment line */
135 /* So far, only do simple #ifdef/#ifndef/#if defined/#if !defined tests,
136 * and #if <SYMBOL>/#if !<SYMBOL> */
137 struct pp_conditions {
138 /* We're inside another ifdef? */
139 struct pp_conditions *parent;
151 /* Preprocessor information about each line. */
153 enum line_info_type type;
155 /* Is this actually a continuation of line above? (which ends in \) */
158 /* Conditions for this line to be compiled. */
159 struct pp_conditions *cond;
163 struct list_node list;
165 /* Name (usually, within m->dir). */
168 /* Full path name. */
171 /* Pristine version of the original file.
172 * Use get_ccan_file_contents to fill this. */
173 const char *contents;
174 size_t contents_size;
176 /* Use get_ccan_file_lines / get_ccan_line_info to fill these. */
177 unsigned int num_lines;
179 struct line_info *line_info;
181 struct list_head *doc_sections;
183 /* If this file gets compiled (eg. .C file to .o file), result here. */
184 char *compiled[COMPILE_TYPES];
186 /* Filename containing output from valgrind. */
189 /* Leak output from valgrind. */
192 /* Simplified stream (lowercase letters and single spaces) */
196 /* A new ccan_file, with the given name (talloc_steal onto returned value). */
197 struct ccan_file *new_ccan_file(const void *ctx, const char *dir, char *name);
199 /* Use this rather than accessing f->contents directly: loads on demand. */
200 const char *get_ccan_file_contents(struct ccan_file *f);
202 /* Use this rather than accessing f->lines directly: loads on demand. */
203 char **get_ccan_file_lines(struct ccan_file *f);
205 /* Use this rather than accessing f->lines directly: loads on demand. */
206 struct line_info *get_ccan_line_info(struct ccan_file *f);
208 /* Use this rather than accessing f->simplified directly: loads on demand. */
209 const char *get_ccan_simplified(struct ccan_file *f);
217 /* Simple evaluator. If symbols are set this way, is this condition true?
218 * NULL values mean undefined, NULL symbol terminates. */
219 enum line_compiled get_ccan_line_pp(struct pp_conditions *cond,
221 const unsigned int *value, ...);
223 /* Get token if it's equal to token. */
224 bool get_token(const char **line, const char *token);
225 /* Talloc copy of symbol token, or NULL. Increment line. */
226 char *get_symbol_token(void *ctx, const char **line);
228 /* Similarly for ->doc_sections */
229 struct list_head *get_ccan_file_docs(struct ccan_file *f);
231 /* Get NULL-terminated array options for this file for this test */
232 char **per_file_options(const struct ccanlint *test, struct ccan_file *f);
234 /* Append message about this file (and line, if non-zero) to the score->error */
235 void score_file_error(struct score *, struct ccan_file *f, unsigned line,
236 const char *errorfmt, ...);
239 extern struct ccanlint trailing_whitespace;
243 struct list_node node;
244 struct ccanlint *dependent;
247 /* Is this test excluded (cmdline or _info). */
248 bool is_excluded(const char *name);
250 /* Are we happy to compile stuff, or just non-intrusive tests? */
251 extern bool safe_mode;
253 /* Where is the ccan dir? Available after first manifest. */
254 extern const char *ccan_dir;
256 /* Compiler and CFLAGS, from config.h if available. */
257 extern const char *compiler, *cflags;
259 /* Contents of config.h (or NULL if not found) */
260 extern const char *config_header;
262 #endif /* CCAN_LINT_H */