X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ffailtest%2Ffailtest.c;h=dcf034ccffe7594f90ada21fdc916bf978a90546;hp=1874d620286d697c9c063319f8435e52dd5823aa;hb=5069685c5ec19f6d29cb0bd5eefd534c617119cc;hpb=479813329a1ca27f48877b2e872d813f85c957ab diff --git a/ccan/failtest/failtest.c b/ccan/failtest/failtest.c index 1874d620..dcf034cc 100644 --- a/ccan/failtest/failtest.c +++ b/ccan/failtest/failtest.c @@ -25,6 +25,7 @@ static int tracefd = -1; unsigned int failtest_timeout_ms = 20000; const char *failpath; +const char *debugpath; enum info_type { WRITE, @@ -329,6 +330,29 @@ static bool should_fail(struct failtest_call *call) } } + /* Attach debugger if they asked for it. */ + if (debugpath && history_num == strlen(debugpath)) { + unsigned int i; + + for (i = 0; i < history_num; i++) { + char c = info_to_arg[history[i].type]; + if (history[i].fail) + c = toupper(c); + if (c != debugpath[i]) + break; + } + if (i == history_num) { + char str[80]; + + /* Don't timeout. */ + signal(SIGUSR1, SIG_IGN); + sprintf(str, "xterm -e gdb /proc/%d/exe %d &", + getpid(), getpid()); + system(str); + sleep(5); + } + } + if (!failtest_hook(history, history_num)) { call->fail = false; return false; @@ -431,9 +455,13 @@ static bool should_fail(struct failtest_call *call) close(output[0]); close(control[0]); waitpid(child, &status, 0); - if (!WIFEXITED(status)) - child_fail(out, outlen, "Killed by signal %u: ", - WTERMSIG(status)); + if (!WIFEXITED(status)) { + if (WTERMSIG(status) == SIGUSR1) + child_fail(out, outlen, "Timed out"); + else + child_fail(out, outlen, "Killed by signal %u: ", + WTERMSIG(status)); + } /* Child printed failure already, just pass up exit code. */ if (type == FAILURE) { fprintf(stderr, "%.*s", (int)outlen, out); @@ -927,6 +955,9 @@ void failtest_init(int argc, char *argv[]) } else if (strcmp(argv[i], "--tracepath") == 0) { tracefd = dup(STDERR_FILENO); failtest_timeout_ms = -1; + } else if (!strncmp(argv[i], "--debugpath=", + strlen("--debugpath="))) { + debugpath = argv[i] + strlen("--debugpath="); } } gettimeofday(&start, NULL);