From: Victor Julien Date: Tue, 20 Jan 2015 10:25:02 +0000 (+0100) Subject: unittests: add exception to detect engine setup X-Git-Tag: suricata-2.1beta4~131 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b038b6a2f87549474503ff80c2e5586ccd02c92d;p=thirdparty%2Fsuricata.git unittests: add exception to detect engine setup Add code to allow for unittests not following the complete api. Update replace tests as they don't use the unittests runmode that powers the workaround based on RunmodeIsUnittests(). --- diff --git a/src/detect-engine.c b/src/detect-engine.c index b81fe74ef7..7e0f57138a 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -1559,8 +1559,17 @@ TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data) det_ctx->tv = tv; det_ctx->de_ctx = DetectEngineGetCurrent(); if (det_ctx->de_ctx == NULL) { +#ifdef UNITTESTS + if (RunmodeIsUnittests()) { + det_ctx->de_ctx = (DetectEngineCtx *)initdata; + } else { + DetectEngineThreadCtxDeinit(tv, det_ctx); + return TM_ECODE_FAILED; + } +#else DetectEngineThreadCtxDeinit(tv, det_ctx); return TM_ECODE_FAILED; +#endif } if (ThreadCtxDoInit(det_ctx->de_ctx, det_ctx) != TM_ECODE_OK) { @@ -1705,7 +1714,12 @@ TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data) } DetectEngineThreadCtxDeinitKeywords(det_ctx->de_ctx, det_ctx); +#ifdef UNITTESTS + if (!RunmodeIsUnittests() || det_ctx->de_ctx->ref_cnt > 0) + DetectEngineDeReference(&det_ctx->de_ctx); +#else DetectEngineDeReference(&det_ctx->de_ctx); +#endif SCFree(det_ctx); return TM_ECODE_OK; diff --git a/src/detect-replace.c b/src/detect-replace.c index 6031c31184..3bf725a992 100644 --- a/src/detect-replace.c +++ b/src/detect-replace.c @@ -261,9 +261,11 @@ int DetectReplaceLongPatternMatchTest(uint8_t *raw_eth_pkt, uint16_t pktsize, ch } SigGroupBuild(de_ctx); - DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx); + DetectEngineAddToMaster(de_ctx); + DetectEngineThreadCtxInit(&th_v, NULL, (void *)&det_ctx); SigMatchSignatures(&th_v, de_ctx, det_ctx, p); + DetectEngineMoveToFreeList(de_ctx); if (PacketAlertCheck(p, sid) != 1) { SCLogDebug("replace: no alert on sig %d", sid); @@ -281,14 +283,9 @@ int DetectReplaceLongPatternMatchTest(uint8_t *raw_eth_pkt, uint16_t pktsize, ch end: if (dtv.app_tctx != NULL) AppLayerDestroyCtxThread(dtv.app_tctx); - if (de_ctx != NULL) - { - SigGroupCleanup(de_ctx); - SigCleanSignatures(de_ctx); - if (det_ctx != NULL) - DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx); - DetectEngineCtxFree(de_ctx); - } + if (det_ctx != NULL) + DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx); + DetectEnginePruneFreeList(); PACKET_RECYCLE(p); FlowShutdown(); SCFree(p);