unittests: fix stream-tcp.c

Lock and recycle fixes for stream-tcp.c
pull/506/head
Eric Leblond 12 years ago committed by Victor Julien
parent cd3e32ce19
commit 189327981a

@ -60,6 +60,7 @@
#include "stream.h"
#include "pkt-var.h"
#include "host.h"
#include "app-layer-parser.h"
#include "app-layer-protos.h"
@ -5468,8 +5469,10 @@ static int StreamTcpTest02 (void) {
StreamTcpInitConfig(TRUE);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1) {
goto end;
}
p->tcph->th_ack = htonl(1);
p->tcph->th_flags = TH_SYN | TH_ACK;
@ -5523,6 +5526,7 @@ static int StreamTcpTest02 (void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -5562,6 +5566,7 @@ static int StreamTcpTest03 (void) {
p->tcph = &tcph;
int ret = 0;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -5597,6 +5602,7 @@ static int StreamTcpTest03 (void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -5637,6 +5643,7 @@ static int StreamTcpTest04 (void) {
int ret = 0;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -5664,6 +5671,7 @@ static int StreamTcpTest04 (void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -5712,6 +5720,7 @@ static int StreamTcpTest05 (void) {
p->payload = payload;
p->payload_len = 3;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -5767,6 +5776,7 @@ static int StreamTcpTest05 (void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -5805,6 +5815,7 @@ static int StreamTcpTest06 (void) {
tcph.th_flags = TH_FIN;
p->tcph = &tcph;
SCMutexLock(&f.m);
/* StreamTcpPacket returns -1 on unsolicited FIN */
if (StreamTcpPacket(&tv, p, &stt, &pq) != -1) {
printf("StreamTcpPacket failed: ");
@ -5831,6 +5842,7 @@ static int StreamTcpTest06 (void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -5894,6 +5906,7 @@ static int StreamTcpTest07 (void) {
p->payload = payload;
p->payload_len = 1;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -5918,6 +5931,7 @@ static int StreamTcpTest07 (void) {
}
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -5982,6 +5996,7 @@ static int StreamTcpTest08 (void) {
p->payload = payload;
p->payload_len = 1;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -6008,6 +6023,7 @@ static int StreamTcpTest08 (void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -6058,6 +6074,7 @@ static int StreamTcpTest09 (void) {
p->payload = payload;
p->payload_len = 1;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -6085,6 +6102,7 @@ static int StreamTcpTest09 (void) {
StreamTcpSessionClear(p->flow->protoctx);
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -6124,6 +6142,7 @@ static int StreamTcpTest10 (void) {
p->tcph = &tcph;
int ret = 0;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -6185,6 +6204,7 @@ static int StreamTcpTest10 (void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -6224,6 +6244,7 @@ static int StreamTcpTest11 (void) {
p->tcph = &tcph;
int ret = 0;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -6286,6 +6307,7 @@ static int StreamTcpTest11 (void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -6325,6 +6347,7 @@ static int StreamTcpTest12 (void) {
p->tcph = &tcph;
int ret = 0;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -6379,6 +6402,7 @@ static int StreamTcpTest12 (void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -6419,6 +6443,7 @@ static int StreamTcpTest13 (void) {
p->tcph = &tcph;
int ret = 0;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -6485,6 +6510,7 @@ static int StreamTcpTest13 (void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -6648,6 +6674,7 @@ static int StreamTcpTest14 (void) {
p->payload = payload;
p->payload_len = 3;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -6748,6 +6775,7 @@ end:
StreamTcpFreeConfig(TRUE);
ConfDeInit();
ConfRestoreContextBackup();
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -6786,6 +6814,7 @@ static int StreamTcp4WHSTest01 (void) {
tcph.th_flags = TH_SYN;
p->tcph = &tcph;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -6827,6 +6856,7 @@ static int StreamTcp4WHSTest01 (void) {
end:
StreamTcpSessionClear(p->flow->protoctx);
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -6866,6 +6896,7 @@ static int StreamTcp4WHSTest02 (void) {
tcph.th_flags = TH_SYN;
p->tcph = &tcph;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -6896,6 +6927,7 @@ static int StreamTcp4WHSTest02 (void) {
end:
StreamTcpSessionClear(p->flow->protoctx);
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -6935,6 +6967,7 @@ static int StreamTcp4WHSTest03 (void) {
tcph.th_flags = TH_SYN;
p->tcph = &tcph;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -6976,6 +7009,7 @@ static int StreamTcp4WHSTest03 (void) {
end:
StreamTcpSessionClear(p->flow->protoctx);
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -7046,6 +7080,7 @@ static int StreamTcpTest15 (void) {
p->payload = payload;
p->payload_len = 3;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -7146,6 +7181,7 @@ end:
StreamTcpFreeConfig(TRUE);
ConfDeInit();
ConfRestoreContextBackup();
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -7216,6 +7252,7 @@ static int StreamTcpTest16 (void) {
p->payload = payload;
p->payload_len = 3;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -7316,6 +7353,7 @@ end:
StreamTcpFreeConfig(TRUE);
ConfDeInit();
ConfRestoreContextBackup();
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -7387,6 +7425,7 @@ static int StreamTcpTest17 (void) {
p->payload = payload;
p->payload_len = 3;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -7487,6 +7526,7 @@ end:
StreamTcpFreeConfig(TRUE);
ConfDeInit();
ConfRestoreContextBackup();
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -7966,6 +8006,7 @@ static int StreamTcpTest25(void) {
StreamTcpInitConfig(TRUE);
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -8021,6 +8062,7 @@ static int StreamTcpTest25(void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -8060,6 +8102,7 @@ static int StreamTcpTest26(void) {
StreamTcpInitConfig(TRUE);
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -8115,6 +8158,7 @@ static int StreamTcpTest26(void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -8154,6 +8198,7 @@ static int StreamTcpTest27(void) {
StreamTcpInitConfig(TRUE);
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -8209,6 +8254,7 @@ static int StreamTcpTest27(void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -9144,6 +9190,7 @@ static int StreamTcpTest37(void) {
StreamTcpInitConfig(TRUE);
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1) {
printf("failed in processing packet\n");
goto end;
@ -9224,6 +9271,7 @@ static int StreamTcpTest37(void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -9269,6 +9317,7 @@ static int StreamTcpTest38 (void) {
stt.ra_ctx = &ra_ctx;
StreamTcpInitConfig(TRUE);
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1) {
printf("failed in processing packet in StreamTcpPacket\n");
goto end;
@ -9342,6 +9391,8 @@ static int StreamTcpTest38 (void) {
end:
StreamTcpSessionClear(p->flow->protoctx);
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -9387,6 +9438,7 @@ static int StreamTcpTest39 (void) {
StreamTcpInitConfig(TRUE);
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1) {
printf("failed in processing packet in StreamTcpPacket\n");
goto end;
@ -9460,6 +9512,8 @@ static int StreamTcpTest39 (void) {
end:
StreamTcpSessionClear(p->flow->protoctx);
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -9513,8 +9567,9 @@ static int StreamTcpTest40(void) {
return 0;
}
PACKET_RECYCLE(np);
PACKET_RECYCLE(p);
FlowShutdown();
PACKET_CLEANUP(p);
return 1;
}
@ -9577,9 +9632,10 @@ static int StreamTcpTest41(void) {
return 0;
}
FlowShutdown();
PACKET_CLEANUP(p);
PACKET_RECYCLE(np);
PACKET_RECYCLE(p);
SCFree(p);
FlowShutdown();
return 1;
}
@ -9617,6 +9673,7 @@ static int StreamTcpTest42 (void) {
tcph.th_seq = htonl(100);
p->flowflags = FLOW_PKT_TOSERVER;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -9670,6 +9727,7 @@ static int StreamTcpTest42 (void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -9707,6 +9765,7 @@ static int StreamTcpTest43 (void) {
tcph.th_seq = htonl(100);
p->flowflags = FLOW_PKT_TOSERVER;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -9760,6 +9819,7 @@ static int StreamTcpTest43 (void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -9797,6 +9857,7 @@ static int StreamTcpTest44 (void) {
tcph.th_seq = htonl(100);
p->flowflags = FLOW_PKT_TOSERVER;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -9845,6 +9906,7 @@ static int StreamTcpTest44 (void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}
@ -9883,6 +9945,7 @@ static int StreamTcpTest45 (void) {
tcph.th_seq = htonl(100);
p->flowflags = FLOW_PKT_TOSERVER;
SCMutexLock(&f.m);
if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
goto end;
@ -9954,6 +10017,7 @@ static int StreamTcpTest45 (void) {
ret = 1;
end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
return ret;
}

Loading…
Cancel
Save