Commit 7b54c220 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a default 30 second timeout around all test-cases.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4507 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 992c259f
...@@ -53,12 +53,15 @@ SVNID("$Id$") ...@@ -53,12 +53,15 @@ SVNID("$Id$")
#define MAX_FILESIZE (1024 * 1024) #define MAX_FILESIZE (1024 * 1024)
#define MAX_TOKENS 200 #define MAX_TOKENS 200
const char *vtc_file; const char *vtc_file;
char *vtc_desc; char *vtc_desc;
int vtc_error; /* Error encountered */ int vtc_error; /* Error encountered */
int vtc_stop; /* Stops current test without error */ int vtc_stop; /* Stops current test without error */
pthread_t vtc_thread; pthread_t vtc_thread;
char *vtc_tmpdir; char *vtc_tmpdir;
static struct vtclog *vltop;
static pthread_mutex_t vtc_mtx;
static pthread_cond_t vtc_cond;
/********************************************************************** /**********************************************************************
* Macro facility * Macro facility
...@@ -460,33 +463,67 @@ static const struct cmds cmds[] = { ...@@ -460,33 +463,67 @@ static const struct cmds cmds[] = {
{ NULL, NULL } { NULL, NULL }
}; };
struct priv_exec {
const char *fn;
char *buf;
};
static void *
exec_file_thread(void *priv)
{
unsigned old_err;
struct priv_exec *pe;
pe = priv;
parse_string(pe->buf, cmds, NULL, vltop);
old_err = vtc_error;
vtc_stop = 1;
vtc_log(vltop, 1, "RESETTING after %s", pe->fn);
reset_cmds(cmds);
vtc_error = old_err;
AZ(pthread_cond_signal(&vtc_cond));
return (NULL);
}
static double static double
exec_file(const char *fn, struct vtclog *vl) exec_file(const char *fn, unsigned dur)
{ {
char *buf;
double t0; double t0;
unsigned old_err; struct priv_exec pe;
pthread_t pt;
struct timespec ts;
void *v;
int i;
t0 = TIM_mono(); t0 = TIM_mono();
vtc_stop = 0; vtc_stop = 0;
vtc_file = fn; vtc_file = fn;
vtc_desc = NULL; vtc_desc = NULL;
vtc_log(vl, 1, "TEST %s starting", fn); vtc_log(vltop, 1, "TEST %s starting", fn);
buf = read_file(fn); pe.buf = read_file(fn);
if (buf == NULL) if (pe.buf == NULL)
vtc_log(vl, 0, "Cannot read file '%s': %s", vtc_log(vltop, 0, "Cannot read file '%s': %s",
fn, strerror(errno)); fn, strerror(errno));
parse_string(buf, cmds, NULL, vl); pe.fn = fn;
old_err = vtc_error;
vtc_stop = 1; AZ(pthread_create(&pt, NULL, exec_file_thread, &pe));
vtc_log(vl, 1, "RESETTING after %s", fn); AZ(pthread_mutex_lock(&vtc_mtx));
reset_cmds(cmds); AZ(clock_gettime(CLOCK_REALTIME, &ts));
vtc_error = old_err; ts.tv_sec += dur;
i = pthread_cond_timedwait(&vtc_cond, &vtc_mtx, &ts);
AZ(pthread_mutex_unlock(&vtc_mtx));
if (i == ETIMEDOUT) {
vtc_log(vltop, 1, "Test timed out");
vtc_error = 1;
} else {
AZ(pthread_join(pt, &v));
}
if (vtc_error) if (vtc_error)
vtc_log(vl, 1, "TEST %s FAILED", fn); vtc_log(vltop, 1, "TEST %s FAILED", fn);
else { else {
vtc_log(vl, 1, "TEST %s completed", fn); vtc_log(vltop, 1, "TEST %s completed", fn);
vtc_logreset(); vtc_logreset();
} }
...@@ -513,6 +550,10 @@ usage(void) ...@@ -513,6 +550,10 @@ usage(void)
exit(1); exit(1);
} }
/**********************************************************************
* Main
*/
/********************************************************************** /**********************************************************************
* Main * Main
*/ */
...@@ -522,17 +563,17 @@ main(int argc, char * const *argv) ...@@ -522,17 +563,17 @@ main(int argc, char * const *argv)
{ {
int ch, i, ntest = 1, ncheck = 0; int ch, i, ntest = 1, ncheck = 0;
FILE *fok; FILE *fok;
static struct vtclog *vl;
double tmax, t0, t00; double tmax, t0, t00;
unsigned dur = 30;
const char *nmax; const char *nmax;
char cmd[BUFSIZ]; char cmd[BUFSIZ];
setbuf(stdout, NULL); setbuf(stdout, NULL);
setbuf(stderr, NULL); setbuf(stderr, NULL);
vtc_loginit(); vtc_loginit();
vl = vtc_logopen("top"); vltop = vtc_logopen("top");
AN(vl); AN(vltop);
while ((ch = getopt(argc, argv, "n:qv")) != -1) { while ((ch = getopt(argc, argv, "n:qt:v")) != -1) {
switch (ch) { switch (ch) {
case 'n': case 'n':
ntest = strtoul(optarg, NULL, 0); ntest = strtoul(optarg, NULL, 0);
...@@ -540,6 +581,9 @@ main(int argc, char * const *argv) ...@@ -540,6 +581,9 @@ main(int argc, char * const *argv)
case 'q': case 'q':
vtc_verbosity--; vtc_verbosity--;
break; break;
case 't':
dur = strtoul(optarg, NULL, 0);
break;
case 'v': case 'v':
vtc_verbosity++; vtc_verbosity++;
break; break;
...@@ -559,16 +603,19 @@ main(int argc, char * const *argv) ...@@ -559,16 +603,19 @@ main(int argc, char * const *argv)
vtc_tmpdir = tempnam(NULL, "vtc"); vtc_tmpdir = tempnam(NULL, "vtc");
AN(vtc_tmpdir); AN(vtc_tmpdir);
AZ(mkdir(vtc_tmpdir, 0700)); AZ(mkdir(vtc_tmpdir, 0700));
macro_def(vl, NULL, "tmpdir", vtc_tmpdir); macro_def(vltop, NULL, "tmpdir", vtc_tmpdir);
vtc_thread = pthread_self(); vtc_thread = pthread_self();
macro_def(vl, NULL, "bad_ip", "10.255.255.255"); AZ(pthread_mutex_init(&vtc_mtx, NULL));
AZ(pthread_cond_init(&vtc_cond, NULL));
macro_def(vltop, NULL, "bad_ip", "10.255.255.255");
tmax = 0; tmax = 0;
nmax = NULL; nmax = NULL;
t00 = TIM_mono(); t00 = TIM_mono();
for (i = 0; i < ntest; i++) { for (i = 0; i < ntest; i++) {
for (ch = 0; ch < argc; ch++) { for (ch = 0; ch < argc; ch++) {
t0 = exec_file(argv[ch], vl); t0 = exec_file(argv[ch], dur);
ncheck++; ncheck++;
if (t0 > tmax) { if (t0 > tmax) {
tmax = t0; tmax = t0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment