testbench: add test for disk queue .qi file with wrong queue size

main purpose is to show that a problem occurs. This test will
currently time out.

see also https://github.com/rsyslog/rsyslog/issues/868
This commit is contained in:
Rainer Gerhards 2016-03-30 10:57:12 +02:00
parent e61fbb411f
commit e99ac029ad
4 changed files with 145 additions and 3 deletions

View File

@ -7,7 +7,8 @@ CLEANFILES = \
# TODO: reenable TESTRUNS = rt_init rscript
check_PROGRAMS = $(TESTRUNS) ourtail nettester tcpflood chkseq msleep randomgen \
diagtalker uxsockrcvr syslog_caller inputfilegen minitcpsrv \
omrelp_dflt_port
omrelp_dflt_port \
mangle_qi
TESTS = $(TESTRUNS)
#TESTS = $(TESTRUNS) cfg.sh
@ -61,6 +62,7 @@ TESTS += \
empty-ruleset.sh \
imtcp-multiport.sh \
daqueue-persist.sh \
daqueue-invld-qi.sh \
diskqueue.sh \
diskqueue-fsync.sh \
rulesetmultiqueue.sh \
@ -103,6 +105,7 @@ TESTS += \
dynfile_invalid2.sh \
complex1.sh \
queue-persist.sh \
daqueue-invld-qi.sh \
pipeaction.sh \
execonlyonce.sh \
execonlywhenprevsuspended.sh \
@ -1169,6 +1172,7 @@ EXTRA_DIST= \
ourtail_SOURCES = ourtail.c
msleep_SOURCES = msleep.c
omrelp_dflt_port_SOURCES = omrelp_dflt_port.c
mangle_qi_SOURCES = mangle_qi.c
chkseq_SOURCES = chkseq.c
uxsockrcvr_SOURCES = uxsockrcvr.c

30
tests/daqueue-invld-qi.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
# This file is part of the rsyslog project, released under ASL 2.0
. $srcdir/diag.sh init
#export RSYSLOG_DEBUG="debug nologfuncflow nostdout noprintmutexaction"
#export RSYSLOG_DEBUGLOG="log"
# prepare config
echo \$MainMsgQueueType LinkedList > work-queuemode.conf
echo "*.* :omtesting:sleep 0 1000" > work-delay.conf
# inject 10000 msgs, so that DO hit the high watermark
. $srcdir/diag.sh startup queue-persist.conf
. $srcdir/diag.sh injectmsg 0 10000
. $srcdir/diag.sh shutdown-immediate
. $srcdir/diag.sh wait-shutdown
. $srcdir/diag.sh check-mainq-spool
./mangle_qi -d -q test-spool/mainq.qi > tmp.qi
mv tmp.qi test-spool/mainq.qi
echo "Enter phase 2, rsyslogd restart"
# restart engine and have rest processed
#remove delay
echo "#" > work-delay.conf
. $srcdir/diag.sh startup queue-persist.conf
. $srcdir/diag.sh shutdown-when-empty # shut down rsyslogd when done processing messages
. $srcdir/diag.sh wait-shutdown
. $srcdir/diag.sh seq-check 0 9999
. $srcdir/diag.sh exit

View File

@ -56,7 +56,7 @@ case $1 in
rm -f rsyslog.out.*.log work-presort rsyslog.pipe
rm -f rsyslog.input rsyslog.empty
rm -f testconf.conf
rm -f rsyslog.errorfile
rm -f rsyslog.errorfile tmp.qi
rm -f core.* vgcore.*
# Note: rsyslog.action.*.include must NOT be deleted, as it
# is used to setup some parameters BEFORE calling init. This
@ -84,7 +84,7 @@ case $1 in
rm -f rsyslog.out.*.log rsyslog.random.data work-presort rsyslog.pipe
rm -f rsyslog.input rsyslog.conf.tlscert stat-file1 rsyslog.empty
rm -f testconf.conf
rm -f rsyslog.errorfile
rm -f rsyslog.errorfile tmp.qi
rm -f HOSTNAME imfile-state:.-rsyslog.input
unset TCPFLOOD_EXTRA_OPTS
echo -------------------------------------------------------------------------------

108
tests/mangle_qi.c Normal file
View File

@ -0,0 +1,108 @@
/* rsyslog testbench tool to mangle .qi files
*
* Copyright (C) 2016 by Rainer Gerhards
* Released uner ASL 2.0
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
static int debug = 0;
void
usage(void)
{
fprintf(stderr, "mangle_qi -d -q <.qi-file>\n"
"-d enables debug messages\n");
exit(1);
}
void
processQI(FILE *const __restrict__ qi)
{
char lnbuf[4096];
char propname[64];
int rectype;
int length;
int queuesize;
int i;
int c;
fgets(lnbuf, sizeof(lnbuf), qi);
fputs(lnbuf, stdout);
/* we now read the queue size line */
/* note: this is quick and dirty, no error checks
* are done!
*/
fgetc(qi); /* skip '+' */
for(i = 0 ; (c = fgetc(qi)) != ':' ; ++i) {
propname[i] = c;
}
propname[i] = '\0';
if(strcmp(propname, "iQueueSize")) {
fprintf(stderr, ".qi file format unknown: line 2 does "
"not contain iQueueSize property, instead '%s'\n",
propname);
exit(1);
}
rectype = 0;
for(c = fgetc(qi) ; isdigit(c) ; c = fgetc(qi))
rectype = rectype * 10 + c - '0';
length = 0;
for(c = fgetc(qi) ; isdigit(c) ; c = fgetc(qi))
length = length * 10 + c - '0';
queuesize = 0;
for(c = fgetc(qi) ; isdigit(c) ; c = fgetc(qi))
queuesize = queuesize * 10 + c - '0';
int maxval_for_length = 10;
for(i = 1 ; i < length ; ++i)
maxval_for_length *= 10; /* simulate int-exp() */
if(debug) {
fprintf(stderr, "rectype: %d\n", rectype);
fprintf(stderr, "length: %d\n", length);
fprintf(stderr, "queuesize: %d\n", queuesize);
fprintf(stderr, "maxval_for_length: %d\n", maxval_for_length);
}
queuesize += 1; /* fake invalid queue size */
if(queuesize > maxval_for_length)
++length;
/* ready to go, write mangled queue size */
printf("+%s:%d:%d:%d:", propname, rectype, length, queuesize);
/* copy rest of file */
while((c = fgetc(qi)) != EOF)
putchar(c);
}
int
main(int argc, char *argv[])
{
char *qifile;
FILE *qi;
int opt;
while((opt = getopt(argc, argv, "dq:")) != -1) {
switch (opt) {
case 'q': qifile = optarg;
break;
case 'd': debug = 1;
break;
default: usage();
break;
}
}
if((qi = fopen(qifile, "r")) == NULL) {
perror(qifile);
exit(1);
}
processQI(qi);
return 0;
}