aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-10-11 14:04:32 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2013-10-11 14:38:21 +0300
commit791cdf412f5fb66a056aa28b27507fdc9af86507 (patch)
tree9e6c4af696424ea72b51d0b8d9c8cf85c8b43856
parentdf83b714395d41b096f7ad8cc3a090c9341f7598 (diff)
downloadvmod-binlog-791cdf412f5fb66a056aa28b27507fdc9af86507.tar.gz
vmod-binlog-791cdf412f5fb66a056aa28b27507fdc9af86507.tar.bz2
Add testsuite.
-rw-r--r--Makefile.am4
-rw-r--r--configure.ac8
-rw-r--r--src/binlog.c0
-rw-r--r--src/binlogcat.c16
-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, 298 insertions, 6 deletions
diff --git a/Makefile.am b/Makefile.am
index 221d1c0..d11b042 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -12,10 +12,10 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
-# along with vmod-sql. If not, see <http://www.gnu.org/licenses/>.
+# along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>.
ACLOCAL_AMFLAGS = -I m4
-SUBDIRS = src #doc tests
+SUBDIRS = src tests #doc
EXTRA_DIST=git2chg.awk
diff --git a/configure.ac b/configure.ac
index 2924eae..ea7c061 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,7 +12,7 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
-# along with vmod-sql. If not, see <http://www.gnu.org/licenses/>.
+# along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>.
AC_PREREQ(2.69)
AC_INIT([vmod-binlog], 1.0, [gray@gnu.org])
AC_CONFIG_AUX_DIR([build-aux])
@@ -96,7 +96,11 @@ if test -z "$VMODDIR"; then
VMODDIR='$(libdir)/varnish/mods'
fi
-dnl FIXME: tests/Makefile
+# Initialize the test suite.
+AC_CONFIG_TESTDIR(tests)
+AC_CONFIG_FILES([tests/Makefile tests/atlocal])
+AM_MISSING_PROG([AUTOM4TE], [autom4te])
+
dnl FIXME: doc/Makefile
AC_CONFIG_FILES([
Makefile
diff --git a/src/binlog.c b/src/binlog.c
index f896803..be32e10 100644
--- a/src/binlog.c
+++ b/src/binlog.c
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;
char *timefmt = "%c";
int number_option;
int verbose_option;
+int timediff_option;
void
catlog(const char *fname)
@@ -37,6 +38,7 @@ catlog(const char *fname)
struct binlog_record rec;
char timebuf[128];
size_t i;
+ time_t start_ts;
if (strcmp(fname, "-") == 0)
fp = stdin;
@@ -83,6 +85,12 @@ catlog(const char *fname)
break;
}
+ if (timediff_option) {
+ if (i == 0)
+ start_ts = rec.ts;
+ rec.ts -= start_ts;
+ }
+
strftime(timebuf, sizeof timebuf, timefmt, localtime(&rec.ts));
if (number_option)
printf("%lu ", (unsigned long) i);
@@ -95,7 +103,7 @@ catlog(const char *fname)
void
help()
{
- printf("usage: %s [-hnv] [t FORMAT] [FILE...]\n");
+ printf("usage: %s [-dhnv] [t FORMAT] [FILE...]\n");
}
int
@@ -104,8 +112,12 @@ main(int argc, char **argv)
progname = argv[0];
int c;
- while ((c = getopt(argc, argv, "ht:nv")) != EOF)
+ while ((c = getopt(argc, argv, "dht:nv")) != EOF)
switch (c) {
+ case 'd':
+ timediff_option = 1;
+ timefmt = "%s";
+ break;
case 'h':
help();
return 0;
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 0000000..93f8f46
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,6 @@
+atconfig
+atlocal
+package.m4
+testsuite
+testsuite.dir
+testsuite.log
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..7f24aeb
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,71 @@
+# This file is part of vmod-binlog
+# Copyright (C) 2013 Sergey Poznyakoff
+#
+# Vmod-binlog is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Vmod-binlog is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>.
+
+EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4
+DISTCLEANFILES = atconfig $(check_SCRIPTS)
+MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE)
+
+
+## ------------ ##
+## package.m4. ##
+## ------------ ##
+
+$(srcdir)/package.m4: $(top_srcdir)/configure.ac
+ $(AM_V_GEN){ \
+ echo '# Signature of the current package.'; \
+ echo 'm4_define([AT_PACKAGE_NAME], [@PACKAGE_NAME@])'; \
+ echo 'm4_define([AT_PACKAGE_TARNAME], [@PACKAGE_TARNAME@])'; \
+ echo 'm4_define([AT_PACKAGE_VERSION], [@PACKAGE_VERSION@])'; \
+ echo 'm4_define([AT_PACKAGE_STRING], [@PACKAGE_STRING@])'; \
+ echo 'm4_define([AT_PACKAGE_BUGREPORT], [@PACKAGE_BUGREPORT@])'; \
+ } >$(srcdir)/package.m4
+
+#
+
+## ------------ ##
+## Test suite. ##
+## ------------ ##
+
+TESTSUITE_AT = \
+ test01.at\
+ test02.at\
+ testsuite.at
+
+TESTSUITE = $(srcdir)/testsuite
+M4=m4
+
+AUTOTEST = $(AUTOM4TE) --language=autotest
+$(TESTSUITE): package.m4 $(TESTSUITE_AT)
+ $(AUTOTEST) -I $(srcdir) testsuite.at -o $@.tmp
+ mv $@.tmp $@
+
+atconfig: $(top_builddir)/config.status
+ cd $(top_builddir) && ./config.status tests/$@
+
+clean-local:
+ test ! -f $(TESTSUITE) || $(SHELL) $(TESTSUITE) --clean
+
+check-local: atconfig atlocal $(TESTSUITE)
+ $(SHELL) $(TESTSUITE)
+
+# Run the test suite on the *installed* tree.
+#installcheck-local:
+# $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin
+
+
+
+
+
diff --git a/tests/atlocal.in b/tests/atlocal.in
new file mode 100644
index 0000000..24a523c
--- /dev/null
+++ b/tests/atlocal.in
@@ -0,0 +1,8 @@
+# @configure_input@ -*- shell-script -*-
+# Configurable variable values for vmod-binlog test suite.
+# Copyright (C) 2013 Sergey Poznyakoff
+
+PATH=@abs_builddir@:@abs_top_builddir@/src:@abs_top_srcdir@/build-aux:$top_srcdir:$srcdir:$PATH
+VARNISHTEST="@VARNISHSRC@/bin/varnishtest/varnishtest -Dvarnishd=@VARNISHSRC@/bin/varnishd/varnishd"
+
+
diff --git a/tests/test01.at b/tests/test01.at
new file mode 100644
index 0000000..116c8f1
--- /dev/null
+++ b/tests/test01.at
@@ -0,0 +1,83 @@
+# This file is part of vmod-binlog testsuite -*- autotest -*-
+# Copyright (C) 2013 Sergey Poznyakoff
+#
+# Vmod-binlog is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Vmod-binlog is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([appends])
+AT_KEYWORDS([append])
+
+AT_CHECK([
+cwd=`pwd`
+mkdir log
+
+cat > test.vtc <<EOT
+varnishtest "Appends"
+
+server s1 {
+ rxreq
+ txresp
+} -start
+
+varnish v1 -vcl+backend {
+ import binlog from "$abs_top_builddir/src/.libs/libvmod_binlog.so";
+ sub vcl_init {
+ binlog.init("dir=$cwd/log;size=1M;pattern=logfile");
+ }
+ sub vcl_fini {
+ binlog.close();
+ }
+ sub vcl_recv {
+ binlog.sappend(req.http.X-nid, req.http.X-aid);
+ return (lookup);
+ }
+} -start
+
+client c1 {
+ txreq -url / -hdr "X-nid:1" -hdr "X-aid:0"
+ rxresp
+ expect resp.status == 200
+
+ txreq -url / -hdr "X-nid:1" -hdr "X-aid:1"
+ rxresp
+ expect resp.status == 200
+
+ delay 1.0
+
+ txreq -url / -hdr "X-nid:2" -hdr "X-aid:0"
+ rxresp
+ expect resp.status == 200
+
+ delay 1.0
+
+ txreq -url / -hdr "X-nid:2" -hdr "X-aid:0"
+ rxresp
+ expect resp.status == 200
+}
+
+client c1 -run
+EOT
+
+$VARNISHTEST test.vtc | sed 's/^#.*TEST test.vtc passed.*/OK/'
+binlogcat -d log/logfile
+],
+[0],
+[OK
+0 1 0
+0 1 1
+1 2 0
+2 2 0
+])
+
+AT_CLEANUP
+
diff --git a/tests/test02.at b/tests/test02.at
new file mode 100644
index 0000000..df639a5
--- /dev/null
+++ b/tests/test02.at
@@ -0,0 +1,83 @@
+# This file is part of vmod-binlog testsuite -*- autotest -*-
+# Copyright (C) 2013 Sergey Poznyakoff
+#
+# Vmod-binlog is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Vmod-binlog is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([log rotation])
+AT_KEYWORDS([rotation])
+
+AT_CHECK([
+cwd=`pwd`
+mkdir log
+
+cat > test.vtc <<EOT
+varnishtest "Log rotation"
+
+server s1 {
+ rxreq
+ txresp
+} -start
+
+varnish v1 -vcl+backend {
+ import binlog from "$abs_top_builddir/src/.libs/libvmod_binlog.so";
+ sub vcl_init {
+ binlog.init("dir=$cwd/log;size=1M;interval=10;roundts=1;pattern=%S.log");
+ }
+ sub vcl_fini {
+ binlog.close();
+ }
+ sub vcl_recv {
+ binlog.sappend(req.http.X-nid, req.http.X-aid);
+ return (lookup);
+ }
+} -start
+
+client c1 {
+ txreq -url / -hdr "X-nid:1" -hdr "X-aid:0"
+ rxresp
+ expect resp.status == 200
+
+ txreq -url / -hdr "X-nid:1" -hdr "X-aid:1"
+ rxresp
+ expect resp.status == 200
+}
+
+client c1 -run
+EOT
+
+sed s/X-nid:1/X-nid:2/ test.vtc > test1.vtc
+
+$VARNISHTEST test.vtc | sed 's/^#.*TEST test.vtc passed.*/OK/'
+sleep 11
+$VARNISHTEST test1.vtc | sed 's/^#.*TEST test1.vtc passed.*/OK/'
+
+find log -name '*.log' | sort | while read file
+do
+ echo "# file"
+ binlogcat -d $file
+done
+],
+[0],
+[OK
+OK
+# file
+0 1 0
+0 1 1
+# file
+0 2 0
+0 2 1
+])
+
+AT_CLEANUP
+
diff --git a/tests/testsuite.at b/tests/testsuite.at
new file mode 100644
index 0000000..4f8b786
--- /dev/null
+++ b/tests/testsuite.at
@@ -0,0 +1,25 @@
+# This file is part of vmod-binlog -*- autotest -*-
+# Copyright (C) 2013 Sergey Poznyakoff
+#
+# Vmod-binlog is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Vmod-binlog is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>.
+
+m4_version_prereq([2.52g])
+
+m4_define([AT_SKIP_TEST],[exit 77])
+
+AT_INIT
+m4_include([test01.at])
+m4_include([test02.at])
+
+# End of testsuite.at

Return to:

Send suggestions and report system problems to the System administrator.