summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2013-10-11 11:04:32 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-10-11 11:38:21 (GMT)
commit791cdf412f5fb66a056aa28b27507fdc9af86507 (patch) (unidiff)
tree9e6c4af696424ea72b51d0b8d9c8cf85c8b43856
parentdf83b714395d41b096f7ad8cc3a090c9341f7598 (diff)
downloadvmod-binlog-791cdf412f5fb66a056aa28b27507fdc9af86507.tar.gz
vmod-binlog-791cdf412f5fb66a056aa28b27507fdc9af86507.tar.bz2
Add testsuite.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile.am4
-rw-r--r--configure.ac8
-rw-r--r--src/binlog.c2
-rw-r--r--src/binlogcat.c18
-rw-r--r--tests/.gitignore6
-rw-r--r--tests/Makefile.am71
-rw-r--r--tests/atlocal.in8
-rw-r--r--tests/test01.at83
-rw-r--r--tests/test02.at83
-rw-r--r--tests/testsuite.at25
10 files changed, 300 insertions, 8 deletions
diff --git a/Makefile.am b/Makefile.am
index 221d1c0..d11b042 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -12,10 +12,10 @@
12# GNU General Public License for more details. 12# GNU General Public License for more details.
13# 13#
14# You should have received a copy of the GNU General Public License 14# You should have received a copy of the GNU General Public License
15# along with vmod-sql. If not, see <http://www.gnu.org/licenses/>. 15# along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>.
16ACLOCAL_AMFLAGS = -I m4 16ACLOCAL_AMFLAGS = -I m4
17 17
18SUBDIRS = src #doc tests 18SUBDIRS = src tests #doc
19 19
20EXTRA_DIST=git2chg.awk 20EXTRA_DIST=git2chg.awk
21 21
diff --git a/configure.ac b/configure.ac
index 2924eae..ea7c061 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,7 +12,7 @@
12# GNU General Public License for more details. 12# GNU General Public License for more details.
13# 13#
14# You should have received a copy of the GNU General Public License 14# You should have received a copy of the GNU General Public License
15# along with vmod-sql. If not, see <http://www.gnu.org/licenses/>. 15# along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>.
16AC_PREREQ(2.69) 16AC_PREREQ(2.69)
17AC_INIT([vmod-binlog], 1.0, [gray@gnu.org]) 17AC_INIT([vmod-binlog], 1.0, [gray@gnu.org])
18AC_CONFIG_AUX_DIR([build-aux]) 18AC_CONFIG_AUX_DIR([build-aux])
@@ -96,7 +96,11 @@ if test -z "$VMODDIR"; then
96 VMODDIR='$(libdir)/varnish/mods' 96 VMODDIR='$(libdir)/varnish/mods'
97fi 97fi
98 98
99 dnl FIXME:tests/Makefile 99# Initialize the test suite.
100AC_CONFIG_TESTDIR(tests)
101AC_CONFIG_FILES([tests/Makefile tests/atlocal])
102AM_MISSING_PROG([AUTOM4TE], [autom4te])
103
100 dnl FIXME:doc/Makefile 104 dnl FIXME:doc/Makefile
101AC_CONFIG_FILES([ 105AC_CONFIG_FILES([
102 Makefile 106 Makefile
diff --git a/src/binlog.c b/src/binlog.c
index f896803..be32e10 100644
--- a/src/binlog.c
+++ b/src/binlog.c
@@ -452,7 +452,7 @@ vmod_append(struct sess *sp, struct vmod_priv *priv, int nid, int aid)
452 return; 452 return;
453 453
454 ts = time(NULL); 454 ts = time(NULL);
455 455
456 if (ts >= conf->stoptime) { 456 if (ts >= conf->stoptime) {
457 AZ(pthread_mutex_lock(&conf->mutex)); 457 AZ(pthread_mutex_lock(&conf->mutex));
458 closefile(sp, conf); 458 closefile(sp, conf);
diff --git a/src/binlogcat.c b/src/binlogcat.c
index c51125b..219f78c 100644
--- a/src/binlogcat.c
+++ b/src/binlogcat.c
@@ -28,6 +28,7 @@ char *progname;
28char *timefmt = "%c"; 28char *timefmt = "%c";
29int number_option; 29int number_option;
30int verbose_option; 30int verbose_option;
31int timediff_option;
31 32
32void 33void
33catlog(const char *fname) 34catlog(const char *fname)
@@ -37,7 +38,8 @@ catlog(const char *fname)
37 struct binlog_record rec; 38 struct binlog_record rec;
38 char timebuf[128]; 39 char timebuf[128];
39 size_t i; 40 size_t i;
40 41 time_t start_ts;
42
41 if (strcmp(fname, "-") == 0) 43 if (strcmp(fname, "-") == 0)
42 fp = stdin; 44 fp = stdin;
43 else { 45 else {
@@ -83,6 +85,12 @@ catlog(const char *fname)
83 break; 85 break;
84 } 86 }
85 87
88 if (timediff_option) {
89 if (i == 0)
90 start_ts = rec.ts;
91 rec.ts -= start_ts;
92 }
93
86 strftime(timebuf, sizeof timebuf, timefmt, localtime(&rec.ts)); 94 strftime(timebuf, sizeof timebuf, timefmt, localtime(&rec.ts));
87 if (number_option) 95 if (number_option)
88 printf("%lu ", (unsigned long) i); 96 printf("%lu ", (unsigned long) i);
@@ -95,7 +103,7 @@ catlog(const char *fname)
95void 103void
96help() 104help()
97{ 105{
98 printf("usage: %s [-hnv] [t FORMAT] [FILE...]\n"); 106 printf("usage: %s [-dhnv] [t FORMAT] [FILE...]\n");
99} 107}
100 108
101int 109int
@@ -104,8 +112,12 @@ main(int argc, char **argv)
104 progname = argv[0]; 112 progname = argv[0];
105 int c; 113 int c;
106 114
107 while ((c = getopt(argc, argv, "ht:nv")) != EOF) 115 while ((c = getopt(argc, argv, "dht:nv")) != EOF)
108 switch (c) { 116 switch (c) {
117 case 'd':
118 timediff_option = 1;
119 timefmt = "%s";
120 break;
109 case 'h': 121 case 'h':
110 help(); 122 help();
111 return 0; 123 return 0;
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 0000000..93f8f46
--- a/dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,6 @@
1atconfig
2atlocal
3package.m4
4testsuite
5testsuite.dir
6testsuite.log
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..7f24aeb
--- a/dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,71 @@
1# This file is part of vmod-binlog
2# Copyright (C) 2013 Sergey Poznyakoff
3#
4# Vmod-binlog is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Vmod-binlog is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>.
16
17EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4
18DISTCLEANFILES = atconfig $(check_SCRIPTS)
19MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE)
20
21
22## ------------ ##
23## package.m4. ##
24## ------------ ##
25
26$(srcdir)/package.m4: $(top_srcdir)/configure.ac
27 $(AM_V_GEN){ \
28 echo '# Signature of the current package.'; \
29 echo 'm4_define([AT_PACKAGE_NAME], [@PACKAGE_NAME@])'; \
30 echo 'm4_define([AT_PACKAGE_TARNAME], [@PACKAGE_TARNAME@])'; \
31 echo 'm4_define([AT_PACKAGE_VERSION], [@PACKAGE_VERSION@])'; \
32 echo 'm4_define([AT_PACKAGE_STRING], [@PACKAGE_STRING@])'; \
33 echo 'm4_define([AT_PACKAGE_BUGREPORT], [@PACKAGE_BUGREPORT@])'; \
34 } >$(srcdir)/package.m4
35
36#
37
38## ------------ ##
39## Test suite. ##
40## ------------ ##
41
42TESTSUITE_AT = \
43 test01.at\
44 test02.at\
45 testsuite.at
46
47TESTSUITE = $(srcdir)/testsuite
48M4=m4
49
50AUTOTEST = $(AUTOM4TE) --language=autotest
51$(TESTSUITE): package.m4 $(TESTSUITE_AT)
52 $(AUTOTEST) -I $(srcdir) testsuite.at -o $@.tmp
53 mv $@.tmp $@
54
55atconfig: $(top_builddir)/config.status
56 cd $(top_builddir) && ./config.status tests/$@
57
58clean-local:
59 test ! -f $(TESTSUITE) || $(SHELL) $(TESTSUITE) --clean
60
61check-local: atconfig atlocal $(TESTSUITE)
62 $(SHELL) $(TESTSUITE)
63
64# Run the test suite on the *installed* tree.
65#installcheck-local:
66 #$(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin
67
68
69
70
71
diff --git a/tests/atlocal.in b/tests/atlocal.in
new file mode 100644
index 0000000..24a523c
--- a/dev/null
+++ b/tests/atlocal.in
@@ -0,0 +1,8 @@
1# @configure_input@ -*- shell-script -*-
2# Configurable variable values for vmod-binlog test suite.
3# Copyright (C) 2013 Sergey Poznyakoff
4
5PATH=@abs_builddir@:@abs_top_builddir@/src:@abs_top_srcdir@/build-aux:$top_srcdir:$srcdir:$PATH
6VARNISHTEST="@VARNISHSRC@/bin/varnishtest/varnishtest -Dvarnishd=@VARNISHSRC@/bin/varnishd/varnishd"
7
8
diff --git a/tests/test01.at b/tests/test01.at
new file mode 100644
index 0000000..116c8f1
--- a/dev/null
+++ b/tests/test01.at
@@ -0,0 +1,83 @@
1# This file is part of vmod-binlog testsuite -*- autotest -*-
2# Copyright (C) 2013 Sergey Poznyakoff
3#
4# Vmod-binlog is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Vmod-binlog is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP([appends])
18AT_KEYWORDS([append])
19
20AT_CHECK([
21cwd=`pwd`
22mkdir log
23
24cat > test.vtc <<EOT
25varnishtest "Appends"
26
27server s1 {
28 rxreq
29 txresp
30} -start
31
32varnish v1 -vcl+backend {
33 import binlog from "$abs_top_builddir/src/.libs/libvmod_binlog.so";
34 sub vcl_init {
35 binlog.init("dir=$cwd/log;size=1M;pattern=logfile");
36 }
37 sub vcl_fini {
38 binlog.close();
39 }
40 sub vcl_recv {
41 binlog.sappend(req.http.X-nid, req.http.X-aid);
42 return (lookup);
43 }
44} -start
45
46client c1 {
47 txreq -url / -hdr "X-nid:1" -hdr "X-aid:0"
48 rxresp
49 expect resp.status == 200
50
51 txreq -url / -hdr "X-nid:1" -hdr "X-aid:1"
52 rxresp
53 expect resp.status == 200
54
55 delay 1.0
56
57 txreq -url / -hdr "X-nid:2" -hdr "X-aid:0"
58 rxresp
59 expect resp.status == 200
60
61 delay 1.0
62
63 txreq -url / -hdr "X-nid:2" -hdr "X-aid:0"
64 rxresp
65 expect resp.status == 200
66}
67
68client c1 -run
69EOT
70
71$VARNISHTEST test.vtc | sed 's/^#.*TEST test.vtc passed.*/OK/'
72binlogcat -d log/logfile
73],
74[0],
75[OK
760 1 0
770 1 1
781 2 0
792 2 0
80])
81
82AT_CLEANUP
83
diff --git a/tests/test02.at b/tests/test02.at
new file mode 100644
index 0000000..df639a5
--- a/dev/null
+++ b/tests/test02.at
@@ -0,0 +1,83 @@
1# This file is part of vmod-binlog testsuite -*- autotest -*-
2# Copyright (C) 2013 Sergey Poznyakoff
3#
4# Vmod-binlog is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Vmod-binlog is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP([log rotation])
18AT_KEYWORDS([rotation])
19
20AT_CHECK([
21cwd=`pwd`
22mkdir log
23
24cat > test.vtc <<EOT
25varnishtest "Log rotation"
26
27server s1 {
28 rxreq
29 txresp
30} -start
31
32varnish v1 -vcl+backend {
33 import binlog from "$abs_top_builddir/src/.libs/libvmod_binlog.so";
34 sub vcl_init {
35 binlog.init("dir=$cwd/log;size=1M;interval=10;roundts=1;pattern=%S.log");
36 }
37 sub vcl_fini {
38 binlog.close();
39 }
40 sub vcl_recv {
41 binlog.sappend(req.http.X-nid, req.http.X-aid);
42 return (lookup);
43 }
44} -start
45
46client c1 {
47 txreq -url / -hdr "X-nid:1" -hdr "X-aid:0"
48 rxresp
49 expect resp.status == 200
50
51 txreq -url / -hdr "X-nid:1" -hdr "X-aid:1"
52 rxresp
53 expect resp.status == 200
54}
55
56client c1 -run
57EOT
58
59sed s/X-nid:1/X-nid:2/ test.vtc > test1.vtc
60
61$VARNISHTEST test.vtc | sed 's/^#.*TEST test.vtc passed.*/OK/'
62sleep 11
63$VARNISHTEST test1.vtc | sed 's/^#.*TEST test1.vtc passed.*/OK/'
64
65find log -name '*.log' | sort | while read file
66do
67 echo "# file"
68 binlogcat -d $file
69done
70],
71[0],
72[OK
73OK
74# file
750 1 0
760 1 1
77# file
780 2 0
790 2 1
80])
81
82AT_CLEANUP
83
diff --git a/tests/testsuite.at b/tests/testsuite.at
new file mode 100644
index 0000000..4f8b786
--- a/dev/null
+++ b/tests/testsuite.at
@@ -0,0 +1,25 @@
1 # This file is part of vmod-binlog -*- autotest -*-
2# Copyright (C) 2013 Sergey Poznyakoff
3#
4# Vmod-binlog is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Vmod-binlog is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>.
16
17m4_version_prereq([2.52g])
18
19m4_define([AT_SKIP_TEST],[exit 77])
20
21AT_INIT
22m4_include([test01.at])
23m4_include([test02.at])
24
25# End of testsuite.at

Return to:

Send suggestions and report system problems to the System administrator.