detect/event: convert unittests to FAIL/PASS APIs

Task #4025
pull/6582/head
Sam Muhammed 4 years ago committed by Victor Julien
parent 07ce871da4
commit 025fd385cd

@ -1,4 +1,4 @@
/* Copyright (C) 2007-2020 Open Information Security Foundation /* Copyright (C) 2007-2021 Open Information Security Foundation
* *
* You can copy, redistribute or modify this Program under the terms of * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * the GNU General Public License version 2 as published by the Free
@ -265,14 +265,13 @@ static int DetectStreamEventSetup (DetectEngineCtx *de_ctx, Signature *s, const
*/ */
static int EngineEventTestParse01 (void) static int EngineEventTestParse01 (void)
{ {
DetectEngineEventData *de = NULL; DetectEngineEventData *de = DetectEngineEventParse("decoder.ipv4.pkt_too_small");
de = DetectEngineEventParse("decoder.ipv4.pkt_too_small");
if (de) { FAIL_IF_NULL(de);
DetectEngineEventFree(NULL, de); DetectEngineEventFree(NULL, de);
return 1;
}
return 0; PASS;
} }
@ -281,14 +280,13 @@ static int EngineEventTestParse01 (void)
*/ */
static int EngineEventTestParse02 (void) static int EngineEventTestParse02 (void)
{ {
DetectEngineEventData *de = NULL; DetectEngineEventData *de = DetectEngineEventParse("decoder.PPP.pkt_too_small");
de = DetectEngineEventParse("decoder.PPP.pkt_too_small");
if (de) { FAIL_IF_NULL(de);
DetectEngineEventFree(NULL, de); DetectEngineEventFree(NULL, de);
return 1;
}
return 0; PASS;
} }
/** /**
@ -296,14 +294,13 @@ static int EngineEventTestParse02 (void)
*/ */
static int EngineEventTestParse03 (void) static int EngineEventTestParse03 (void)
{ {
DetectEngineEventData *de = NULL; DetectEngineEventData *de = DetectEngineEventParse("decoder.IPV6.PKT_TOO_SMALL");
de = DetectEngineEventParse("decoder.IPV6.PKT_TOO_SMALL");
if (de) { FAIL_IF_NULL(de);
DetectEngineEventFree(NULL, de); DetectEngineEventFree(NULL, de);
return 1;
}
return 0; PASS;
} }
/** /**
@ -311,14 +308,13 @@ static int EngineEventTestParse03 (void)
*/ */
static int EngineEventTestParse04 (void) static int EngineEventTestParse04 (void)
{ {
DetectEngineEventData *de = NULL; DetectEngineEventData *de = DetectEngineEventParse("decoder.IPV6.INVALID_EVENT");
de = DetectEngineEventParse("decoder.IPV6.INVALID_EVENT");
if (de) { FAIL_IF_NOT_NULL(de);
DetectEngineEventFree(NULL, de); DetectEngineEventFree(NULL, de);
return 0;
}
return 1; PASS;
} }
/** /**
@ -326,14 +322,13 @@ static int EngineEventTestParse04 (void)
*/ */
static int EngineEventTestParse05 (void) static int EngineEventTestParse05 (void)
{ {
DetectEngineEventData *de = NULL; DetectEngineEventData *de = DetectEngineEventParse("decoder.IPV-6,INVALID_CHAR");
de = DetectEngineEventParse("decoder.IPV-6,INVALID_CHAR");
if (de) { FAIL_IF_NOT_NULL(de);
DetectEngineEventFree(NULL, de); DetectEngineEventFree(NULL, de);
return 0;
}
return 1; PASS;
} }
/** /**
@ -342,44 +337,33 @@ static int EngineEventTestParse05 (void)
static int EngineEventTestParse06 (void) static int EngineEventTestParse06 (void)
{ {
Packet *p = SCMalloc(SIZE_OF_PACKET); Packet *p = SCMalloc(SIZE_OF_PACKET);
if (unlikely(p == NULL)) FAIL_IF_NULL(p);
return 0;
ThreadVars tv;
int ret = 0;
DetectEngineEventData *de = NULL;
SigMatch *sm = NULL;
ThreadVars tv;
memset(&tv, 0, sizeof(ThreadVars)); memset(&tv, 0, sizeof(ThreadVars));
memset(p, 0, SIZE_OF_PACKET); memset(p, 0, SIZE_OF_PACKET);
ENGINE_SET_EVENT(p,PPP_PKT_TOO_SMALL); ENGINE_SET_EVENT(p,PPP_PKT_TOO_SMALL);
de = DetectEngineEventParse("decoder.ppp.pkt_too_small"); DetectEngineEventData *de = DetectEngineEventParse("decoder.ppp.pkt_too_small");
if (de == NULL) FAIL_IF_NULL(de);
goto error;
de->event = PPP_PKT_TOO_SMALL; de->event = PPP_PKT_TOO_SMALL;
sm = SigMatchAlloc(); SigMatch *sm = SigMatchAlloc();
if (sm == NULL) FAIL_IF_NULL(sm);
goto error;
sm->type = DETECT_DECODE_EVENT; sm->type = DETECT_DECODE_EVENT;
sm->ctx = (SigMatchCtx *)de; sm->ctx = (SigMatchCtx *)de;
ret = DetectEngineEventMatch(NULL,p,NULL,sm->ctx); FAIL_IF_NOT(DetectEngineEventMatch(NULL, p, NULL, sm->ctx));
if(ret) {
SCFree(p); SCFree(p);
return 1; SCFree(de);
} SCFree(sm);
error: PASS;
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
} }
/** /**

Loading…
Cancel
Save