diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-10-11 14:04:32 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-10-11 14:38:21 +0300 |
commit | 791cdf412f5fb66a056aa28b27507fdc9af86507 (patch) | |
tree | 9e6c4af696424ea72b51d0b8d9c8cf85c8b43856 | |
parent | df83b714395d41b096f7ad8cc3a090c9341f7598 (diff) | |
download | vmod-binlog-791cdf412f5fb66a056aa28b27507fdc9af86507.tar.gz vmod-binlog-791cdf412f5fb66a056aa28b27507fdc9af86507.tar.bz2 |
Add testsuite.
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | configure.ac | 8 | ||||
-rw-r--r-- | src/binlog.c | 2 | ||||
-rw-r--r-- | src/binlogcat.c | 18 | ||||
-rw-r--r-- | tests/.gitignore | 6 | ||||
-rw-r--r-- | tests/Makefile.am | 71 | ||||
-rw-r--r-- | tests/atlocal.in | 8 | ||||
-rw-r--r-- | tests/test01.at | 83 | ||||
-rw-r--r-- | tests/test02.at | 83 | ||||
-rw-r--r-- | tests/testsuite.at | 25 |
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/>. |
16 | ACLOCAL_AMFLAGS = -I m4 | 16 | ACLOCAL_AMFLAGS = -I m4 |
17 | 17 | ||
18 | SUBDIRS = src #doc tests | 18 | SUBDIRS = src tests #doc |
19 | 19 | ||
20 | EXTRA_DIST=git2chg.awk | 20 | EXTRA_DIST=git2chg.awk |
21 | 21 | ||
22 | .PHONY: ChangeLog | 22 | .PHONY: ChangeLog |
23 | ChangeLog: | 23 | ChangeLog: |
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/>. |
16 | AC_PREREQ(2.69) | 16 | AC_PREREQ(2.69) |
17 | AC_INIT([vmod-binlog], 1.0, [gray@gnu.org]) | 17 | AC_INIT([vmod-binlog], 1.0, [gray@gnu.org]) |
18 | AC_CONFIG_AUX_DIR([build-aux]) | 18 | AC_CONFIG_AUX_DIR([build-aux]) |
19 | AC_CONFIG_MACRO_DIR([m4]) | 19 | AC_CONFIG_MACRO_DIR([m4]) |
20 | AC_CONFIG_SRCDIR(src/binlog.c) | 20 | AC_CONFIG_SRCDIR(src/binlog.c) |
21 | AM_CONFIG_HEADER(config.h) | 21 | AM_CONFIG_HEADER(config.h) |
@@ -93,13 +93,17 @@ AC_ARG_WITH([vmod-dir], | |||
93 | esac]) | 93 | esac]) |
94 | 94 | ||
95 | if test -z "$VMODDIR"; then | 95 | if test -z "$VMODDIR"; then |
96 | VMODDIR='$(libdir)/varnish/mods' | 96 | VMODDIR='$(libdir)/varnish/mods' |
97 | fi | 97 | fi |
98 | 98 | ||
99 | dnl FIXME: tests/Makefile | 99 | # Initialize the test suite. |
100 | AC_CONFIG_TESTDIR(tests) | ||
101 | AC_CONFIG_FILES([tests/Makefile tests/atlocal]) | ||
102 | AM_MISSING_PROG([AUTOM4TE], [autom4te]) | ||
103 | |||
100 | dnl FIXME: doc/Makefile | 104 | dnl FIXME: doc/Makefile |
101 | AC_CONFIG_FILES([ | 105 | AC_CONFIG_FILES([ |
102 | Makefile | 106 | Makefile |
103 | src/Makefile | 107 | src/Makefile |
104 | ]) | 108 | ]) |
105 | AC_OUTPUT | 109 | AC_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 | ||
27 | char *progname; | 27 | char *progname; |
28 | char *timefmt = "%c"; | 28 | char *timefmt = "%c"; |
29 | int number_option; | 29 | int number_option; |
30 | int verbose_option; | 30 | int verbose_option; |
31 | int timediff_option; | ||
31 | 32 | ||
32 | void | 33 | void |
33 | catlog(const char *fname) | 34 | catlog(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 | ||
95 | void | 103 | void |
96 | help() | 104 | help() |
97 | { | 105 | { |
98 | printf("usage: %s [-hnv] [t FORMAT] [FILE...]\n"); | 106 | printf("usage: %s [-dhnv] [t FORMAT] [FILE...]\n"); |
99 | } | 107 | } |
100 | 108 | ||
101 | int | 109 | int |
102 | main(int argc, char **argv) | 110 | main(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 @@ | |||
1 | atconfig | ||
2 | atlocal | ||
3 | package.m4 | ||
4 | testsuite | ||
5 | testsuite.dir | ||
6 | 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 @@ | |||
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 | <