detect/threshold: fix unittests for storage based cache

(cherry picked from commit f67dadc3d8)
pull/16123/head
Victor Julien 3 months ago
parent 1794222100
commit b72d0df5a9

@ -485,16 +485,26 @@ static void ThresholdCacheThreadFree(void *ptr)
static void ThresholdCacheInit(void) static void ThresholdCacheInit(void)
{ {
#ifdef UNITTESTS
/* many tests don't manage the thread storage correctly, so skip the cache in unittests */
if (!(RunmodeIsUnittests())) {
#endif
/* Register thread storage. */ /* Register thread storage. */
thread_storage_id = ThreadStorageRegister( thread_storage_id = ThreadStorageRegister(
"threshold_cache", sizeof(void *), NULL, ThresholdCacheThreadFree); "threshold_cache", sizeof(void *), NULL, ThresholdCacheThreadFree);
if (thread_storage_id.id < 0) { if (thread_storage_id.id < 0) {
FatalError("Failed to register threshold_cache thread storage"); FatalError("Failed to register threshold_cache thread storage");
} }
#ifdef UNITTESTS
}
#endif
} }
int ThresholdCacheThreadInit(DetectEngineThreadCtx *det_ctx) int ThresholdCacheThreadInit(DetectEngineThreadCtx *det_ctx)
{ {
if (thread_storage_id.id < 0)
return 0;
struct ThresholdCacheThreadCtx *tctx = SCCalloc(1, sizeof(*tctx)); struct ThresholdCacheThreadCtx *tctx = SCCalloc(1, sizeof(*tctx));
if (tctx == NULL) if (tctx == NULL)
return -1; return -1;

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save