*/
static int DetectTagTestPacket01 (void)
{
- int result = 0;
uint8_t *buf = (uint8_t *)"Hi all!";
uint8_t *buf2 = (uint8_t *)"lalala!";
uint16_t buf_len = strlen((char *)buf);
HostInitConfig(1);
SCLogDebug("running tests");
- result = UTHGenericTest(p, 7, sigs, sid, (uint32_t *) results, 5);
+ FAIL_IF_NOT(UTHGenericTest(p, 7, sigs, sid, (uint32_t *)results, 5));
SCLogDebug("running tests done");
Host *src = HostLookupHostFromHash(&p[1]->src);
- if (src) {
- void *tag = HostGetStorageById(src, host_tag_id);
- if (tag != NULL) {
- printf("tag should have been expired: ");
- result = 0;
- }
+ FAIL_IF_NULL(src);
+ FAIL_IF_NOT_NULL(HostGetStorageById(src, host_tag_id));
- HostRelease(src);
- }
Host *dst = HostLookupHostFromHash(&p[1]->dst);
- if (dst) {
- void *tag = HostGetStorageById(dst, host_tag_id);
- BUG_ON(tag == NULL);
+ FAIL_IF_NULL(dst);
- DetectTagDataEntry *iter = tag;
+ void *tag = HostGetStorageById(dst, host_tag_id);
+ FAIL_IF_NULL(tag);
- /* check internal state */
- if (!(iter->gid == 1 && iter->sid == 2 && iter->packets == 4 && iter->count == 4)) {
- printf("gid %u sid %u packets %u count %u: ", iter->gid, iter->sid, iter->packets, iter->count);
- result = 0;
- }
+ DetectTagDataEntry *iter = tag;
- HostRelease(dst);
- }
- BUG_ON(src == NULL || dst == NULL);
+ /* check internal state */
+ FAIL_IF_NOT(iter->gid == 1);
+ FAIL_IF_NOT(iter->sid == 2);
+ FAIL_IF_NOT(iter->packets == 4);
+ FAIL_IF_NOT(iter->count == 4);
+
+ HostRelease(src);
+ HostRelease(dst);
UTHFreePackets(p, 7);
HostShutdown();
TagDestroyCtx();
StorageCleanup();
- return result;
+ PASS;
}
/**
*/
static int DetectTagTestPacket02 (void)
{
- int result = 0;
uint8_t *buf = (uint8_t *)"Hi all!";
uint8_t *buf2 = (uint8_t *)"lalala!";
uint16_t buf_len = strlen((char *)buf);
HostInitConfig(1);
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
- if (de_ctx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
Packet *p[7];
uint32_t sid[5] = {1,2,3,4,5};
int numsigs = 5;
- if (UTHAppendSigs(de_ctx, sigs, numsigs) == 0)
- goto cleanup;
+ FAIL_IF(UTHAppendSigs(de_ctx, sigs, numsigs) == 0);
//de_ctx->flags |= DE_QUIET;
SCLogDebug("packet %d", i);
TimeGet(&p[i]->ts);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p[i]);
- if (UTHCheckPacketMatchResults(p[i], sid, (uint32_t *)&results[i][0], numsigs) == 0)
- goto cleanup;
+ FAIL_IF(UTHCheckPacketMatchResults(p[i], sid, (uint32_t *)&results[i][0], numsigs) == 0);
TimeSetIncrementTime(2);
SCLogDebug("packet %d flag %s", i, p[i]->flags & PKT_HAS_TAG ? "true" : "false");
/* see if the PKT_HAS_TAG is set on the packet if needed */
- bool expect;
- if (i == 0 || i == 2 || i == 3 || i == 5 || i == 6)
- expect = false;
- else
- expect = true;
- if (((p[i]->flags & PKT_HAS_TAG) ? true : false) != expect)
- goto cleanup;
+ bool expect = (i == 1 || i == 4);
+ FAIL_IF(((p[i]->flags & PKT_HAS_TAG) ? true : false) != expect);
}
- result = 1;
-
-cleanup:
UTHFreePackets(p, 7);
- if (det_ctx != NULL)
- DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
+ DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
+ DetectEngineCtxFree(de_ctx);
- if (de_ctx != NULL) {
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
- DetectEngineCtxFree(de_ctx);
- }
-end:
HostShutdown();
TagDestroyCtx();
StorageCleanup();
- return result;
+ PASS;
}
/**
*/
static int DetectTagTestPacket03 (void)
{
- int result = 0;
uint8_t *buf = (uint8_t *)"Hi all!";
uint8_t *buf2 = (uint8_t *)"lalala!";
uint16_t buf_len = strlen((char *)buf);
HostInitConfig(1);
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
- if (de_ctx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(de_ctx);
+
de_ctx->flags |= DE_QUIET;
Packet *p[7];
uint32_t sid[5] = {1,2,3,4,5};
int numsigs = 5;
- if (UTHAppendSigs(de_ctx, sigs, numsigs) == 0)
- goto cleanup;
+ FAIL_IF(UTHAppendSigs(de_ctx, sigs, numsigs) == 0);
int32_t results[7][5] = {
{1, 1, 0, 0, 0},
for (; i < num_packets; i++) {
SigMatchSignatures(&th_v, de_ctx, det_ctx, p[i]);
- if (UTHCheckPacketMatchResults(p[i], sid, (uint32_t *)&results[i][0], numsigs) == 0)
- goto cleanup;
+ FAIL_IF(UTHCheckPacketMatchResults(p[i], sid, (uint32_t *)&results[i][0], numsigs) == 0);
SCLogDebug("packet %d flag %s", i, p[i]->flags & PKT_HAS_TAG ? "true" : "false");
/* see if the PKT_HAS_TAG is set on the packet if needed */
- bool expect;
- if (i == 0 || i == 3 || i == 5 || i == 6)
- expect = false;
- else
- expect = true;
- if (((p[i]->flags & PKT_HAS_TAG) ? true : false) != expect)
- goto cleanup;
+ bool expect = (i == 1 || i == 2 || i == 4);
+ FAIL_IF(((p[i]->flags & PKT_HAS_TAG) ? true : false) != expect);
}
- result = 1;
-
-cleanup:
UTHFreePackets(p, 7);
- if (det_ctx != NULL)
- DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
+ DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
+ DetectEngineCtxFree(de_ctx);
- if (de_ctx != NULL) {
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
- DetectEngineCtxFree(de_ctx);
- }
-end:
HostShutdown();
TagDestroyCtx();
StorageCleanup();
- return result;
+ PASS;
}
/**
*/
static int DetectTagTestPacket04 (void)
{
- int result = 0;
uint8_t *buf = (uint8_t *)"Hi all!";
uint8_t *buf2 = (uint8_t *)"lalala!";
uint16_t buf_len = strlen((char *)buf);
FlowInitConfig(1);
f = FlowAlloc();
- BUG_ON(f == NULL);
+ FAIL_IF_NULL(f);
FLOW_INITIALIZE(f);
f->protoctx = (void *)&ssn;
f->flags |= FLOW_IPV4;
- if (inet_pton(AF_INET, "192.168.1.5", f->src.addr_data32) != 1)
- goto end;
- if (inet_pton(AF_INET, "192.168.1.1", f->dst.addr_data32) != 1)
- goto end;
+ FAIL_IF(inet_pton(AF_INET, "192.168.1.5", f->src.addr_data32) != 1);
+ FAIL_IF(inet_pton(AF_INET, "192.168.1.1", f->dst.addr_data32) != 1);
DecodeThreadVars dtv;
ThreadVars th_v;
memset(&th_v, 0, sizeof(th_v));
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
- if (de_ctx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
Packet *p[7];
uint32_t sid[5] = {1,2,3,4,5};
int numsigs = 5;
- if (UTHAppendSigs(de_ctx, sigs, numsigs) == 0)
- goto cleanup;
+ FAIL_IF(UTHAppendSigs(de_ctx, sigs, numsigs) == 0);
int32_t results[7][5] = {
{1, 0, 0, 0, 0},
p[i]->flow->protoctx = &ssn;
SigMatchSignatures(&th_v, de_ctx, det_ctx, p[i]);
- if (UTHCheckPacketMatchResults(p[i], sid, (uint32_t *)&results[i][0], numsigs) == 0)
- goto cleanup;
+ FAIL_IF(UTHCheckPacketMatchResults(p[i], sid, (uint32_t *)&results[i][0], numsigs) == 0);
SCLogDebug("packet %d flag %s", i, p[i]->flags & PKT_HAS_TAG ? "true" : "false");
/* see if the PKT_HAS_TAG is set on the packet if needed */
- bool expect;
- if (i == 0 || i == 4 || i == 5 || i == 6)
- expect = false;
- else
- expect = true;
- if (((p[i]->flags & PKT_HAS_TAG) ? true : false) != expect)
- goto cleanup;
+ bool expect = (i == 1 || i == 2 || i == 3);
+ FAIL_IF(((p[i]->flags & PKT_HAS_TAG) ? true : false) != expect);
}
- result = 1;
-
-cleanup:
UTHFreePackets(p, 7);
- if (det_ctx != NULL)
- DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
-
- if (de_ctx != NULL) {
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
- DetectEngineCtxFree(de_ctx);
- }
+ DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
+ DetectEngineCtxFree(de_ctx);
/* clean up flow */
uint8_t proto_map = FlowGetProtoMapping(f->proto);
FlowClearMemory(f, proto_map);
FLOW_DESTROY(f);
FlowFree(f);
-end:
+
FlowShutdown();
HostShutdown();
TagDestroyCtx();
StorageCleanup();
- return result;
+ PASS;
}
/**
*/
static int DetectTagTestPacket05 (void)
{
- int result = 0;
uint8_t *buf = (uint8_t *)"Hi all!";
uint8_t *buf2 = (uint8_t *)"lalala!";
uint16_t buf_len = strlen((char *)buf);
FlowInitConfig(1);
f = FlowAlloc();
- BUG_ON(f == NULL);
+ FAIL_IF_NULL(f);
FLOW_INITIALIZE(f);
f->protoctx = (void *)&ssn;
f->flags |= FLOW_IPV4;
- if (inet_pton(AF_INET, "192.168.1.5", f->src.addr_data32) != 1)
- goto end;
- if (inet_pton(AF_INET, "192.168.1.1", f->dst.addr_data32) != 1)
- goto end;
+ FAIL_IF(inet_pton(AF_INET, "192.168.1.5", f->src.addr_data32) != 1);
+ FAIL_IF(inet_pton(AF_INET, "192.168.1.1", f->dst.addr_data32) != 1);
DecodeThreadVars dtv;
ThreadVars th_v;
memset(&th_v, 0, sizeof(th_v));
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
- if (de_ctx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
Packet *p[7];
uint32_t sid[5] = {1,2,3,4,5};
int numsigs = 5;
- if (UTHAppendSigs(de_ctx, sigs, numsigs) == 0)
- goto cleanup;
+ FAIL_IF(UTHAppendSigs(de_ctx, sigs, numsigs) == 0);
int32_t results[7][5] = {
{1, 0, 0, 0, 0},
TimeGet(&p[i]->ts);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p[i]);
- if (UTHCheckPacketMatchResults(p[i], sid, (uint32_t *)&results[i][0], numsigs) == 0)
- goto cleanup;
+ FAIL_IF(UTHCheckPacketMatchResults(p[i], sid, (uint32_t *)&results[i][0], numsigs) == 0);
TimeSetIncrementTime(2);
SCLogDebug("packet %d flag %s", i, p[i]->flags & PKT_HAS_TAG ? "true" : "false");
/* see if the PKT_HAS_TAG is set on the packet if needed */
- bool expect;
- if (i == 0 || i == 5 || i == 6)
- expect = false;
- else
- expect = true;
- if (((p[i]->flags & PKT_HAS_TAG) ? true : false) != expect)
- goto cleanup;
+ bool expect = (i == 1 || i == 2 || i == 3 || i == 4);
+ FAIL_IF(((p[i]->flags & PKT_HAS_TAG) ? true : false) != expect);
}
- result = 1;
-
-cleanup:
UTHFreePackets(p, 7);
- if (det_ctx != NULL)
- DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
-
- if (de_ctx != NULL) {
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
- DetectEngineCtxFree(de_ctx);
- }
+ DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
+ DetectEngineCtxFree(de_ctx);
/* clean up flow */
uint8_t proto_map = FlowGetProtoMapping(f->proto);
FlowClearMemory(f, proto_map);
FLOW_DESTROY(f);
FlowFree(f);
-end:
+
FlowShutdown();
HostShutdown();
TagDestroyCtx();
StorageCleanup();
- return result;
+ PASS;
}
/**
*/
static int DetectTagTestPacket06 (void)
{
- int result = 0;
uint8_t *buf = (uint8_t *)"Hi all!";
uint8_t *buf2 = (uint8_t *)"lalala!";
uint16_t buf_len = strlen((char *)buf);
FlowInitConfig(1);
f = FlowAlloc();
- BUG_ON(f == NULL);
+ FAIL_IF_NULL(f);
FLOW_INITIALIZE(f);
f->protoctx = (void *)&ssn;
f->flags |= FLOW_IPV4;
- if (inet_pton(AF_INET, "192.168.1.5", f->src.addr_data32) != 1)
- goto end;
- if (inet_pton(AF_INET, "192.168.1.1", f->dst.addr_data32) != 1)
- goto end;
+ FAIL_IF(inet_pton(AF_INET, "192.168.1.5", f->src.addr_data32) != 1);
+ FAIL_IF(inet_pton(AF_INET, "192.168.1.1", f->dst.addr_data32) != 1);
DecodeThreadVars dtv;
ThreadVars th_v;
memset(&th_v, 0, sizeof(th_v));
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
- if (de_ctx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
Packet *p[7];
uint32_t sid[5] = {1,2,3,4,5};
int numsigs = 5;
- if (UTHAppendSigs(de_ctx, sigs, numsigs) == 0)
- goto cleanup;
+ FAIL_IF(UTHAppendSigs(de_ctx, sigs, numsigs) == 0);
int32_t results[7][5] = {
{1, 0, 0, 0, 0},
p[i]->flow->protoctx = &ssn;
SigMatchSignatures(&th_v, de_ctx, det_ctx, p[i]);
- if (UTHCheckPacketMatchResults(p[i], sid, (uint32_t *)&results[i][0], numsigs) == 0)
- goto cleanup;
+ FAIL_IF(UTHCheckPacketMatchResults(p[i], sid, (uint32_t *)&results[i][0], numsigs) == 0);
SCLogDebug("packet %d flag %s", i, p[i]->flags & PKT_HAS_TAG ? "true" : "false");
/* see if the PKT_HAS_TAG is set on the packet if needed */
- int expect;
- if (i == 0 || i == 3 || i == 4 || i == 5 || i == 6)
- expect = FALSE;
- else
- expect = TRUE;
- if (((p[i]->flags & PKT_HAS_TAG) ? TRUE : FALSE) != expect)
- goto cleanup;
+ bool expect = (i == 1 || i == 2);
+ FAIL_IF(((p[i]->flags & PKT_HAS_TAG) ? true : false) != expect);
}
- result = 1;
-
-cleanup:
UTHFreePackets(p, 7);
- if (det_ctx != NULL)
- DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
-
- if (de_ctx != NULL) {
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
- DetectEngineCtxFree(de_ctx);
- }
+ DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
+ DetectEngineCtxFree(de_ctx);
/* clean up flow */
uint8_t proto_map = FlowGetProtoMapping(f->proto);
FlowClearMemory(f, proto_map);
FLOW_DESTROY(f);
FlowFree(f);
-end:
+
FlowShutdown();
HostShutdown();
TagDestroyCtx();
StorageCleanup();
- return result;
+ PASS;
}
/**
*/
static int DetectTagTestPacket07 (void)
{
- int result = 0;
uint8_t *buf = (uint8_t *)"Hi all!";
uint8_t *buf2 = (uint8_t *)"lalala!";
uint16_t buf_len = strlen((char *)buf);
FlowInitConfig(1);
f = FlowAlloc();
- BUG_ON(f == NULL);
+ FAIL_IF_NULL(f);
FLOW_INITIALIZE(f);
f->protoctx = (void *)&ssn;
f->flags |= FLOW_IPV4;
- if (inet_pton(AF_INET, "192.168.1.5", f->src.addr_data32) != 1)
- goto end;
- if (inet_pton(AF_INET, "192.168.1.1", f->dst.addr_data32) != 1)
- goto end;
+ FAIL_IF(inet_pton(AF_INET, "192.168.1.5", f->src.addr_data32) != 1);
+ FAIL_IF(inet_pton(AF_INET, "192.168.1.1", f->dst.addr_data32) != 1);
DecodeThreadVars dtv;
ThreadVars th_v;
memset(&th_v, 0, sizeof(th_v));
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
- if (de_ctx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
Packet *p[7];
uint32_t sid[5] = {1,2,3,4,5};
int numsigs = 5;
- if (UTHAppendSigs(de_ctx, sigs, numsigs) == 0)
- goto cleanup;
-
+ FAIL_IF(UTHAppendSigs(de_ctx, sigs, numsigs) == 0);
int32_t results[7][5] = {
{1, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
p[i]->flow->protoctx = &ssn;
SigMatchSignatures(&th_v, de_ctx, det_ctx, p[i]);
- if (UTHCheckPacketMatchResults(p[i], sid, (uint32_t *)&results[i][0], numsigs) == 0)
- goto cleanup;
+ FAIL_IF(UTHCheckPacketMatchResults(p[i], sid, (uint32_t *)&results[i][0], numsigs) == 0);
SCLogDebug("packet %d flag %s", i, p[i]->flags & PKT_HAS_TAG ? "true" : "false");
-#if 1
+
/* see if the PKT_HAS_TAG is set on the packet if needed */
- int expect;
- if (i == 0 || i == 6)
- expect = FALSE;
- else
- expect = TRUE;
- if (((p[i]->flags & PKT_HAS_TAG) ? TRUE : FALSE) != expect)
- goto cleanup;
-#endif
+ bool expect = (i == 1 || i == 2 || i == 3 || i == 4 || i == 5);
+ FAIL_IF(((p[i]->flags & PKT_HAS_TAG) ? true : false) != expect);
}
- result = 1;
-
-cleanup:
UTHFreePackets(p, 7);
- if (det_ctx != NULL)
- DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
-
- if (de_ctx != NULL) {
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
- DetectEngineCtxFree(de_ctx);
- }
+ DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
+ DetectEngineCtxFree(de_ctx);
/* clean up flow */
uint8_t proto_map = FlowGetProtoMapping(f->proto);
FlowClearMemory(f, proto_map);
FLOW_DESTROY(f);
FlowFree(f);
-end:
+
FlowShutdown();
HostShutdown();
TagDestroyCtx();
StorageCleanup();
- return result;
+ PASS;
}
#endif /* UNITTESTS */