summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2010-03-10 12:19:51 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2010-03-10 12:19:51 +0100
commit5106cbe466781e824846742a036d36ba5f884ad6 (patch)
treec1a3e42dee13ae59daaafcbd415a4973e36d386b
parent4408d4137acfacef57bd2e088a0da83d25e34918 (diff)
downloadrsyslog-5106cbe466781e824846742a036d36ba5f884ad6.tar.gz
rsyslog-5106cbe466781e824846742a036d36ba5f884ad6.tar.xz
rsyslog-5106cbe466781e824846742a036d36ba5f884ad6.zip
added ability to work with larger message sizes to testbench tools
-rw-r--r--tests/chkseq.c26
-rw-r--r--tests/tcpflood.c48
2 files changed, 63 insertions, 11 deletions
diff --git a/tests/chkseq.c b/tests/chkseq.c
index 6334d787..b8088cd5 100644
--- a/tests/chkseq.c
+++ b/tests/chkseq.c
@@ -32,6 +32,7 @@
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <getopt.h>
int main(int argc, char *argv[])
@@ -40,14 +41,18 @@ int main(int argc, char *argv[])
int val;
int i;
int ret = 0;
+ int scanfOK;
int verbose = 0;
+ int bHaveExtraData = 0;
int dupsPermitted = 0;
int start = 0, end = 0;
int opt;
int nDups = 0;
+ int edLen; /* length of extra data */
+ static char edBuf[500*1024]; /* buffer for extra data (pretty large to be on the save side...) */
char *file = NULL;
- while((opt = getopt(argc, argv, "e:f:ds:v")) != EOF) {
+ while((opt = getopt(argc, argv, "e:f:ds:vE")) != EOF) {
switch((char)opt) {
case 'f':
file = optarg;
@@ -64,8 +69,11 @@ int main(int argc, char *argv[])
case 'v':
++verbose;
break;
- default:printf("Invalid call of chkseq\n");
- printf("Usage: chkseq file -sstart -eend -d\n");
+ case 'E':
+ bHaveExtraData = 1;
+ break;
+ default:printf("Invalid call of chkseq, optchar='%c'\n", opt);
+ printf("Usage: chkseq file -sstart -eend -d -E\n");
exit(1);
}
}
@@ -93,7 +101,17 @@ int main(int argc, char *argv[])
}
for(i = start ; i < end+1 ; ++i) {
- if(fscanf(fp, "%d\n", &val) != 1) {
+ if(bHaveExtraData) {
+ scanfOK = fscanf(fp, "%d,%d,%s\n", &val, &edLen, edBuf) == 3 ? 1 : 0;
+ if(edLen != (int) strlen(edBuf)) {
+ printf("extra data length specified %d, but actually is %ld in record %d\n",
+ edLen, (long) strlen(edBuf), i);
+ exit(1);
+ }
+ } else {
+ scanfOK = fscanf(fp, "%d\n", &val) == 1 ? 1 : 0;
+ }
+ if(!scanfOK) {
printf("scanf error in index i=%d\n", i);
exit(1);
}
diff --git a/tests/tcpflood.c b/tests/tcpflood.c
index 308495a5..fcfc30a7 100644
--- a/tests/tcpflood.c
+++ b/tests/tcpflood.c
@@ -7,6 +7,13 @@
* -c number of connections (default 1)
* -m number of messages to send (connection is random)
* -i initial message number (optional)
+ * -P PRI to be used for generated messages (default is 167).
+ * Specify the plain number without leading zeros
+ * -d amount of extra data to add to message. If present, the
+ * number itself will be added as third field, and the data
+ * bytes as forth. Add -r to randomize the amount of extra
+ * data included in the range 1..(value of -d).
+ * -r randomize amount of extra data added (-d must be > 0)
*
* Part of the testbench for rsyslog.
*
@@ -47,8 +54,13 @@
/* Name of input file, must match $IncludeConfig in test suite .conf files */
#define NETTEST_INPUT_CONF_FILE "nettest.input.conf" /* name of input file, must match $IncludeConfig in .conf files */
+#define MAX_EXTRADATA_LEN 100*1024
+
static char *targetIP = "127.0.0.1";
+static char *msgPRI = "167";
static int targetPort = 13514;
+static int extraDataLen = 0; /* amount of extra data to add to message */
+static int bRandomizeExtraData = 0; /* randomize amount of extra data added */
static int numMsgsToSend; /* number of messages to send */
static int numConnections = 1; /* number of connections to create */
static int *sockArray; /* array of sockets to use */
@@ -164,7 +176,9 @@ int sendMessages(void)
int socknum;
int lenBuf;
int lenSend;
- char buf[2048];
+ int edLen; /* actual extra data length to use */
+ char buf[MAX_EXTRADATA_LEN + 1024];
+ char extraData[MAX_EXTRADATA_LEN + 1];
srand(time(NULL)); /* seed is good enough for our needs */
@@ -177,7 +191,19 @@ int sendMessages(void)
socknum = i - (numMsgsToSend - numConnections);
else
socknum = rand() % numConnections;
- lenBuf = sprintf(buf, "<167>Mar 1 01:00:00 172.20.245.8 tag msgnum:%8.8d:\n", msgNum);
+ if(extraDataLen == 0) {
+ lenBuf = sprintf(buf, "<%s>Mar 1 01:00:00 172.20.245.8 tag msgnum:%8.8d:\n",
+ msgPRI, msgNum);
+ } else {
+ if(bRandomizeExtraData)
+ edLen = ((long) rand() + extraDataLen) % extraDataLen + 1;
+ else
+ edLen = extraDataLen;
+ memset(extraData, 'X', edLen);
+ extraData[edLen] = '\0';
+ lenBuf = sprintf(buf, "<%s>Mar 1 01:00:00 172.20.245.8 tag msgnum:%8.8d:%d:%s\n",
+ msgPRI, msgNum, edLen, extraData);
+ }
lenSend = send(sockArray[socknum], buf, lenBuf, 0);
if(lenSend != lenBuf) {
printf("\r%5.5d\n", i);
@@ -251,9 +277,7 @@ tcpSend(char *buf, int lenBuf)
}
-/* Run the test suite. This must be called with exactly one parameter, the
- * name of the test suite. For details, see file header comment at the top
- * of this file.
+/* Run the test.
* rgerhards, 2009-04-03
*/
int main(int argc, char *argv[])
@@ -273,7 +297,7 @@ int main(int argc, char *argv[])
setvbuf(stdout, buf, _IONBF, 48);
- while((opt = getopt(argc, argv, "t:p:c:m:i:")) != -1) {
+ while((opt = getopt(argc, argv, "t:p:c:m:i:P:d:r")) != -1) {
switch (opt) {
case 't': targetIP = optarg;
break;
@@ -285,6 +309,17 @@ int main(int argc, char *argv[])
break;
case 'i': msgNum = atoi(optarg);
break;
+ case 'P': msgPRI = optarg;
+ break;
+ case 'd': extraDataLen = atoi(optarg);
+ if(extraDataLen > MAX_EXTRADATA_LEN) {
+ fprintf(stderr, "-d max is %d!\n",
+ MAX_EXTRADATA_LEN);
+ exit(1);
+ }
+ break;
+ case 'r': bRandomizeExtraData = 1;
+ break;
}
}
@@ -298,7 +333,6 @@ int main(int argc, char *argv[])
exit(1);
}
- //closeConnections();
printf("End of tcpflood Run\n");
exit(ret);