Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
trackrdrd
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
trackrdrd
Commits
86d00977
Commit
86d00977
authored
Oct 09, 2012
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trackrdrd: Added test_data to make check, TEST_RUNNER to minunit.h
parent
84ab0853
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
217 additions
and
28 deletions
+217
-28
Makefile.am
trackrdrd/Makefile.am
+0
-2
data.c
trackrdrd/src/data.c
+1
-0
Makefile.am
trackrdrd/src/test/Makefile.am
+11
-3
minunit.h
trackrdrd/src/test/minunit.h
+53
-2
regress.sh
trackrdrd/src/test/regress.sh
+2
-1
test_data.c
trackrdrd/src/test/test_data.c
+142
-0
test_parse.c
trackrdrd/src/test/test_parse.c
+8
-20
No files found.
trackrdrd/Makefile.am
View file @
86d00977
...
@@ -3,8 +3,6 @@ ACLOCAL_AMFLAGS = -I m4
...
@@ -3,8 +3,6 @@ ACLOCAL_AMFLAGS = -I m4
SUBDIRS
=
src src/test
SUBDIRS
=
src src/test
EXTRA_DIST
=
README.rst autogen.sh m4/
*
EXTRA_DIST
=
README.rst autogen.sh m4/
*
dist-hook
:
git clean
-f
dist_man_MANS
=
trackrdrd.3
dist_man_MANS
=
trackrdrd.3
MAINTAINERCLEANFILES
=
$(dist_man_MANS)
MAINTAINERCLEANFILES
=
$(dist_man_MANS)
...
...
trackrdrd/src/data.c
View file @
86d00977
...
@@ -158,6 +158,7 @@ DATA_Init(void)
...
@@ -158,6 +158,7 @@ DATA_Init(void)
return
(
0
);
return
(
0
);
}
}
/* XXX: set xid and DATA_OPEN in the entry */
dataentry
dataentry
*
DATA_Insert
(
unsigned
xid
)
*
DATA_Insert
(
unsigned
xid
)
{
{
...
...
trackrdrd/src/test/Makefile.am
View file @
86d00977
INCLUDES
=
-I
$(VARNISHSRC)
/include
-I
$(VARNISHSRC)
INCLUDES
=
-I
$(VARNISHSRC)
/include
-I
$(VARNISHSRC)
TESTS
=
test_parse regress.sh
TESTS
=
test_parse
test_data
regress.sh
check_PROGRAMS
=
test_parse
check_PROGRAMS
=
test_parse
test_data
test_parse_SOURCES
=
\
test_parse_SOURCES
=
\
minunit.h
\
minunit.h
\
...
@@ -11,4 +11,12 @@ test_parse_SOURCES = \
...
@@ -11,4 +11,12 @@ test_parse_SOURCES = \
test_parse_LDADD
=
\
test_parse_LDADD
=
\
-lm
\
-lm
\
../parse.
$(OBJEXT)
../parse.
$(OBJEXT)
\ No newline at end of file
test_data_SOURCES
=
\
minunit.h
\
test_data.c
\
../trackrdrd.h
test_data_LDADD
=
\
../data.
$(OBJEXT)
trackrdrd/src/test/minunit.h
View file @
86d00977
/*-
/*-
* Copied from http://www.jera.com/techinfo/jtns/jtn002.html
* Copyright (c) 2012 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2012 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 <stdlib.h>
/*-
* Adapted from http://www.jera.com/techinfo/jtns/jtn002.html
* "MinUnit" - a minimal unit testing framework for C
* "MinUnit" - a minimal unit testing framework for C
*
*
* "You may use the code in this tech note for any purpose, with the
* "You may use the code in this tech note for any purpose, with the
* understanding that it comes with NO WARRANTY."
* understanding that it comes with NO WARRANTY."
*/
*/
/* XXX: Format error message in mu_assert() */
#define mu_assert(msg, test) do { if (!(test)) return msg; } while (0)
#define mu_assert(msg, test) do { if (!(test)) return msg; } while (0)
#define mu_run_test(test) do { char *msg = test(); tests_run++; \
#define mu_run_test(test) do { c
onst c
har *msg = test(); tests_run++; \
if (msg) return msg; } while (0)
if (msg) return msg; } while (0)
extern
int
tests_run
;
extern
int
tests_run
;
#define TEST_RUNNER \
int \
main(int argc, char **argv) \
{ \
(void) argc; \
\
printf("\nTEST: %s\n", argv[0]); \
const char *result = all_tests(); \
printf("%s: %d tests run\n", argv[0], tests_run); \
if (result != NULL) { \
printf("%s\n", result); \
exit(EXIT_FAILURE); \
} \
exit(EXIT_SUCCESS); \
}
trackrdrd/src/test/regress.sh
View file @
86d00977
...
@@ -11,7 +11,8 @@
...
@@ -11,7 +11,8 @@
# logging to stdout in debug mode, and obtains a cksum from
# logging to stdout in debug mode, and obtains a cksum from
# stdout. The cksum must match an expected value.
# stdout. The cksum must match an expected value.
echo
"
$0
: running"
echo
echo
"TEST:
$0
"
CKSUM
=
$(
../trackrdrd
-f
varnish.binlog
-l
-
-d
-c
test.conf |
cksum
)
CKSUM
=
$(
../trackrdrd
-f
varnish.binlog
-l
-
-d
-c
test.conf |
cksum
)
if
[
"
$CKSUM
"
!=
'3372973632 229022'
]
;
then
if
[
"
$CKSUM
"
!=
'3372973632 229022'
]
;
then
echo
"ERROR: Regression test incorrect cksum:
$CKSUM
"
echo
"ERROR: Regression test incorrect cksum:
$CKSUM
"
...
...
trackrdrd/src/test/test_data.c
0 → 100644
View file @
86d00977
/*-
* Copyright (c) 2012 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2012 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 <string.h>
#include "minunit.h"
#include "../trackrdrd.h"
int
tests_run
=
0
;
static
char
errmsg
[
BUFSIZ
];
/* N.B.: Always run this test first */
static
char
*
test_data_init
(
void
)
{
int
err
;
printf
(
"... testing data table initialization
\n
"
);
config
.
maxopen_scale
=
0
;
config
.
maxdata_scale
=
0
;
err
=
DATA_Init
();
sprintf
(
errmsg
,
"DATA_Init: %s"
,
strerror
(
err
));
mu_assert
(
errmsg
,
err
==
0
);
sprintf
(
errmsg
,
"DATA_Init: expected table length 1024, got %d"
,
tbl
.
len
);
mu_assert
(
errmsg
,
tbl
.
len
==
1024
);
return
NULL
;
}
static
const
char
*
test_data_insert
(
void
)
{
dataentry
*
entry
;
printf
(
"... testing data insert
\n
"
);
entry
=
DATA_Insert
(
1234567890
);
mu_assert
(
"DATA_Insert returned NULL"
,
entry
!=
NULL
);
sprintf
(
errmsg
,
"DATA_Insert: invalid magic number %d"
,
entry
->
magic
);
mu_assert
(
errmsg
,
entry
->
magic
==
DATA_MAGIC
);
mu_assert
(
"DATA_Insert: entry not empty"
,
entry
->
state
==
DATA_EMPTY
);
unsigned
xid
=
1234567890
;
for
(
int
i
=
0
;
i
<
tbl
.
len
;
i
++
)
{
entry
=
DATA_Insert
(
xid
+
i
);
mu_assert
(
"DATA_Insert returned NULL, table not full"
,
entry
!=
NULL
);
entry
->
state
=
DATA_OPEN
;
}
xid
++
;
entry
=
DATA_Insert
(
xid
);
mu_assert
(
"DATA_Insert: table full, expected NULL"
,
entry
==
NULL
);
/* Cleanup */
for
(
int
i
=
0
;
i
<
tbl
.
len
;
i
++
)
tbl
.
entry
[
i
].
state
=
DATA_EMPTY
;
return
NULL
;
}
static
const
char
*
test_data_find
(
void
)
{
dataentry
*
entry1
,
*
entry2
;
unsigned
xid
;
printf
(
"... testing data find
\n
"
);
entry1
=
DATA_Insert
(
1234567890
);
entry1
->
state
=
DATA_OPEN
;
entry1
->
xid
=
1234567890
;
entry2
=
DATA_Find
(
1234567890
);
mu_assert
(
"DATA_Find: returned NULL"
,
entry2
!=
NULL
);
sprintf
(
errmsg
,
"DATA_Find: invalid magic number %d"
,
entry2
->
magic
);
mu_assert
(
errmsg
,
entry2
->
magic
==
DATA_MAGIC
);
sprintf
(
errmsg
,
"DATA_Find: expected XID=1234567890, got %d"
,
entry2
->
xid
);
mu_assert
(
errmsg
,
entry2
->
xid
==
1234567890
);
/* Cleanup */
entry1
->
state
=
DATA_EMPTY
;
entry1
->
xid
=
0
;
entry2
=
DATA_Find
(
1234567890
);
mu_assert
(
"DATA_Find: expected NULL"
,
entry2
==
NULL
);
xid
=
1234567890
;
for
(
int
i
=
0
;
i
<
tbl
.
len
;
i
++
)
{
entry1
=
DATA_Insert
(
xid
);
entry1
->
state
=
DATA_OPEN
;
entry1
->
xid
=
xid
++
;
}
entry2
=
DATA_Find
(
xid
);
mu_assert
(
"DATA_Find: expected NULL"
,
entry2
==
NULL
);
for
(
int
i
=
0
;
i
<
tbl
.
len
;
i
++
)
{
entry2
=
DATA_Find
(
1234567890
+
i
);
sprintf
(
errmsg
,
"DATA_Find: %d, returned NULL"
,
1234567890
+
i
);
mu_assert
(
errmsg
,
entry2
!=
NULL
);
}
return
NULL
;
}
static
const
char
*
all_tests
(
void
)
{
mu_run_test
(
test_data_init
);
mu_run_test
(
test_data_insert
);
mu_run_test
(
test_data_find
);
return
NULL
;
}
TEST_RUNNER
trackrdrd/src/test/test_parse.c
View file @
86d00977
...
@@ -55,7 +55,8 @@ static char
...
@@ -55,7 +55,8 @@ static char
unsigned
xid
=
(
unsigned
int
)
lrand48
();
unsigned
xid
=
(
unsigned
int
)
lrand48
();
if
(
xid
==
0
)
if
(
xid
==
0
)
xid
=
1
;
xid
=
1
;
printf
(
"Parsing %d sequential XIDs from random start
\n
"
,
MAX_RANDOM_XIDS
);
printf
(
"... parsing %d sequential XIDs from random start
\n
"
,
MAX_RANDOM_XIDS
);
for
(
int
i
=
0
;
i
<
MAX_RANDOM_XIDS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
MAX_RANDOM_XIDS
;
i
++
)
{
sprintf
(
s
,
"%d%c"
,
xid
,
(
char
)
random
());
sprintf
(
s
,
"%d%c"
,
xid
,
(
char
)
random
());
...
@@ -77,7 +78,7 @@ static char
...
@@ -77,7 +78,7 @@ static char
unsigned
xid
;
unsigned
xid
;
int
err
;
int
err
;
printf
(
"
T
esting XID corner cases
\n
"
);
printf
(
"
... t
esting XID corner cases
\n
"
);
err
=
Parse_XID
(
"0"
,
1
,
&
xid
);
err
=
Parse_XID
(
"0"
,
1
,
&
xid
);
sprintf
(
errmsg
,
"0: %s"
,
strerror
(
err
));
sprintf
(
errmsg
,
"0: %s"
,
strerror
(
err
));
...
@@ -112,7 +113,7 @@ static char
...
@@ -112,7 +113,7 @@ static char
unsigned
xid
;
unsigned
xid
;
int
err
;
int
err
;
printf
(
"
T
esting Parse_ReqStart
\n
"
);
printf
(
"
... t
esting Parse_ReqStart
\n
"
);
#define REQSTART "127.0.0.1 40756 1253687608"
#define REQSTART "127.0.0.1 40756 1253687608"
err
=
Parse_ReqStart
(
REQSTART
,
strlen
(
REQSTART
),
&
xid
);
err
=
Parse_ReqStart
(
REQSTART
,
strlen
(
REQSTART
),
&
xid
);
...
@@ -134,7 +135,7 @@ static char
...
@@ -134,7 +135,7 @@ static char
unsigned
xid
;
unsigned
xid
;
int
err
;
int
err
;
printf
(
"
T
esting Parse_ReqEnd
\n
"
);
printf
(
"
... t
esting Parse_ReqEnd
\n
"
);
#define REQEND "1253687608 1348291555.658257008 1348291555.670388222 -0.012122154 NaN NaN"
#define REQEND "1253687608 1348291555.658257008 1348291555.670388222 -0.012122154 NaN NaN"
...
@@ -158,7 +159,7 @@ static char
...
@@ -158,7 +159,7 @@ static char
int
err
,
len
;
int
err
,
len
;
char
*
data
;
char
*
data
;
printf
(
"
T
esting Parse_VCL_Log
\n
"
);
printf
(
"
... t
esting Parse_VCL_Log
\n
"
);
#define VCLLOG "1253687608 url=%2Frdrtestapp%2F"
#define VCLLOG "1253687608 url=%2Frdrtestapp%2F"
err
=
Parse_VCL_Log
(
VCLLOG
,
strlen
(
VCLLOG
),
&
xid
,
&
data
,
&
len
);
err
=
Parse_VCL_Log
(
VCLLOG
,
strlen
(
VCLLOG
),
&
xid
,
&
data
,
&
len
);
...
@@ -212,7 +213,7 @@ static char
...
@@ -212,7 +213,7 @@ static char
return
NULL
;
return
NULL
;
}
}
static
char
static
c
onst
c
har
*
all_tests
(
void
)
*
all_tests
(
void
)
{
{
mu_run_test
(
test_random_xids
);
mu_run_test
(
test_random_xids
);
...
@@ -223,17 +224,4 @@ static char
...
@@ -223,17 +224,4 @@ static char
return
NULL
;
return
NULL
;
}
}
int
TEST_RUNNER
main
(
int
argc
,
char
**
argv
)
{
(
void
)
argc
;
printf
(
"%s: running
\n
"
,
argv
[
0
]);
char
*
result
=
all_tests
();
printf
(
"%s: %d tests run
\n
"
,
argv
[
0
],
tests_run
);
if
(
result
!=
NULL
)
{
printf
(
"%s
\n
"
,
result
);
exit
(
EXIT_FAILURE
);
}
exit
(
EXIT_SUCCESS
);
}
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