From: Modupe Falodun Date: Mon, 6 Dec 2021 08:28:42 +0000 (+0100) Subject: detect-ipopts: convert unittests to FAIL/PASS APIs X-Git-Tag: suricata-7.0.0-beta1~1133 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76131c8cff1c5b895b49f2fecdf37764551cc7bb;p=thirdparty%2Fsuricata.git detect-ipopts: convert unittests to FAIL/PASS APIs Bug: 4047 --- diff --git a/src/detect-ipopts.c b/src/detect-ipopts.c index 787b2002ef..9bd02dd2bb 100644 --- a/src/detect-ipopts.c +++ b/src/detect-ipopts.c @@ -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 * 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 /** * \test IpOptsTestParse01 is a test for a valid ipopts value - * - * \retval 1 on succces - * \retval 0 on failure */ static int IpOptsTestParse01 (void) { - DetectIpOptsData *de = NULL; - de = DetectIpOptsParse("lsrr"); - if (de) { - DetectIpOptsFree(NULL, de); - return 1; - } + DetectIpOptsData *de = DetectIpOptsParse("lsrr"); - return 0; + FAIL_IF_NULL(de); + + DetectIpOptsFree(NULL, de); + + PASS; } /** * \test IpOptsTestParse02 is a test for an invalid ipopts value - * - * \retval 1 on succces - * \retval 0 on failure */ static int IpOptsTestParse02 (void) { - DetectIpOptsData *de = NULL; - de = DetectIpOptsParse("invalidopt"); - if (de) { - DetectIpOptsFree(NULL, de); - return 0; - } + DetectIpOptsData *de = DetectIpOptsParse("invalidopt"); + + FAIL_IF_NOT_NULL(de); - return 1; + DetectIpOptsFree(NULL, de); + + PASS; } /** * \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) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (unlikely(p == NULL)) - return 0; + FAIL_IF_NULL(p); ThreadVars tv; - int ret = 0; - DetectIpOptsData *de = NULL; - SigMatch *sm = NULL; IPV4Hdr ip4h; memset(&tv, 0, sizeof(ThreadVars)); @@ -275,47 +260,32 @@ static int IpOptsTestParse03 (void) p->ip4h = &ip4h; p->ip4vars.opts_set = IPV4_OPT_FLAG_RR; - de = DetectIpOptsParse("rr"); - - if (de == NULL) - goto error; + DetectIpOptsData *de = DetectIpOptsParse("rr"); + FAIL_IF_NULL(de); - sm = SigMatchAlloc(); - if (sm == NULL) - goto error; + SigMatch *sm = SigMatchAlloc(); + FAIL_IF_NULL(sm); sm->type = DETECT_IPOPTS; sm->ctx = (SigMatchCtx *)de; - ret = DetectIpOptsMatch(NULL, p, NULL, sm->ctx); - - if(ret) { - SCFree(p); - return 1; - } + FAIL_IF_NOT(DetectIpOptsMatch(NULL, p, NULL, sm->ctx)); -error: - if (de) SCFree(de); - if (sm) SCFree(sm); + SCFree(de); + SCFree(sm); SCFree(p); - return 0; + + PASS; } /** * \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) { Packet *p = SCMalloc(SIZE_OF_PACKET); - if (unlikely(p == NULL)) - return 0; + FAIL_IF_NULL(p); ThreadVars tv; - int ret = 0; - DetectIpOptsData *de = NULL; - SigMatch *sm = NULL; IPV4Hdr ip4h; memset(&tv, 0, sizeof(ThreadVars)); @@ -325,31 +295,22 @@ static int IpOptsTestParse04 (void) p->ip4h = &ip4h; p->ip4vars.opts_set = IPV4_OPT_FLAG_RR; - de = DetectIpOptsParse("lsrr"); - - if (de == NULL) - goto error; + DetectIpOptsData *de = DetectIpOptsParse("lsrr"); + FAIL_IF_NULL(de); - sm = SigMatchAlloc(); - if (sm == NULL) - goto error; + SigMatch *sm = SigMatchAlloc(); + FAIL_IF_NULL(sm); sm->type = DETECT_IPOPTS; sm->ctx = (SigMatchCtx *)de; - ret = DetectIpOptsMatch(NULL, p, NULL, sm->ctx); - - if(ret) { - SCFree(p); - return 0; - } + FAIL_IF(DetectIpOptsMatch(NULL, p, NULL, sm->ctx)); - /* Error expected. */ -error: - if (de) SCFree(de); - if (sm) SCFree(sm); + SCFree(de); + SCFree(sm); SCFree(p); - return 1; + + PASS; } /**