detect-ipopts: convert unittests to FAIL/PASS APIs

Bug: 4047
pull/6680/head
Modupe Falodun 4 years ago committed by Victor Julien
parent 1b10848d84
commit 76131c8cff

@ -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
@ -217,55 +217,40 @@ void DetectIpOptsFree(DetectEngineCtx *de_ctx, void *de_ptr)
#ifdef UNITTESTS #ifdef UNITTESTS
/** /**
* \test IpOptsTestParse01 is a test for a valid ipopts value * \test IpOptsTestParse01 is a test for a valid ipopts value
*
* \retval 1 on succces
* \retval 0 on failure
*/ */
static int IpOptsTestParse01 (void) static int IpOptsTestParse01 (void)
{ {
DetectIpOptsData *de = NULL; DetectIpOptsData *de = DetectIpOptsParse("lsrr");
de = DetectIpOptsParse("lsrr");
if (de) { FAIL_IF_NULL(de);
DetectIpOptsFree(NULL, de); DetectIpOptsFree(NULL, de);
return 1;
}
return 0; PASS;
} }
/** /**
* \test IpOptsTestParse02 is a test for an invalid ipopts value * \test IpOptsTestParse02 is a test for an invalid ipopts value
*
* \retval 1 on succces
* \retval 0 on failure
*/ */
static int IpOptsTestParse02 (void) static int IpOptsTestParse02 (void)
{ {
DetectIpOptsData *de = NULL; DetectIpOptsData *de = DetectIpOptsParse("invalidopt");
de = DetectIpOptsParse("invalidopt");
if (de) { FAIL_IF_NOT_NULL(de);
DetectIpOptsFree(NULL, de); DetectIpOptsFree(NULL, de);
return 0;
}
return 1; PASS;
} }
/** /**
* \test IpOptsTestParse03 test the match function on a packet that needs to match * \test IpOptsTestParse03 test the match function on a packet that needs to match
*
* \retval 1 on succces
* \retval 0 on failure
*/ */
static int IpOptsTestParse03 (void) static int IpOptsTestParse03 (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; ThreadVars tv;
int ret = 0;
DetectIpOptsData *de = NULL;
SigMatch *sm = NULL;
IPV4Hdr ip4h; IPV4Hdr ip4h;
memset(&tv, 0, sizeof(ThreadVars)); memset(&tv, 0, sizeof(ThreadVars));
@ -275,47 +260,32 @@ static int IpOptsTestParse03 (void)
p->ip4h = &ip4h; p->ip4h = &ip4h;
p->ip4vars.opts_set = IPV4_OPT_FLAG_RR; p->ip4vars.opts_set = IPV4_OPT_FLAG_RR;
de = DetectIpOptsParse("rr"); DetectIpOptsData *de = DetectIpOptsParse("rr");
FAIL_IF_NULL(de);
if (de == NULL) SigMatch *sm = SigMatchAlloc();
goto error; FAIL_IF_NULL(sm);
sm = SigMatchAlloc();
if (sm == NULL)
goto error;
sm->type = DETECT_IPOPTS; sm->type = DETECT_IPOPTS;
sm->ctx = (SigMatchCtx *)de; sm->ctx = (SigMatchCtx *)de;
ret = DetectIpOptsMatch(NULL, p, NULL, sm->ctx); FAIL_IF_NOT(DetectIpOptsMatch(NULL, p, NULL, sm->ctx));
if(ret) { SCFree(de);
SCFree(sm);
SCFree(p); SCFree(p);
return 1;
}
error: PASS;
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
} }
/** /**
* \test IpOptsTestParse04 test the match function on a packet that needs to not match * \test IpOptsTestParse04 test the match function on a packet that needs to not match
*
* \retval 1 on succces
* \retval 0 on failure
*/ */
static int IpOptsTestParse04 (void) static int IpOptsTestParse04 (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; ThreadVars tv;
int ret = 0;
DetectIpOptsData *de = NULL;
SigMatch *sm = NULL;
IPV4Hdr ip4h; IPV4Hdr ip4h;
memset(&tv, 0, sizeof(ThreadVars)); memset(&tv, 0, sizeof(ThreadVars));
@ -325,31 +295,22 @@ static int IpOptsTestParse04 (void)
p->ip4h = &ip4h; p->ip4h = &ip4h;
p->ip4vars.opts_set = IPV4_OPT_FLAG_RR; p->ip4vars.opts_set = IPV4_OPT_FLAG_RR;
de = DetectIpOptsParse("lsrr"); DetectIpOptsData *de = DetectIpOptsParse("lsrr");
FAIL_IF_NULL(de);
if (de == NULL)
goto error;
sm = SigMatchAlloc(); SigMatch *sm = SigMatchAlloc();
if (sm == NULL) FAIL_IF_NULL(sm);
goto error;
sm->type = DETECT_IPOPTS; sm->type = DETECT_IPOPTS;
sm->ctx = (SigMatchCtx *)de; sm->ctx = (SigMatchCtx *)de;
ret = DetectIpOptsMatch(NULL, p, NULL, sm->ctx); FAIL_IF(DetectIpOptsMatch(NULL, p, NULL, sm->ctx));
if(ret) { SCFree(de);
SCFree(sm);
SCFree(p); SCFree(p);
return 0;
}
/* Error expected. */ PASS;
error:
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 1;
} }
/** /**

Loading…
Cancel
Save