Commit 2723d5bc authored by Geoff Simmons's avatar Geoff Simmons

add test_writer (just a superficial test for write timeouts)

parent 172f46c9
......@@ -28,6 +28,7 @@ src/test/.deps/
src/test/test_data
src/test/test_strfTIM
src/test/test_format
src/test/test_writer
src/varnishevent
*.1
stamp-h1
......@@ -49,8 +49,8 @@
else if (!VSTAILQ_EMPTY((head2))) { \
(head2)->vstqh_last = &(head1)->vstqh_first; \
(head1)->vstqh_first = (head2)->vstqh_first; \
VSTAILQ_INIT((head2)); \
} \
VSTAILQ_INIT((head2)); \
} while (0)
static const char *statename[3] = { "EMPTY", "DONE" };
......
......@@ -29,7 +29,7 @@
*
*/
/* including source must include varnishevent.h */
#include "varnishevent.h"
typedef struct arg_t {
char *name;
......
AM_CPPFLAGS = @VARNISH_CFLAGS@ -I ${ac_varnish_pkgdataincludedir}
TESTS = test_data test_strfTIM test_format # test_writer regress.sh ncsa.sh vslarg.sh
TESTS = test_data test_strfTIM test_format test_writer # regress.sh ncsa.sh vslarg.sh
check_PROGRAMS = test_data test_strfTIM test_format # test_writer
check_PROGRAMS = test_data test_strfTIM test_format test_writer
test_data_SOURCES = \
minunit.h \
......@@ -30,18 +30,19 @@ test_format_LDADD = \
test_writer_SOURCES = \
minunit.h \
../writer.c
test_writer.c
test_writer_LDADD = \
../config.$(OBJEXT) \
../format.$(OBJEXT) \
../log.$(OBJEXT) \
../data.$(OBJEXT) \
../monitor.$(OBJEXT) \
../base64.$(OBJEXT) \
../spscq.$(OBJEXT) \
@VARNISH_LIBS@ -lvarnish
test_writer_CFLAGS = -DTEST_DRIVER
../strfTIM.$(OBJEXT) \
../writer.$(OBJEXT) \
@VARNISH_LIBS@ @VARNISH_LIBVARNISH_LIB@ -lvarnish
test_strfTIM_SOURCES = \
minunit.h \
......
/*-
* Copyright (c) 2015 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2015 Otto Gmbh & Co KG
* All rights reserved
* Use only with permission
*
* Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include "../varnishevent.h"
#include "../writer.h"
#include "minunit.h"
int tests_run = 0;
static char errmsg[BUFSIZ];
#define THRESHOLD 1000
int
RDR_Waiting(void)
{
return 0;
}
void
RDR_Stats(void)
{}
static char
*test_timeout(void)
{
tx_t tx;
logline_t rec;
chunk_t chunk;
printf("... testing write timeouts\n");
CONF_Init();
strcpy(config.cformat, "");
MAZ(FMT_Init(&errmsg[0]));
strcpy(config.log_file, "-");
MAZ(LOG_Open("test_writer"));
config.output_timeout.tv_sec = 1;
config.output_timeout.tv_usec = 0;
MAZ(WRT_Init());
VSTAILQ_INIT(&wrt_freelist);
MASSERT(VSTAILQ_EMPTY(&wrt_freelist));
/* XXX: common helper functions with test_format */
tx.magic = TX_MAGIC;
VSTAILQ_INIT(&tx.lines);
VSTAILQ_INSERT_TAIL(&tx.lines, &rec, linelist);
rec.magic = LOGLINE_MAGIC;
VSTAILQ_INIT(&rec.chunks);
VSTAILQ_INSERT_TAIL(&rec.chunks, &chunk, chunklist);
chunk.magic = CHUNK_MAGIC;
chunk.data = (char *) calloc(1, config.chunk_size);
for (int i = 0; i < THRESHOLD; i++) {
tx.state = DATA_DONE;
tx.type = VSL_t_req;
wrt_write(&tx);
MAZ(to.tv_sec);
MASSERT(1e6 - to.tv_usec < THRESHOLD);
}
return NULL;
}
static const char
*all_tests(void)
{
mu_run_test(test_timeout);
return NULL;
}
TEST_RUNNER
......@@ -660,6 +660,7 @@ main(int argc, char *argv[])
LOG_Log0(LOG_WARNING, "Varnish log closed");
WRT_Halt();
WRT_Fini();
SPSCQ_Shutdown();
MON_Shutdown();
FMT_Fini();
......
......@@ -29,6 +29,9 @@
*
*/
#ifndef VARNISHEVENT_H_INCLUDED
#define VARNISHEVENT_H_INCLUDED
#include <stdint.h>
#include <stdio.h>
#include <pthread.h>
......@@ -263,7 +266,7 @@ int WRT_Running(void);
int WRT_Waiting(void);
void WRT_Reopen(void);
void WRT_Halt(void);
void WRT_Shutdown(void);
void WRT_Fini(void);
/* spscq.c */
void SPSCQ_Enq(tx_t *ptr);
......@@ -297,3 +300,5 @@ void FMT_Fini(void);
void HNDL_Init(const char *a0);
void HNDL_Abort(int sig);
#endif
#endif
/*-
* Copyright (c) 2013 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2013 Otto Gmbh & Co KG
* Copyright (c) 2013-2015 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2013-2015 Otto Gmbh & Co KG
* All rights reserved
* Use only with permission
*
......@@ -39,6 +39,7 @@
#include <errno.h>
#include "varnishevent.h"
#include "writer.h"
#include "vas.h"
#include "miniobj.h"
......@@ -64,19 +65,16 @@ static const char* statename[WRT_STATE_E_LIMIT] = {
};
/* Single writer thread, consumer for the SPSC queue. */
pthread_t writer;
static pthread_t writer;
/* local freelist - return space in chunks */
static struct txhead_s wrt_freelist;
static unsigned wrt_nfree;
static struct vsb *os;
static FILE *fo;
int fd;
fd_set set;
struct timeval to;
struct timeval *timeout = NULL;
static int fd;
static fd_set set;
static struct timeval *timeout = NULL;
static char *obuf = NULL;
static pthread_mutex_t reopen_lock = PTHREAD_MUTEX_INITIALIZER;
......@@ -149,7 +147,7 @@ wrt_return_freelist(void)
}
}
static inline void
void
wrt_write(tx_t *tx)
{
int errnum;
......@@ -378,7 +376,7 @@ WRT_Halt(void)
}
void
WRT_Shutdown(void)
WRT_Fini(void)
{
/* WRT_Halt() must always be called first */
AZ(run);
......@@ -387,70 +385,3 @@ WRT_Shutdown(void)
VSB_delete(os);
AZ(pthread_mutex_destroy(&reopen_lock));
}
#ifdef TEST_DRIVER
#include "minunit.h"
int tests_run = 0;
static char errmsg[BUFSIZ];
#define THRESHOLD 1000
int
RDR_Waiting(void)
{
return 0;
}
void
RDR_Stats(void)
{}
static char
*test_timeout(void)
{
logline_t ll;
printf("... testing write timeouts\n");
strcpy(config.cformat, "");
MAZ(FMT_Init(&errmsg[0]));
strcpy(config.log_file, "-");
MAZ(LOG_Open("test_writer"));
config.output_timeout.tv_sec = 1;
config.output_timeout.tv_usec = 0;
MAZ(WRT_Init());
VSTAILQ_INIT(&wrt_freelist);
MASSERT(VSTAILQ_EMPTY(&wrt_freelist));
for (int i = 0; i < THRESHOLD; i++) {
ll.magic = LOGLINE_MAGIC;
ll.state = DATA_DONE;
ll.spec = VSL_S_CLIENT;
ll.rx_headers = NULL;
ll.tx_headers = NULL;
ll.vcl_log = NULL;
ll.vcl_call = NULL;
wrt_write(&ll);
MAZ(to.tv_sec);
MASSERT(1e6 - to.tv_usec < THRESHOLD);
}
return NULL;
}
static const char
*all_tests(void)
{
mu_run_test(test_timeout);
return NULL;
}
TEST_RUNNER
#endif
/*-
* Copyright (c) 2015 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2015 Otto Gmbh & Co KG
* All rights reserved.
* Use only with permission
*
* Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include "varnishevent.h"
/* local freelist - return space in chunks */
struct txhead_s wrt_freelist;
/*
* Set to the write timeout, and indicates the time elapsed after the
* select() call.
*/
struct timeval to;
void wrt_write(tx_t *tx);
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