Commit 97f8d464 authored by Michael Meyling's avatar Michael Meyling

[trackrdrd] test_config: refactoring and some more testing

parent adbbc80d
......@@ -9,9 +9,7 @@ check_PROGRAMS = test_parse test_data test_hash test_mq test_spmcq test_config \
test_parse_SOURCES = \
minunit.h \
test_parse.c \
../trackrdrd.h \
testing.h \
testing.c
../trackrdrd.h
test_parse_LDADD = \
-lm \
......@@ -74,11 +72,12 @@ test_config_SOURCES = \
../config_common.c \
../log.c \
test_config.c \
test_utils.c \
test_utils.h \
../trackrdrd.h
test_config_LDADD = \
$(VARNISHSRC)/lib/libvarnish/libvarnish.la \
testing.$(OBJEXT)
$(VARNISHSRC)/lib/libvarnish/libvarnish.la
test_worker_SOURCES = \
......
......@@ -29,29 +29,37 @@
*
*/
/***** includes ***************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "minunit.h"
#include "testing.h"
#include "test_utils.h"
#include "../trackrdrd.h"
#include "config_common.h"
int tests_run = 0;
/***** defines ****************************************************************/
#define DEFAULT_USER "nobody"
#define DEFAULT_PID_FILE "/var/run/trackrdrd.pid"
#define confdump(str,val) \
i += sprintf(verbose_buffer + i, str"\n", (val))
/***** variables **************************************************************/
int tests_run = 0;
char verbose_buffer[9000];
char * getConfigContent(void);
int saveConfig(const char * fname);
#define confdump(str,val) \
i += sprintf(verbose_buffer + i, str"\n", (val))
/***** functions **************************************************************/
char *
static char *
getConfigContent(void)
{
int i = 0;
......@@ -81,7 +89,8 @@ getConfigContent(void)
return verbose_buffer;
}
int saveConfig(const char * fname)
static int
saveConfig(const char * fname)
{
FILE *fp;
char * content;
......@@ -105,8 +114,8 @@ int saveConfig(const char * fname)
return 0;
}
static char
*test_CONF_Init(void)
static char *
test_CONF_Init(void)
{
printf("... testing CONF_Init\n");
......@@ -120,8 +129,30 @@ static char
}
static char
*test_CONF_ReadDefault(void)
static char *
readAndCompare(const char * confName)
{
int err;
char confNameNew[512];
err = CONF_ReadDefault();
VMASSERT(err == 0, "Error code during reading default config: %i", err);
err = CONF_ReadFile(confName, CONF_Add);
VMASSERT(err == 0, "Error code during reading config \"%s\": %i", confName, err);
// verbose("Config is:\n%s", getConfigContent());
strcpy(confNameNew, confName);
strcat(confNameNew, ".new");
saveConfig(confNameNew);
VMASSERT(TEST_compareFiles(confName, confNameNew),
"Files are not equal: \"%s\" and \"%s\"", confName, confNameNew);
// CONF_Dump();
return NULL;
}
static const char *
test_CONF_ReadDefault(void)
{
printf("... testing CONF_ReadDefault\n");
......@@ -129,23 +160,16 @@ static char
LOG_Open("trackrdrd");
LOG_SetLevel(7);
int err;
err = CONF_ReadDefault();
VMASSERT(err == 0, "Error code during reading default config: %i", err);
err = CONF_ReadFile("trackrdrd.conf", CONF_Add);
VMASSERT(err == 0, "Error code during reading config: %i", err);
// verbose("Config is:\n%s", getConfigContent());
saveConfig("trackrdrd.conf.new");
VMASSERT(TEST_compareFiles("trackrdrd.conf", "trackrdrd.conf.new"),
"Files are not equal: %s %s", "trackrdrd.conf", "trackrdrd.conf.new");
// CONF_Dump();
returnIfNotNull(readAndCompare("trackrdrd_001.conf"));
returnIfNotNull(readAndCompare("trackrdrd_002.conf"));
returnIfNotNull(readAndCompare("trackrdrd_003.conf"));
return NULL;
}
static const char
*all_tests(void)
static const char *
all_tests(void)
{
mu_run_test(test_CONF_Init);
mu_run_test(test_CONF_ReadDefault);
......
......@@ -30,13 +30,13 @@
*/
/**
* Module: testing.c
* Module: test_utils.c
* Description: Contains utilities for testing.
*/
/***** includes ***************************************************************/
#include "testing.h"
#include "test_utils.h"
/***** functions **************************************************************/
......
......@@ -30,12 +30,12 @@
*/
/**
* Module: testing.h
* Module: test_utils.h
* Description: Contains utilities for testing.
*/
#ifndef _TESTING_H
#define _TESTING_H
#ifndef _TEST_UTILS_H
#define _TEST_UTILS_H
/***** includes ***************************************************************/
......@@ -54,6 +54,7 @@
#define verbose(fmt, ...) do{ } while ( 0 )
#endif
#define returnIfNotNull(test) do { const char *msg = test; if (msg) return msg; } while (0)
/***** variables **************************************************************/
......@@ -68,4 +69,4 @@ extern long global_line_pos; /* actual position in input line */
extern int TEST_compareFiles(const char * fname1, const char * fname2);
#endif /* _TESTING_H */
#endif /* _TEST_UTILS_H */
pid.file = /var/opt/run/my/very/deeply/hidden/run/directory/SOME_OTHER_trackrdrd.pid
varnish.name = /var/opt/varnish/var/varnish_pa_proxy/
log.file = testing.log
varnish.bindump =
syslog.facility = LOCAL5
monitor.interval = 300
monitor.workers = false
maxopen.scale = 12
maxdone = 10001
maxdata = 1024
maxkeylen = 124
qlen.goal = 4991
hash.max_probes = 9
hash.ttl = 59
hash.mlt = 12
mq.module = /var/opt/varnish_tracking/lib/trackrdrd/libtrackrdr-activemq.so
mq.config_file = /etc/trackrdr-activemq.conf
nworkers = 2
restarts = 3
thread.restarts = 4
user = nobody
pid.file = trackrdrd.pid
varnish.name = /var/opt/varnish/var/varnish_pa_proxy/
log.file = testing.log
varnish.bindump =
syslog.facility = LOCAL5
monitor.interval = 10000000
monitor.workers = true
maxopen.scale = 12
maxdone = 10001
maxdata = 1024
maxkeylen = 124
qlen.goal = 4991
hash.max_probes = 100
hash.ttl = 59
hash.mlt = 112
mq.module = /var/opt/varnish_tracking/lib/trackrdrd/libtrackrdr-activemq.so
mq.config_file = /etc/trackrdr-activemq.conf
nworkers = 1
restarts = 1
thread.restarts = 1
user = root
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