Fix errors in the unittests reported by valgrind's drd tool. Add explanation of a FP.

remotes/origin/master-1.0.x
Victor Julien 15 years ago
parent 4875c2daf4
commit 958b61ab85

@ -1231,33 +1231,36 @@ static int FlowTest02 (void) {
static int FlowTestPrune(Flow *f, struct timeval *ts) {
FlowQueue *q = FlowQueueNew();
int r = SCMutexInit(&q->mutex_q, NULL);
if (r != 0) {
SCLogDebug("Error initializing mutex!");
return 0;
if (q == NULL) {
goto error;
}
q->top = NULL;
FlowEnqueue(q, f);
if (q->len != 1) {
printf("Failed in enqueue the flow in flowqueue\n");
return 0;
printf("Failed in enqueue the flow in flowqueue: ");
goto error;
}
FlowPrune(q, ts);
if (q->len != 0) {
printf("Failed in prunning the flow\n");
return 0;
printf("Failed in prunning the flow: ");
goto error;
}
if (f->protoctx != NULL){
printf("Failed in freeing the TcpSession\n");
return 0;
printf("Failed in freeing the TcpSession: ");
goto error;
}
return 1;
error:
if (q != NULL) {
FlowQueueDestroy(q);
}
return 0;
}
/**
@ -1278,19 +1281,25 @@ static int FlowTest03 (void) {
memset(&f, 0, sizeof(Flow));
memset(&ts, 0, sizeof(ts));
memset(&fb, 0, sizeof(FlowBucket));
SCMutexInit(&fb.m, NULL);
SCMutexInit(&f.m, NULL);
TimeGet(&ts);
f.lastts.tv_sec = ts.tv_sec - 5000;
f.protoctx = &ssn;
SCMutexInit(&fb.m, NULL);
f.fb = &fb;
f.proto = IPPROTO_TCP;
if (FlowTestPrune(&f, &ts) != 1)
if (FlowTestPrune(&f, &ts) != 1) {
SCMutexDestroy(&fb.m);
SCMutexDestroy(&f.m);
return 0;
}
SCMutexDestroy(&fb.m);
SCMutexDestroy(&f.m);
return 1;
}
@ -1318,8 +1327,8 @@ static int FlowTest04 (void) {
memset(&seg, 0, sizeof(TcpSegment));
memset(&client, 0, sizeof(TcpSegment));
SCMutexInit(&f.m, NULL);
SCMutexInit(&fb.m, NULL);
SCMutexInit(&f.m, NULL);
TimeGet(&ts);
seg.payload = payload;
@ -1335,9 +1344,14 @@ static int FlowTest04 (void) {
f.fb = &fb;
f.proto = IPPROTO_TCP;
if (FlowTestPrune(&f, &ts) != 1)
if (FlowTestPrune(&f, &ts) != 1) {
SCMutexDestroy(&fb.m);
SCMutexDestroy(&f.m);
return 0;
}
SCMutexDestroy(&fb.m);
SCMutexDestroy(&f.m);
return 1;
}
@ -1361,8 +1375,8 @@ static int FlowTest05 (void) {
memset(&ts, 0, sizeof(ts));
memset(&fb, 0, sizeof(FlowBucket));
SCMutexInit(&f.m, NULL);
SCMutexInit(&fb.m, NULL);
SCMutexInit(&f.m, NULL);
TimeGet(&ts);
ssn.state = TCP_SYN_SENT;
@ -1372,9 +1386,14 @@ static int FlowTest05 (void) {
f.proto = IPPROTO_TCP;
f.flags = FLOW_EMERGENCY;
if (FlowTestPrune(&f, &ts) != 1)
if (FlowTestPrune(&f, &ts) != 1) {
SCMutexDestroy(&fb.m);
SCMutexDestroy(&f.m);
return 0;
}
SCMutexDestroy(&fb.m);
SCMutexDestroy(&f.m);
return 1;
}
@ -1420,9 +1439,14 @@ static int FlowTest06 (void) {
f.proto = IPPROTO_TCP;
f.flags = FLOW_EMERGENCY;
if (FlowTestPrune(&f, &ts) != 1)
if (FlowTestPrune(&f, &ts) != 1) {
SCMutexDestroy(&fb.m);
SCMutexDestroy(&f.m);
return 0;
}
SCMutexDestroy(&fb.m);
SCMutexDestroy(&f.m);
return 1;
}

@ -1,5 +1,8 @@
/* Copyright (c) 2009 Open Information Security Foundation */
/**
* Copyright (c) 2009 Open Information Security Foundation
*
* \file
*
* \author Victor Julien <victor@inliniac.net>
* \author Pablo Rincon Crespo <pablo.rincon.crespo@gmail.com>
@ -31,6 +34,18 @@ int ThreadMacrosTest01Mutex(void) {
/**
* \brief Test Spin Macros
*
* Valgrind's DRD tool (valgrind-3.5.0-Debian) reports:
*
* ==31156== Recursive locking not allowed: mutex 0x7fefff97c, recursion count 1, owner 1.
* ==31156== at 0x4C2C77E: pthread_spin_trylock (drd_pthread_intercepts.c:829)
* ==31156== by 0x40EB3E: ThreadMacrosTest02Spinlocks (threads.c:40)
* ==31156== by 0x532E8A: UtRunTests (util-unittest.c:182)
* ==31156== by 0x4065C3: main (suricata.c:789)
*
* To me this is a false possitve, as the whole point of "trylock" is to see
* if a spinlock is actually locked.
*
*/
int ThreadMacrosTest02Spinlocks(void) {
SCSpinlock mut;

Loading…
Cancel
Save