Commit 3a61b691 authored by Tollef Fog Heen's avatar Tollef Fog Heen

Add tmpdir macro to varnishtest

Make a tmpdir macro available that points at a temporary directory
which will be cleaned up after the test has run.  Adjust test cases to
use this rather than hard-coding paths in /tmp.

git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4455 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 09758dbe
......@@ -2,4 +2,4 @@
test "See that the VCL compiler works"
shell "cd ../varnishd && ./varnishd -b 127.0.0.1:80 -C -n /tmp/__v1"
shell "cd ../varnishd && ./varnishd -b 127.0.0.1:80 -C -n ${tmpdir}"
......@@ -12,19 +12,17 @@ server s1 {
txresp -body "bar"
} -start
shell "echo 'backend foo { .host = \"${s1_addr}\"; .port = \"${s1_port}\"; }' > /tmp/_b00014.vcl"
varnish v1 -arg "-f /tmp/_b00014.vcl" -start
shell "echo 'backend foo { .host = \"${s1_addr}\"; .port = \"${s1_port}\"; }' > ${tmpdir}/_b00014.vcl"
varnish v1 -arg "-f ${tmpdir}/_b00014.vcl" -start
client c1 {
txreq -url /foo
rxresp
} -run
varnish v1 -cliok "vcl.load foo /tmp/_b00014.vcl" -cliok "vcl.use foo"
varnish v1 -cliok "vcl.load foo ${tmpdir}/_b00014.vcl" -cliok "vcl.use foo"
client c1 {
txreq -url /bar
rxresp
} -run
shell "rm -f /tmp/_b00014.vcl"
......@@ -7,11 +7,11 @@ server s1 {
txresp
} -start
shell "rm -f /tmp/__v1/_.per"
shell "rm -f ${tmpdir}/_.per"
varnish v1 \
-arg "-pdiag_bitmap=0x20000" \
-arg "-spersistent,/tmp/__v1/_.per,10m" -vcl+backend { } -start
-arg "-spersistent,${tmpdir}/_.per,10m" -vcl+backend { } -start
varnish v1 -stop
......
......@@ -2,7 +2,7 @@
test "Change TTL on persistent object"
shell "rm -f /tmp/__v1/_.per"
shell "rm -f ${tmpdir}/_.per"
server s1 {
rxreq
......@@ -11,7 +11,7 @@ server s1 {
varnish v1 \
-arg "-pdiag_bitmap=0x20000" \
-arg "-spersistent,/tmp/__v1/_.per,10m" -vcl+backend { } -start
-arg "-spersistent,${tmpdir}/_.per,10m" -vcl+backend { } -start
client c1 {
txreq -url "/"
......
......@@ -2,7 +2,7 @@
test "Ban a persistent object"
shell "rm -f /tmp/__v1/_.per[12]"
shell "rm -f ${tmpdir}/_.per[12]"
server s1 {
rxreq
......@@ -11,8 +11,8 @@ server s1 {
varnish v1 \
-arg "-pdiag_bitmap=0x20000" \
-arg "-spersistent,/tmp/__v1/_.per1,10m" \
-arg "-spersistent,/tmp/__v1/_.per2,10m" \
-arg "-spersistent,${tmpdir}/_.per1,10m" \
-arg "-spersistent,${tmpdir}/_.per2,10m" \
-vcl+backend { } -start
client c1 {
......
......@@ -2,7 +2,7 @@
test "Ban a persistent object"
shell "rm -f /tmp/__v1/_.per"
shell "rm -f ${tmpdir}/_.per"
server s1 {
rxreq
......@@ -11,7 +11,7 @@ server s1 {
varnish v1 \
-arg "-pdiag_bitmap=0x20000" \
-arg "-spersistent,/tmp/__v1/_.per,10m" \
-arg "-spersistent,${tmpdir}/_.per,10m" \
-vcl+backend { } -start
varnish v1 -cliok purge.list
......
......@@ -2,7 +2,7 @@
test "Check object references"
shell "rm -f /tmp/__v1/_.per"
shell "rm -f ${tmpdir}/_.per"
server s1 {
rxreq
......@@ -13,7 +13,7 @@ server s1 {
varnish v1 \
-arg "-pdiag_bitmap=0x20000" \
-arg "-spersistent,/tmp/__v1/_.per,10m" \
-arg "-spersistent,${tmpdir}/_.per,10m" \
-vcl+backend { } -start
client c1 {
......
......@@ -2,7 +2,7 @@
test "Check expiry of non-instantiated object"
shell "rm -f /tmp/__v1/_.per"
shell "rm -f ${tmpdir}/_.per"
server s1 {
rxreq
......@@ -11,7 +11,7 @@ server s1 {
varnish v1 \
-arg "-pdiag_bitmap=0x30000" \
-arg "-spersistent,/tmp/__v1/_.per,10m" \
-arg "-spersistent,${tmpdir}/_.per,10m" \
-vcl+backend {
sub vcl_fetch {
set beresp.ttl = 3s;
......
......@@ -2,7 +2,7 @@
test "Check that Vary headers are stored"
shell "rm -f /tmp/__v1/_.per"
shell "rm -f ${tmpdir}/_.per"
server s1 {
rxreq
......@@ -13,7 +13,7 @@ server s1 {
varnish v1 \
-arg "-spersistent,/tmp/__v1/_.per,10m" \
-arg "-spersistent,${tmpdir}/_.per,10m" \
-vcl+backend { } -start
client c1 {
......
......@@ -2,19 +2,19 @@
test "Various VCL compiler coverage tests"
shell "true > /tmp/_varnishtest_empty_file"
shell "true > ${tmpdir}/_varnishtest_empty_file"
varnish v1 -vcl {
backend b { .host = "127.0.0.1"; }
include "/tmp/_varnishtest_empty_file" ;
include "${tmpdir}/_varnishtest_empty_file" ;
}
varnish v1 -badvcl {
backend b { .host = "127.0.0.1"; }
include "/tmp/_varnishtest_empty_file" |
include "${tmpdir}/_varnishtest_empty_file" |
}
shell "rm -f /tmp/_varnishtest_empty_file"
shell "rm -f ${tmpdir}/_varnishtest_empty_file"
varnish v1 -badvcl {
backend b { .host = "127.0.0.1"; }
......
......@@ -40,6 +40,8 @@ SVNID("$Id$")
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "compat/asprintf.h"
#include "libvarnish.h"
......@@ -509,6 +511,7 @@ main(int argc, char * const *argv)
static struct vtclog *vl;
double tmax, t0, t00;
const char *nmax;
char *tmpdir, *cmd;
setbuf(stdout, NULL);
setbuf(stderr, NULL);
......@@ -538,6 +541,10 @@ main(int argc, char * const *argv)
init_macro();
init_sema();
tmpdir = tempnam(NULL, "vtc");
AN(tmpdir);
mkdir(tmpdir, 0700);
macro_def(vl, NULL, "tmpdir", tmpdir);
vtc_thread = pthread_self();
tmax = 0;
nmax = NULL;
......@@ -558,6 +565,13 @@ main(int argc, char * const *argv)
break;
}
/* XXX this will always remove the tmpdir even on failures.
* Maybe we should keep it in that case? */
assert(asprintf(&cmd, "rm -rf %s", tmpdir) > 0);
AZ(system(cmd));
free(tmpdir);
free(cmd);
if (vtc_error)
return (2);
......
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