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 \ ...@@ -9,9 +9,7 @@ check_PROGRAMS = test_parse test_data test_hash test_mq test_spmcq test_config \
test_parse_SOURCES = \ test_parse_SOURCES = \
minunit.h \ minunit.h \
test_parse.c \ test_parse.c \
../trackrdrd.h \ ../trackrdrd.h
testing.h \
testing.c
test_parse_LDADD = \ test_parse_LDADD = \
-lm \ -lm \
...@@ -74,11 +72,12 @@ test_config_SOURCES = \ ...@@ -74,11 +72,12 @@ test_config_SOURCES = \
../config_common.c \ ../config_common.c \
../log.c \ ../log.c \
test_config.c \ test_config.c \
test_utils.c \
test_utils.h \
../trackrdrd.h ../trackrdrd.h
test_config_LDADD = \ test_config_LDADD = \
$(VARNISHSRC)/lib/libvarnish/libvarnish.la \ $(VARNISHSRC)/lib/libvarnish/libvarnish.la
testing.$(OBJEXT)
test_worker_SOURCES = \ test_worker_SOURCES = \
......
...@@ -29,29 +29,37 @@ ...@@ -29,29 +29,37 @@
* *
*/ */
/***** includes ***************************************************************/
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "minunit.h" #include "minunit.h"
#include "testing.h" #include "test_utils.h"
#include "../trackrdrd.h" #include "../trackrdrd.h"
#include "config_common.h" #include "config_common.h"
int tests_run = 0;
/***** defines ****************************************************************/
#define DEFAULT_USER "nobody" #define DEFAULT_USER "nobody"
#define DEFAULT_PID_FILE "/var/run/trackrdrd.pid" #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 verbose_buffer[9000];
char * getConfigContent(void);
int saveConfig(const char * fname);
#define confdump(str,val) \ /***** functions **************************************************************/
i += sprintf(verbose_buffer + i, str"\n", (val))
char * static char *
getConfigContent(void) getConfigContent(void)
{ {
int i = 0; int i = 0;
...@@ -81,7 +89,8 @@ getConfigContent(void) ...@@ -81,7 +89,8 @@ getConfigContent(void)
return verbose_buffer; return verbose_buffer;
} }
int saveConfig(const char * fname) static int
saveConfig(const char * fname)
{ {
FILE *fp; FILE *fp;
char * content; char * content;
...@@ -105,8 +114,8 @@ int saveConfig(const char * fname) ...@@ -105,8 +114,8 @@ int saveConfig(const char * fname)
return 0; return 0;
} }
static char static char *
*test_CONF_Init(void) test_CONF_Init(void)
{ {
printf("... testing CONF_Init\n"); printf("... testing CONF_Init\n");
...@@ -120,8 +129,30 @@ static char ...@@ -120,8 +129,30 @@ static char
} }
static char static char *
*test_CONF_ReadDefault(void) 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"); printf("... testing CONF_ReadDefault\n");
...@@ -129,23 +160,16 @@ static char ...@@ -129,23 +160,16 @@ static char
LOG_Open("trackrdrd"); LOG_Open("trackrdrd");
LOG_SetLevel(7); LOG_SetLevel(7);
int err; returnIfNotNull(readAndCompare("trackrdrd_001.conf"));
err = CONF_ReadDefault(); returnIfNotNull(readAndCompare("trackrdrd_002.conf"));
VMASSERT(err == 0, "Error code during reading default config: %i", err); returnIfNotNull(readAndCompare("trackrdrd_003.conf"));
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();
return NULL; return NULL;
} }
static const char static const char *
*all_tests(void) all_tests(void)
{ {
mu_run_test(test_CONF_Init); mu_run_test(test_CONF_Init);
mu_run_test(test_CONF_ReadDefault); mu_run_test(test_CONF_ReadDefault);
......
...@@ -30,13 +30,13 @@ ...@@ -30,13 +30,13 @@
*/ */
/** /**
* Module: testing.c * Module: test_utils.c
* Description: Contains utilities for testing. * Description: Contains utilities for testing.
*/ */
/***** includes ***************************************************************/ /***** includes ***************************************************************/
#include "testing.h" #include "test_utils.h"
/***** functions **************************************************************/ /***** functions **************************************************************/
......
...@@ -30,12 +30,12 @@ ...@@ -30,12 +30,12 @@
*/ */
/** /**
* Module: testing.h * Module: test_utils.h
* Description: Contains utilities for testing. * Description: Contains utilities for testing.
*/ */
#ifndef _TESTING_H #ifndef _TEST_UTILS_H
#define _TESTING_H #define _TEST_UTILS_H
/***** includes ***************************************************************/ /***** includes ***************************************************************/
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
#define verbose(fmt, ...) do{ } while ( 0 ) #define verbose(fmt, ...) do{ } while ( 0 )
#endif #endif
#define returnIfNotNull(test) do { const char *msg = test; if (msg) return msg; } while (0)
/***** variables **************************************************************/ /***** variables **************************************************************/
...@@ -68,4 +69,4 @@ extern long global_line_pos; /* actual position in input line */ ...@@ -68,4 +69,4 @@ extern long global_line_pos; /* actual position in input line */
extern int TEST_compareFiles(const char * fname1, const char * fname2); 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