Commit 14830c75 authored by Geoff Simmons's avatar Geoff Simmons

trackrdrd: Added test_data to make check, TEST_RUNNER to minunit.h

parent 661262fd
......@@ -3,8 +3,6 @@ ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src src/test
EXTRA_DIST = README.rst autogen.sh m4/*
dist-hook:
git clean -f
dist_man_MANS = trackrdrd.3
MAINTAINERCLEANFILES = $(dist_man_MANS)
......
......@@ -158,6 +158,7 @@ DATA_Init(void)
return(0);
}
/* XXX: set xid and DATA_OPEN in the entry */
dataentry
*DATA_Insert(unsigned xid)
{
......
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 = \
minunit.h \
......@@ -11,4 +11,12 @@ test_parse_SOURCES = \
test_parse_LDADD = \
-lm \
../parse.$(OBJEXT)
\ No newline at end of file
../parse.$(OBJEXT)
test_data_SOURCES = \
minunit.h \
test_data.c \
../trackrdrd.h
test_data_LDADD = \
../data.$(OBJEXT)
/*-
* 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
*
* "You may use the code in this tech note for any purpose, with the
* 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_run_test(test) do { char *msg = test(); tests_run++; \
#define mu_run_test(test) do { const char *msg = test(); tests_run++; \
if (msg) return msg; } while (0)
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); \
}
......@@ -11,7 +11,8 @@
# logging to stdout in debug mode, and obtains a cksum from
# 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)
if [ "$CKSUM" != '3372973632 229022' ]; then
echo "ERROR: Regression test incorrect cksum: $CKSUM"
......
/*-
* 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
......@@ -55,7 +55,8 @@ static char
unsigned xid = (unsigned int) lrand48();
if (xid == 0)
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++) {
sprintf(s, "%d%c", xid, (char) random());
......@@ -77,7 +78,7 @@ static char
unsigned xid;
int err;
printf("Testing XID corner cases\n");
printf("... testing XID corner cases\n");
err = Parse_XID("0", 1, &xid);
sprintf(errmsg, "0: %s", strerror(err));
......@@ -112,7 +113,7 @@ static char
unsigned xid;
int err;
printf("Testing Parse_ReqStart\n");
printf("... testing Parse_ReqStart\n");
#define REQSTART "127.0.0.1 40756 1253687608"
err = Parse_ReqStart(REQSTART, strlen(REQSTART), &xid);
......@@ -134,7 +135,7 @@ static char
unsigned xid;
int err;
printf("Testing Parse_ReqEnd\n");
printf("... testing Parse_ReqEnd\n");
#define REQEND "1253687608 1348291555.658257008 1348291555.670388222 -0.012122154 NaN NaN"
......@@ -158,7 +159,7 @@ static char
int err, len;
char *data;
printf("Testing Parse_VCL_Log\n");
printf("... testing Parse_VCL_Log\n");
#define VCLLOG "1253687608 url=%2Frdrtestapp%2F"
err = Parse_VCL_Log(VCLLOG, strlen(VCLLOG), &xid, &data, &len);
......@@ -212,7 +213,7 @@ static char
return NULL;
}
static char
static const char
*all_tests(void)
{
mu_run_test(test_random_xids);
......@@ -223,17 +224,4 @@ static char
return NULL;
}
int
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);
}
TEST_RUNNER
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