Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnishevent
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
varnishevent
Commits
2723d5bc
Commit
2723d5bc
authored
Apr 13, 2015
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test_writer (just a superficial test for write timeouts)
parent
172f46c9
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
172 additions
and
87 deletions
+172
-87
.gitignore
.gitignore
+1
-0
data.c
src/data.c
+1
-1
format.h
src/format.h
+1
-1
Makefile.am
src/test/Makefile.am
+7
-6
test_writer.c
src/test/test_writer.c
+103
-0
varnishevent.c
src/varnishevent.c
+1
-0
varnishevent.h
src/varnishevent.h
+6
-1
writer.c
src/writer.c
+9
-78
writer.h
src/writer.h
+43
-0
No files found.
.gitignore
View file @
2723d5bc
...
@@ -28,6 +28,7 @@ src/test/.deps/
...
@@ -28,6 +28,7 @@ src/test/.deps/
src/test/test_data
src/test/test_data
src/test/test_strfTIM
src/test/test_strfTIM
src/test/test_format
src/test/test_format
src/test/test_writer
src/varnishevent
src/varnishevent
*.1
*.1
stamp-h1
stamp-h1
src/data.c
View file @
2723d5bc
...
@@ -49,8 +49,8 @@
...
@@ -49,8 +49,8 @@
else if (!VSTAILQ_EMPTY((head2))) { \
else if (!VSTAILQ_EMPTY((head2))) { \
(head2)->vstqh_last = &(head1)->vstqh_first; \
(head2)->vstqh_last = &(head1)->vstqh_first; \
(head1)->vstqh_first = (head2)->vstqh_first; \
(head1)->vstqh_first = (head2)->vstqh_first; \
VSTAILQ_INIT((head2)); \
} \
} \
VSTAILQ_INIT((head2)); \
} while (0)
} while (0)
static
const
char
*
statename
[
3
]
=
{
"EMPTY"
,
"DONE"
};
static
const
char
*
statename
[
3
]
=
{
"EMPTY"
,
"DONE"
};
...
...
src/format.h
View file @
2723d5bc
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
*
*
*/
*/
/* including source must include varnishevent.h */
#include "varnishevent.h"
typedef
struct
arg_t
{
typedef
struct
arg_t
{
char
*
name
;
char
*
name
;
...
...
src/test/Makefile.am
View file @
2723d5bc
AM_CPPFLAGS
=
@VARNISH_CFLAGS@
-I
${
ac_varnish_pkgdataincludedir
}
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
=
\
test_data_SOURCES
=
\
minunit.h
\
minunit.h
\
...
@@ -30,18 +30,19 @@ test_format_LDADD = \
...
@@ -30,18 +30,19 @@ test_format_LDADD = \
test_writer_SOURCES
=
\
test_writer_SOURCES
=
\
minunit.h
\
minunit.h
\
../
writer.c
test_
writer.c
test_writer_LDADD
=
\
test_writer_LDADD
=
\
../config.
$(OBJEXT)
\
../format.
$(OBJEXT)
\
../format.
$(OBJEXT)
\
../log.
$(OBJEXT)
\
../log.
$(OBJEXT)
\
../data.
$(OBJEXT)
\
../data.
$(OBJEXT)
\
../monitor.
$(OBJEXT)
\
../monitor.
$(OBJEXT)
\
../base64.
$(OBJEXT)
\
../base64.
$(OBJEXT)
\
../spscq.
$(OBJEXT)
\
../spscq.
$(OBJEXT)
\
@VARNISH_LIBS@
-lvarnish
../strfTIM.
$(OBJEXT)
\
../writer.
$(OBJEXT)
\
test_writer_CFLAGS
=
-DTEST_DRIVER
@VARNISH_LIBS@ @VARNISH_LIBVARNISH_LIB@
-lvarnish
test_strfTIM_SOURCES
=
\
test_strfTIM_SOURCES
=
\
minunit.h
\
minunit.h
\
...
...
src/test/test_writer.c
0 → 100644
View file @
2723d5bc
/*-
* 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
src/varnishevent.c
View file @
2723d5bc
...
@@ -660,6 +660,7 @@ main(int argc, char *argv[])
...
@@ -660,6 +660,7 @@ main(int argc, char *argv[])
LOG_Log0
(
LOG_WARNING
,
"Varnish log closed"
);
LOG_Log0
(
LOG_WARNING
,
"Varnish log closed"
);
WRT_Halt
();
WRT_Halt
();
WRT_Fini
();
SPSCQ_Shutdown
();
SPSCQ_Shutdown
();
MON_Shutdown
();
MON_Shutdown
();
FMT_Fini
();
FMT_Fini
();
...
...
src/varnishevent.h
View file @
2723d5bc
...
@@ -29,6 +29,9 @@
...
@@ -29,6 +29,9 @@
*
*
*/
*/
#ifndef VARNISHEVENT_H_INCLUDED
#define VARNISHEVENT_H_INCLUDED
#include <stdint.h>
#include <stdint.h>
#include <stdio.h>
#include <stdio.h>
#include <pthread.h>
#include <pthread.h>
...
@@ -263,7 +266,7 @@ int WRT_Running(void);
...
@@ -263,7 +266,7 @@ int WRT_Running(void);
int
WRT_Waiting
(
void
);
int
WRT_Waiting
(
void
);
void
WRT_Reopen
(
void
);
void
WRT_Reopen
(
void
);
void
WRT_Halt
(
void
);
void
WRT_Halt
(
void
);
void
WRT_
Shutdown
(
void
);
void
WRT_
Fini
(
void
);
/* spscq.c */
/* spscq.c */
void
SPSCQ_Enq
(
tx_t
*
ptr
);
void
SPSCQ_Enq
(
tx_t
*
ptr
);
...
@@ -297,3 +300,5 @@ void FMT_Fini(void);
...
@@ -297,3 +300,5 @@ void FMT_Fini(void);
void HNDL_Init(const char *a0);
void HNDL_Init(const char *a0);
void HNDL_Abort(int sig);
void HNDL_Abort(int sig);
#endif
#endif
#endif
src/writer.c
View file @
2723d5bc
/*-
/*-
* Copyright (c) 2013 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2013
-2015
UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2013 Otto Gmbh & Co KG
* Copyright (c) 2013
-2015
Otto Gmbh & Co KG
* All rights reserved
* All rights reserved
* Use only with permission
* Use only with permission
*
*
...
@@ -39,6 +39,7 @@
...
@@ -39,6 +39,7 @@
#include <errno.h>
#include <errno.h>
#include "varnishevent.h"
#include "varnishevent.h"
#include "writer.h"
#include "vas.h"
#include "vas.h"
#include "miniobj.h"
#include "miniobj.h"
...
@@ -64,19 +65,16 @@ static const char* statename[WRT_STATE_E_LIMIT] = {
...
@@ -64,19 +65,16 @@ static const char* statename[WRT_STATE_E_LIMIT] = {
};
};
/* Single writer thread, consumer for the SPSC queue. */
/* 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
unsigned
wrt_nfree
;
static
struct
vsb
*
os
;
static
struct
vsb
*
os
;
static
FILE
*
fo
;
static
FILE
*
fo
;
int
fd
;
static
int
fd
;
fd_set
set
;
static
fd_set
set
;
struct
timeval
to
;
static
struct
timeval
*
timeout
=
NULL
;
struct
timeval
*
timeout
=
NULL
;
static
char
*
obuf
=
NULL
;
static
char
*
obuf
=
NULL
;
static
pthread_mutex_t
reopen_lock
=
PTHREAD_MUTEX_INITIALIZER
;
static
pthread_mutex_t
reopen_lock
=
PTHREAD_MUTEX_INITIALIZER
;
...
@@ -149,7 +147,7 @@ wrt_return_freelist(void)
...
@@ -149,7 +147,7 @@ wrt_return_freelist(void)
}
}
}
}
static
inline
void
void
wrt_write
(
tx_t
*
tx
)
wrt_write
(
tx_t
*
tx
)
{
{
int
errnum
;
int
errnum
;
...
@@ -378,7 +376,7 @@ WRT_Halt(void)
...
@@ -378,7 +376,7 @@ WRT_Halt(void)
}
}
void
void
WRT_
Shutdown
(
void
)
WRT_
Fini
(
void
)
{
{
/* WRT_Halt() must always be called first */
/* WRT_Halt() must always be called first */
AZ
(
run
);
AZ
(
run
);
...
@@ -387,70 +385,3 @@ WRT_Shutdown(void)
...
@@ -387,70 +385,3 @@ WRT_Shutdown(void)
VSB_delete
(
os
);
VSB_delete
(
os
);
AZ
(
pthread_mutex_destroy
(
&
reopen_lock
));
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
src/writer.h
0 → 100644
View file @
2723d5bc
/*-
* 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
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment