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. */
30 LICENSE_PUBLIC_DOMAIN,
36 /* The module name, ie. final element of dir name */
38 struct ccan_file *info_file;
40 /* Linked off deps. */
41 struct list_node list;
42 /* Where our final compiled output is */
45 struct list_head c_files;
46 struct list_head h_files;
48 struct list_head run_tests;
49 struct list_head api_tests;
50 struct list_head compile_ok_tests;
51 struct list_head compile_fail_tests;
52 struct list_head other_test_c_files;
53 struct list_head other_test_files;
55 struct list_head other_files;
56 struct list_head examples;
57 struct list_head mangled_examples;
59 /* From tests/check_depends_exist.c */
60 struct list_head deps;
62 /* From tests/license_exists.c */
66 /* Get the manifest for a given directory. */
67 struct manifest *get_manifest(const void *ctx, const char *dir);
69 /* Error in a particular file: stored off score->per_file_errors. */
71 struct list_node list;
72 struct ccan_file *file;
76 /* The score for an individual test. */
78 /* Starts as false: if not set to true, ccanlint exits non-zero.
79 * Thus it is usually set for compilation or other serious failures. */
81 /* Starts at 0 and 1 respectively. */
82 unsigned int score, total;
83 /* The error message to print. */
85 /* Per file errors, set by score_file_error() */
86 struct list_head per_file_errors;
90 struct list_node list;
92 /* More concise unique name of test. */
95 /* Unique name of test */
98 /* Can we run this test? Return string explaining why, if not. */
99 const char *(*can_run)(struct manifest *m);
101 /* keep is set if you should keep the results.
102 * If timeleft is set to 0, means it timed out.
103 * score is the result, and a talloc context freed after all our
104 * depends are done. */
105 void (*check)(struct manifest *m,
106 bool keep, unsigned int *timeleft, struct score *score);
108 /* Can we do something about it? (NULL if not) */
109 void (*handle)(struct manifest *m, struct score *score);
111 /* Options from _info. */
113 /* If not set, we'll give an error if they try to set options. */
116 /* Space-separated list of dependency keys. */
119 /* Internal use fields: */
120 /* Who depends on us? */
121 struct list_head dependencies;
122 /* How many things do we (still) depend on? */
123 unsigned int num_depends;
124 /* Did we skip a dependency? If so, must skip this, too. */
126 /* Did we fail a dependency? If so, skip and mark as fail. */
128 /* Did the user want to keep these results? */
132 /* Ask the user a yes/no question: the answer is NO if there's an error. */
133 bool ask(const char *question);
135 enum line_info_type {
136 PREPROC_LINE, /* Line starts with # */
137 CODE_LINE, /* Code (ie. not pure comment). */
138 DOC_LINE, /* Line with kernel-doc-style comment. */
139 COMMENT_LINE, /* (pure) comment line */
142 /* So far, only do simple #ifdef/#ifndef/#if defined/#if !defined tests,
143 * and #if <SYMBOL>/#if !<SYMBOL> */
144 struct pp_conditions {
145 /* We're inside another ifdef? */
146 struct pp_conditions *parent;
158 /* Preprocessor information about each line. */
160 enum line_info_type type;
162 /* Is this actually a continuation of line above? (which ends in \) */
165 /* Conditions for this line to be compiled. */
166 struct pp_conditions *cond;
170 struct list_node list;
172 /* Name (usually, within m->dir). */
175 /* Full path name. */
178 /* Pristine version of the original file.
179 * Use get_ccan_file_contents to fill this. */
180 const char *contents;
181 size_t contents_size;
183 /* Use get_ccan_file_lines / get_ccan_line_info to fill these. */
184 unsigned int num_lines;
186 struct line_info *line_info;
188 struct list_head *doc_sections;
190 /* If this file gets compiled (eg. .C file to .o file), result here. */
193 /* Compiled with coverage information. */
196 /* Leak output from valgrind. */
200 /* A new ccan_file, with the given name (talloc_steal onto returned value). */
201 struct ccan_file *new_ccan_file(const void *ctx, const char *dir, char *name);
203 /* Use this rather than accessing f->contents directly: loads on demand. */
204 const char *get_ccan_file_contents(struct ccan_file *f);
206 /* Use this rather than accessing f->lines directly: loads on demand. */
207 char **get_ccan_file_lines(struct ccan_file *f);
209 /* Use this rather than accessing f->lines directly: loads on demand. */
210 struct line_info *get_ccan_line_info(struct ccan_file *f);
218 /* Simple evaluator. If symbols are set this way, is this condition true?
219 * NULL values mean undefined, NULL symbol terminates. */
220 enum line_compiled get_ccan_line_pp(struct pp_conditions *cond,
222 const unsigned int *value, ...);
224 /* Get token if it's equal to token. */
225 bool get_token(const char **line, const char *token);
226 /* Talloc copy of symbol token, or NULL. Increment line. */
227 char *get_symbol_token(void *ctx, const char **line);
229 /* Similarly for ->doc_sections */
230 struct list_head *get_ccan_file_docs(struct ccan_file *f);
232 /* Append message about this file (and line, if non-zero) to the score->error */
233 void score_file_error(struct score *, struct ccan_file *f, unsigned line,
234 const char *errorfmt, ...);
237 extern struct ccanlint trailing_whitespace;
241 struct list_node node;
242 struct ccanlint *dependent;
245 /* Are we happy to compile stuff, or just non-intrusive tests? */
246 extern bool safe_mode;
248 /* Where is the ccan dir? Available after first manifest. */
249 extern const char *ccan_dir;
251 /* Compiler and CFLAGS, from config.h if available. */
252 extern const char *compiler, *cflags;
254 /* Contents of config.h (or NULL if not found) */
255 extern const char *config_header;
257 #endif /* CCAN_LINT_H */