Skip to content

Commit 1b2ffd5

Browse files
committed
testbench: add test for receiver abort and restart
Also - much improved testbench framework and tools to support this type of test. Done some general improvements to the tooling. - imported rsyslog tool "chkseq" for checking - added more error messages to code still not fully done and probably needs some review. but even for testbench runs the current set of error messages was too small to be useful. see also rsyslog#130
1 parent 3e91258 commit 1b2ffd5

File tree

13 files changed

+509
-60
lines changed

13 files changed

+509
-60
lines changed

configure.ac

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44
AC_PREREQ(2.61)
55
AC_INIT([librelp], [1.2.19.master], [[email protected]])
6-
AM_INIT_AUTOMAKE
7-
AM_INIT_AUTOMAKE
6+
7+
# change to the one below if Travis has a timeout
8+
#AM_INIT_AUTOMAKE([subdir-objects serial-tests])
9+
AM_INIT_AUTOMAKE([subdir-objects])
10+
811
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
912
AC_CONFIG_SRCDIR([src/relp.c])
1013
AC_CONFIG_HEADER([config.h])

src/copen.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ BEGINcommand(S, Init)
143143
relpSessSendResponse(pSess, pFrame->txnr, replymsg, sizeof(replymsg) - 1);
144144
ABORT_FINALIZE(RELP_RET_SESSION_OPEN);
145145
}
146-
147146
CHKRet(relpOffersConstructFromFrame(&pCltOffers, pFrame));
148147
CHKRet(selectOffers(pSess, pCltOffers, &pSrvOffers));
149148

src/relpsess.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "relp.h"
5252
#include "relpsess.h"
5353
#include "relpframe.h"
54+
#include "relpclt.h"
5455
#include "sendq.h"
5556
#include "offers.h"
5657
#include "dbllinklist.h"
@@ -67,25 +68,24 @@ callOnErr(const relpSess_t *__restrict__ const pThis,
6768
const relpRetVal ecode)
6869
{
6970
char objinfo[1024];
71+
relpTcp_t *const pTcp = pThis->pTcp;
7072
//pThis->pEngine->dbgprint("librelp: generic error: ecode %d, "
7173
//"emsg '%s'\n", ecode, emsg);
7274
if(pThis->pEngine->onErr != NULL) {
73-
#if 0 // TODO: FIXME
74-
if(pThis->pSrv == NULL) { /* client */
75+
if(pTcp->pSrv == NULL) { /* client */
7576
snprintf(objinfo, sizeof(objinfo), "conn to srvr %s:%s",
76-
pThis->pClt->pSess->srvAddr,
77-
pThis->pClt->pSess->srvPort);
78-
} else if(pThis->pRemHostIP == NULL) { /* server listener */
77+
pTcp->pClt->pSess->srvAddr,
78+
pTcp->pClt->pSess->srvPort);
79+
} else if(pTcp->pRemHostIP == NULL) { /* server listener */
7980
snprintf(objinfo, sizeof(objinfo), "lstn %s",
80-
pThis->pSrv->pLstnPort);
81+
pTcp->pSrv->pLstnPort);
8182
} else { /* server connection to client */
8283
snprintf(objinfo, sizeof(objinfo), "lstn %s: conn to clt %s/%s",
83-
pThis->pSrv->pLstnPort, pThis->pRemHostIP,
84-
pThis->pRemHostName);
84+
pTcp->pSrv->pLstnPort, pTcp->pRemHostIP,
85+
pTcp->pRemHostName);
8586
}
8687
objinfo[sizeof(objinfo)-1] = '\0';
87-
#endif
88-
pThis->pEngine->onErr(pThis->pUsr, "session", emsg, ecode);
88+
pThis->pEngine->onErr(pThis->pUsr, objinfo, emsg, ecode);
8989
}
9090
}
9191

@@ -276,8 +276,9 @@ relpSessRcvData(relpSess_t *pThis)
276276
*/
277277
pThis->sessState = eRelpSessState_BROKEN;
278278
ABORT_FINALIZE(RELP_RET_SESSION_BROKEN);
279-
} else if ((int) lenBuf == -1) { /* I don't know why we need to cast to int, but we must... */
279+
} else if ((int) lenBuf == -1) {
280280
if(errno != EAGAIN) {
281+
callOnErr(pThis, "error when receiving data, session broken", RELP_RET_SESSION_BROKEN);
281282
pThis->pEngine->dbgprint("errno %d during relp session %p, session broken\n",
282283
errno, (void*)pThis);
283284
pThis->sessState = eRelpSessState_BROKEN;
@@ -318,6 +319,7 @@ relpSessSendResponse(relpSess_t *pThis, relpTxnr_t txnr, unsigned char *pData, s
318319
finalize_it:
319320
if(iRet != RELP_RET_OK) {
320321
if(iRet == RELP_RET_IO_ERR) {
322+
callOnErr(pThis, "io error, session broken", RELP_RET_SESSION_BROKEN);
321323
pThis->pEngine->dbgprint("relp session %p is broken, io error\n", (void*)pThis);
322324
pThis->sessState = eRelpSessState_BROKEN;
323325
}
@@ -565,7 +567,7 @@ relpSessWaitState(relpSess_t *const pThis, const relpSessState_t stateExpected,
565567
pfd.fd = sock;
566568
pfd.events = POLLIN;
567569
pThis->pEngine->dbgprint("relpSessWaitRsp waiting for data on "
568-
"fd %d, timeout %d\n", sock, timeout);
570+
"fd %d, timeout %d, state expected %d\n", sock, timeout, stateExpected);
569571
nfds = poll(&pfd, 1, timeout*1000);
570572
if(nfds == -1) {
571573
if(errno == EINTR) {
@@ -597,6 +599,8 @@ relpSessWaitState(relpSess_t *const pThis, const relpSessState_t stateExpected,
597599
iRet == RELP_RET_SESSION_BROKEN ||
598600
relpEngineShouldStop(pThis->pEngine)) {
599601
/* the session is broken! */
602+
callOnErr(pThis, "error waiting on required session state, session broken",
603+
RELP_RET_SESSION_BROKEN);
600604
pThis->sessState = eRelpSessState_BROKEN;
601605
}
602606

@@ -628,6 +632,7 @@ relpSessRawSendCommand(relpSess_t *pThis, unsigned char *pCmd, size_t lenCmd,
628632

629633
if(iRet == RELP_RET_IO_ERR) {
630634
pThis->pEngine->dbgprint("relp session %p flagged as broken, IO error\n", (void*)pThis);
635+
callOnErr(pThis, "io error in RawSendCommand, session broken", RELP_RET_SESSION_BROKEN);
631636
pThis->sessState = eRelpSessState_BROKEN;
632637
ABORT_FINALIZE(RELP_RET_SESSION_BROKEN);
633638
}
@@ -791,6 +796,7 @@ relpSessCBrspOpen(relpSess_t *pThis, relpFrame_t *pFrame)
791796
pEngine->dbgprint("ignoring unknown server offer '%s'\n", pOffer->szName);
792797
}
793798
}
799+
794800
relpSessSetSessState(pThis, eRelpSessState_INIT_RSP_RCVD);
795801

796802
finalize_it:
@@ -816,8 +822,10 @@ relpSessCltConnChkOffers(relpSess_t *pThis)
816822
ABORT_FINALIZE(RELP_RET_RQD_FEAT_MISSING);
817823

818824
finalize_it:
819-
if(iRet != RELP_RET_OK)
825+
if(iRet != RELP_RET_OK) {
826+
callOnErr(pThis, "error in CltConnChkOffers, session broken", RELP_RET_SESSION_BROKEN);
820827
pThis->sessState = eRelpSessState_BROKEN;
828+
}
821829

822830
LEAVE_RELPFUNC;
823831
}
@@ -876,7 +884,6 @@ relpSessConnect(relpSess_t *pThis, int protFamily, unsigned char *port, unsigned
876884
CHKRet(relpOffersToString(pOffers, NULL, 0, &pszOffers, &lenOffers));
877885
CHKRet(relpOffersDestruct(&pOffers));
878886

879-
pThis->pEngine->dbgprint("sending open command\n");
880887
CHKRet(relpSessRawSendCommand(pThis, (unsigned char*)"open", 4, pszOffers, lenOffers,
881888
relpSessCBrspOpen));
882889
relpSessSetSessState(pThis, eRelpSessState_INIT_CMD_SENT);

src/scrsp.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* development.
3232
*/
3333
#include "config.h"
34+
#include <stdio.h>
3435
#include <stdlib.h>
3536
#include <ctype.h>
3637
#include <assert.h>
@@ -106,6 +107,10 @@ BEGINcommand(S, Rsp)
106107
}
107108
CHKRet(relpSendbufDestruct(&pSendbuf));
108109
} else {
110+
if(pSess->pEngine->onErr != NULL) {
111+
pSess->pEngine->onErr(pSess->pUsr, "rsp command",
112+
"peer sent error response", RELP_RET_RSP_STATE_ERR);
113+
}
109114
iRet = RELP_RET_RSP_STATE_ERR;
110115
/* TODO: add a hock to a logger function of the caller */
111116
relpSendbufDestruct(&pSendbuf); /* don't set error code */

src/tcp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,14 +658,17 @@ relpTcpDestruct(relpTcp_t **ppThis)
658658
RELPOBJ_assert(pThis, Tcp);
659659

660660
if(pThis->sock != -1) {
661+
shutdown(pThis->sock, SHUT_RDWR);
661662
close(pThis->sock);
662663
pThis->sock = -1;
663664
}
664665

665666
if(pThis->socks != NULL) {
666667
/* if we have some sockets at this stage, we need to close them */
667-
for(i = 1 ; i <= pThis->socks[0] ; ++i)
668+
for(i = 1 ; i <= pThis->socks[0] ; ++i) {
669+
shutdown(pThis->socks[i], SHUT_RDWR);
668670
close(pThis->socks[i]);
671+
}
669672
free(pThis->socks);
670673
}
671674

@@ -2860,6 +2863,7 @@ relpTcpSend(relpTcp_t *const pThis, relpOctet_t *pBuf, ssize_t *pLenBuf)
28602863
#endif /* defined(ENABLE_TLS) | defined(ENABLE_TLS_OPENSSL */
28612864
written = send(pThis->sock, pBuf, *pLenBuf, 0);
28622865
const int errno_save = errno;
2866+
pThis->pEngine->dbgprint("relpTcpSend: send data: %.*s\n", (int) *pLenBuf, pBuf);
28632867
pThis->pEngine->dbgprint("relpTcpSend: sock %d, lenbuf %zd, send returned %d [errno %d]\n",
28642868
(int)pThis->sock, *pLenBuf, (int) written, errno_save);
28652869
if(written == -1) {

tests/Makefile.am

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
check_PROGRAMS=receive send
1+
check_PROGRAMS=receive send chkseq
22

33
receive_SOURCES=receive.c
4-
#receive_LDADD=-lrelp
54
receive_LDADD=../src/.libs/librelp.la
65
receive_CFLAGS=$(AM_CFLAGS) -I${top_srcdir}/src $(WARN_CFLAGS)
76

87
send_SOURCES=send.c
9-
#send_LDADD=-lrelp
108
send_LDADD=../src/.libs/librelp.la
119
send_CFLAGS=$(AM_CFLAGS) -I${top_srcdir}/src $(WARN_CFLAGS)
1210

11+
chkseq_SOURCES=chkseq.c
12+
1313
VALGRIND_TESTS= \
1414
tls-basic-vg.sh \
1515
duplicate-receiver-vg.sh
1616

1717
TESTS= basic.sh \
1818
basic-realistic.sh \
19+
receiver-abort.sh \
1920
tls-basic.sh \
2021
tls-basic-anon.sh \
2122
tls-basic-certvalid.sh \
@@ -46,6 +47,7 @@ endif
4647
EXTRA_DIST=$(TESTS) \
4748
$(VALGRIND_TESTS) \
4849
dummyclient.py \
50+
dummyserver.py \
4951
test-framework.sh \
5052
receive.c \
5153
send.c \

tests/basic-realistic.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# of messages
55
. ${srcdir:=$(pwd)}/test-framework.sh
66
NUMMESSAGES=50000
7-
startup_receiver $OPT_VERBOSE
7+
startup_receiver
88
./send -t 127.0.0.1 -p $TESTPORT -n$NUMMESSAGES $OPT_VERBOSE
99
stop_receiver
1010
check_msg_count

0 commit comments

Comments
 (0)