3 #include <ccan/list/list.h>
5 #include "../doc_extract.h"
7 #define REGISTER_TEST(name, ...) extern struct ccanlint name
9 /* 0 == Describe failed tests.
10 1 == Describe results for partial failures.
11 2 == One line per test, plus details of failures.
13 Mainly for debugging ccanlint:
14 3 == Describe every object built.
15 4 == Describe every action. */
20 /* The module name, ie. final element of dir name */
22 struct ccan_file *info_file;
24 /* Linked off deps. */
25 struct list_node list;
26 /* Where our final compiled output is */
29 struct list_head c_files;
30 struct list_head h_files;
32 struct list_head run_tests;
33 struct list_head api_tests;
34 struct list_head compile_ok_tests;
35 struct list_head compile_fail_tests;
36 struct list_head other_test_c_files;
37 struct list_head other_test_files;
39 struct list_head other_files;
40 struct list_head examples;
41 struct list_head mangled_examples;
43 /* From tests/check_depends_exist.c */
44 struct list_head deps;
47 /* Get the manifest for a given directory. */
48 struct manifest *get_manifest(const void *ctx, const char *dir);
50 /* Error in a particular file: stored off score->per_file_errors. */
52 struct list_node list;
53 struct ccan_file *file;
57 /* The score for an individual test. */
59 /* Starts as false: if not set to true, ccanlint exits non-zero.
60 * Thus it is usually set for compilation or other serious failures. */
62 /* Starts at 0 and 1 respectively. */
63 unsigned int score, total;
64 /* The error message to print. */
66 /* Per file errors, set by score_file_error() */
67 struct list_head per_file_errors;
71 struct list_node list;
73 /* More concise unique name of test. */
76 /* Unique name of test */
79 /* Can we run this test? Return string explaining why, if not. */
80 const char *(*can_run)(struct manifest *m);
82 /* keep is set if you should keep the results.
83 * If timeleft is set to 0, means it timed out.
84 * score is the result, and a talloc context freed after all our
85 * depends are done. */
86 void (*check)(struct manifest *m,
87 bool keep, unsigned int *timeleft, struct score *score);
89 /* Can we do something about it? (NULL if not) */
90 void (*handle)(struct manifest *m, struct score *score);
92 /* Options from _info. */
94 /* If not set, we'll give an error if they try to set options. */
97 /* Space-separated list of dependency keys. */
100 /* Internal use fields: */
101 /* Who depends on us? */
102 struct list_head dependencies;
103 /* How many things do we (still) depend on? */
104 unsigned int num_depends;
105 /* Did we skip a dependency? If so, must skip this, too. */
107 /* Did we fail a dependency? If so, skip and mark as fail. */
109 /* Did the user want to keep these results? */
113 /* Ask the user a yes/no question: the answer is NO if there's an error. */
114 bool ask(const char *question);
116 enum line_info_type {
117 PREPROC_LINE, /* Line starts with # */
118 CODE_LINE, /* Code (ie. not pure comment). */
119 DOC_LINE, /* Line with kernel-doc-style comment. */
120 COMMENT_LINE, /* (pure) comment line */
123 /* So far, only do simple #ifdef/#ifndef/#if defined/#if !defined tests,
124 * and #if <SYMBOL>/#if !<SYMBOL> */
125 struct pp_conditions {
126 /* We're inside another ifdef? */
127 struct pp_conditions *parent;
139 /* Preprocessor information about each line. */
141 enum line_info_type type;
143 /* Is this actually a continuation of line above? (which ends in \) */
146 /* Conditions for this line to be compiled. */
147 struct pp_conditions *cond;
151 struct list_node list;
153 /* Name (usually, within m->dir). */
156 /* Full path name. */
159 /* Pristine version of the original file.
160 * Use get_ccan_file_contents to fill this. */
161 const char *contents;
162 size_t contents_size;
164 /* Use get_ccan_file_lines / get_ccan_line_info to fill these. */
165 unsigned int num_lines;
167 struct line_info *line_info;
169 struct list_head *doc_sections;
171 /* If this file gets compiled (eg. .C file to .o file), result here. */
174 /* Compiled with coverage information. */
177 /* Leak output from valgrind. */
181 /* A new ccan_file, with the given name (talloc_steal onto returned value). */
182 struct ccan_file *new_ccan_file(const void *ctx, const char *dir, char *name);
184 /* Use this rather than accessing f->contents directly: loads on demand. */
185 const char *get_ccan_file_contents(struct ccan_file *f);
187 /* Use this rather than accessing f->lines directly: loads on demand. */
188 char **get_ccan_file_lines(struct ccan_file *f);
190 /* Use this rather than accessing f->lines directly: loads on demand. */
191 struct line_info *get_ccan_line_info(struct ccan_file *f);
199 /* Simple evaluator. If symbols are set this way, is this condition true?
200 * NULL values mean undefined, NULL symbol terminates. */
201 enum line_compiled get_ccan_line_pp(struct pp_conditions *cond,
203 const unsigned int *value, ...);
205 /* Get token if it's equal to token. */
206 bool get_token(const char **line, const char *token);
207 /* Talloc copy of symbol token, or NULL. Increment line. */
208 char *get_symbol_token(void *ctx, const char **line);
210 /* Similarly for ->doc_sections */
211 struct list_head *get_ccan_file_docs(struct ccan_file *f);
213 /* Append message about this file (and line, if non-zero) to the score->error */
214 void score_file_error(struct score *, struct ccan_file *f, unsigned line,
215 const char *errorfmt, ...);
218 extern struct ccanlint trailing_whitespace;
222 struct list_node node;
223 struct ccanlint *dependent;
226 /* Are we happy to compile stuff, or just non-intrusive tests? */
227 extern bool safe_mode;
229 /* Where is the ccan dir? Available after first manifest. */
230 extern const char *ccan_dir;
232 /* Compiler and CFLAGS, from config.h if available. */
233 extern const char *compiler, *cflags;
235 /* Contents of config.h (or NULL if not found) */
236 extern const char *config_header;
238 #endif /* CCAN_LINT_H */