| 176 | }; |
| 177 | |
| 178 | static int testsuite(int argc, const char **argv) |
| 179 | { |
| 180 | struct testsuite suite = TESTSUITE_INIT; |
| 181 | int max_jobs = 1, i, ret = 0; |
| 182 | DIR *dir; |
| 183 | struct dirent *d; |
| 184 | struct option options[] = { |
| 185 | OPT_BOOL('i', "immediate", &suite.immediate, |
| 186 | "stop at first failed test case(s)"), |
| 187 | OPT_INTEGER('j', "jobs", &max_jobs, "run <N> jobs in parallel"), |
| 188 | OPT_BOOL('q', "quiet", &suite.quiet, "be terse"), |
| 189 | OPT_BOOL('v', "verbose", &suite.verbose, "be verbose"), |
| 190 | OPT_BOOL('V', "verbose-log", &suite.verbose_log, |
| 191 | "be verbose, redirected to a file"), |
| 192 | OPT_BOOL('x', "trace", &suite.trace, "trace shell commands"), |
| 193 | OPT_BOOL(0, "write-junit-xml", &suite.write_junit_xml, |
| 194 | "write JUnit-style XML files"), |
| 195 | OPT_END() |
| 196 | }; |
| 197 | struct run_process_parallel_opts opts = { |
| 198 | .get_next_task = next_test, |
| 199 | .start_failure = test_failed, |
| 200 | .feed_pipe = test_stdin_pipe_feed, |
| 201 | .task_finished = test_finished, |
| 202 | .data = &suite, |
| 203 | }; |
| 204 | struct strbuf progpath = STRBUF_INIT; |
| 205 | size_t path_prefix_len; |
| 206 | |
| 207 | argc = parse_options(argc, argv, NULL, options, |
| 208 | testsuite_usage, PARSE_OPT_STOP_AT_NON_OPTION); |
| 209 | |
| 210 | if (max_jobs <= 0) |
| 211 | max_jobs = online_cpus(); |
| 212 | |
| 213 | /* |
| 214 | * If we run without a shell, execute the programs directly from CWD. |
| 215 | */ |
| 216 | suite.shell_path = getenv("TEST_SHELL_PATH"); |
| 217 | if (!suite.shell_path) |
| 218 | strbuf_addstr(&progpath, "./"); |
| 219 | path_prefix_len = progpath.len; |
| 220 | |
| 221 | dir = opendir("."); |
| 222 | if (!dir) |
| 223 | die("Could not open the current directory"); |
| 224 | while ((d = readdir(dir))) { |
| 225 | const char *p = d->d_name; |
| 226 | |
| 227 | if (!strcmp(p, ".") || !strcmp(p, "..")) |
| 228 | continue; |
| 229 | |
| 230 | /* No pattern: match all */ |
| 231 | if (!argc) { |
| 232 | strbuf_setlen(&progpath, path_prefix_len); |
| 233 | strbuf_addstr(&progpath, p); |
| 234 | string_list_append(&suite.tests, progpath.buf); |
| 235 | continue; |
no test coverage detected