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.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
@@ -9,16 +9,16 @@
9# Vmod-binlog is distributed in the hope that it will be useful, 9# Vmod-binlog is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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
22.PHONY: ChangeLog 22.PHONY: ChangeLog
23ChangeLog: 23ChangeLog:
24 $(AM_V_GEN)if test -d .git; then \ 24 $(AM_V_GEN)if test -d .git; then \
diff --git a/configure.ac b/configure.ac
index 2924eae..ea7c061 100644
--- a/configure.ac
+++ b/configure.ac
@@ -9,13 +9,13 @@
9# Vmod-binlog is distributed in the hope that it will be useful, 9# Vmod-binlog is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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])
19AC_CONFIG_MACRO_DIR([m4]) 19AC_CONFIG_MACRO_DIR([m4])
20AC_CONFIG_SRCDIR(src/binlog.c) 20AC_CONFIG_SRCDIR(src/binlog.c)
21AM_CONFIG_HEADER(config.h) 21AM_CONFIG_HEADER(config.h)
@@ -93,13 +93,17 @@ AC_ARG_WITH([vmod-dir],
93 esac]) 93 esac])
94 94
95if test -z "$VMODDIR"; then 95if test -z "$VMODDIR"; then
96 VMODDIR='$(libdir)/varnish/mods' 96 VMODDIR='$(libdir)/varnish/mods'
97fi 97fi
98 98
99dnl 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
100dnl FIXME: doc/Makefile 104dnl FIXME: doc/Makefile
101AC_CONFIG_FILES([ 105AC_CONFIG_FILES([
102 Makefile 106 Makefile
103 src/Makefile 107 src/Makefile
104]) 108])
105AC_OUTPUT 109AC_OUTPUT
diff --git a/src/binlog.c b/src/binlog.c
index f896803..be32e10 100644
--- a/src/binlog.c
+++ b/src/binlog.c
@@ -449,13 +449,13 @@ vmod_append(struct sess *sp, struct vmod_priv *priv, int nid, int aid)
449 time_t ts; 449 time_t ts;
450 450
451 if (!conf) 451 if (!conf)
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);
459 newfile(sp, conf); 459 newfile(sp, conf);
460 AZ(pthread_mutex_unlock(&conf->mutex)); 460 AZ(pthread_mutex_unlock(&conf->mutex));
461 } 461 }
diff --git a/src/binlogcat.c b/src/binlogcat.c
index c51125b..219f78c 100644
--- a/src/binlogcat.c
+++ b/src/binlogcat.c
@@ -25,22 +25,24 @@
25#include "vmod-binlog.h" 25#include "vmod-binlog.h"
26 26
27char *progname; 27char *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)
34{ 35{
35 FILE *fp; 36 FILE *fp;
36 union binlog_header header; 37 union binlog_header header;
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 {
44 fp = fopen(fname, "r"); 46 fp = fopen(fname, "r");
45 if (!fp) { 47 if (!fp) {
46 fprintf(stderr, "%s: cannot open %s: %s\n", 48 fprintf(stderr, "%s: cannot open %s: %s\n",
@@ -80,35 +82,45 @@ catlog(const char *fname)
80 if (fread(&rec, sizeof(rec), 1, fp) != 1) { 82 if (fread(&rec, sizeof(rec), 1, fp) != 1) {
81 fprintf(stderr, "%s: %s: unexpected eof\n", 83 fprintf(stderr, "%s: %s: unexpected eof\n",
82 progname, fname); 84 progname, 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);
89 printf("%s %ld %ld\n", timebuf, rec.nid, rec.aid); 97 printf("%s %ld %ld\n", timebuf, rec.nid, rec.aid);
90 } 98 }
91 99
92 fclose(fp); 100 fclose(fp);
93} 101}
94 102
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
102main(int argc, char **argv) 110main(int argc, char **argv)
103{ 111{
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;
112 case 't': 124 case 't':
113 timefmt = optarg; 125 timefmt = optarg;
114 break; 126 break;
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 0000000..93f8f46
--- /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
--- /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