|
1 | 1 | #include "config.h" |
2 | 2 |
|
3 | 3 | #include <assert.h> |
| 4 | +#include <ccan/err/err.h> |
4 | 5 | #include <ccan/isaac/isaac64.h> |
5 | 6 | #include <ccan/short_types/short_types.h> |
6 | 7 | #include <ccan/tal/grab_file/grab_file.h> |
@@ -130,24 +131,40 @@ size_t cross_over(const u8 *in1, size_t in1_size, const u8 *in2, |
130 | 131 | /* In non-fuzzing builds, these become unit tests which just run the corpora: |
131 | 132 | * this is also good for attaching a debugger to! */ |
132 | 133 | #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION |
| 134 | +static size_t find_opt(char *argv[], const char *opt) |
| 135 | +{ |
| 136 | + for (size_t i = 1; argv[i]; i++) { |
| 137 | + if (streq(argv[i], opt)) |
| 138 | + return i; |
| 139 | + } |
| 140 | + return 0; |
| 141 | +} |
| 142 | + |
133 | 143 | int main(int argc, char *argv[]) |
134 | 144 | { |
135 | 145 | DIR *d; |
136 | 146 | struct dirent *di; |
| 147 | + int verbose_flag; |
137 | 148 |
|
138 | 149 | common_setup(argv[0]); |
139 | 150 | assert(chdir("tests/fuzz/corpora") == 0); |
140 | 151 | assert(chdir(path_basename(tmpctx, argv[0])) == 0); |
141 | 152 |
|
142 | | - /* FIXME: Support explicit path args? */ |
143 | 153 | init(&argc, &argv); |
| 154 | + verbose_flag = find_opt(argv, "-v"); |
144 | 155 | d = opendir("."); |
145 | 156 | while ((di = readdir(d)) != NULL) { |
146 | 157 | u8 *contents; |
147 | 158 | if (streq(di->d_name, ".") || streq(di->d_name, "..")) |
148 | 159 | continue; |
| 160 | + /* If you specify options other than -v, they're test names */ |
| 161 | + if (argv[verbose_flag + 1] && !find_opt(argv, di->d_name)) |
| 162 | + continue; |
| 163 | + if (verbose_flag) |
| 164 | + printf("%s\n", di->d_name); |
149 | 165 | contents = grab_file_raw(tmpctx, di->d_name); |
150 | | - assert(contents); |
| 166 | + if (!contents) |
| 167 | + err(1, "Could not read %s", di->d_name); |
151 | 168 | run(contents, tal_bytelen(contents)); |
152 | 169 | } |
153 | 170 | closedir(d); |
|
0 commit comments