]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Port unittest from bug #970 for util-mpm-ac.c to util-mpm-ac-tile.c
authorKen Steele <ken@tilera.com>
Wed, 8 Jan 2014 15:46:04 +0000 (10:46 -0500)
committerVictor Julien <victor@inliniac.net>
Fri, 10 Jan 2014 14:01:08 +0000 (15:01 +0100)
Passes on ac-tile too.

src/util-mpm-ac-tile.c

index f3dba0b26efe9c71c30d302161a1f62e53174fbe..c2d89e2902ddfdeeaf84bbb510422d9c188312bd 100644 (file)
 #include "suricata.h"
 
 #include "detect.h"
+#include "detect-parse.h"
+#include "detect-engine.h"
 
 #include "conf.h"
 #include "util-debug.h"
 #include "util-unittest.h"
+#include "util-unittest-helper.h"
 #include "util-memcmp.h"
 #include "util-mpm-ac-tile.h"
 
@@ -2744,6 +2747,60 @@ static int SCACTileTest28(void)
     return result;
 }
 
+static int SCACTileTest29(void)
+{
+    uint8_t *buf = (uint8_t *)"onetwothreefourfivesixseveneightnine";
+    uint16_t buflen = strlen((char *)buf);
+    Packet *p = NULL;
+    ThreadVars th_v;
+    DetectEngineThreadCtx *det_ctx = NULL;
+    int result = 0;
+
+    memset(&th_v, 0, sizeof(th_v));
+    p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
+
+    DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+    if (de_ctx == NULL)
+        goto end;
+
+    de_ctx->flags |= DE_QUIET;
+
+    de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
+                               "(content:\"onetwothreefourfivesixseveneightnine\"; sid:1;)");
+    if (de_ctx->sig_list == NULL)
+        goto end;
+    de_ctx->sig_list->next = SigInit(de_ctx, "alert tcp any any -> any any "
+                               "(content:\"onetwothreefourfivesixseveneightnine\"; fast_pattern:3,3; sid:2;)");
+    if (de_ctx->sig_list->next == NULL)
+        goto end;
+
+    SigGroupBuild(de_ctx);
+    DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
+
+    SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
+    if (PacketAlertCheck(p, 1) != 1) {
+        printf("if (PacketAlertCheck(p, 1) != 1) failure\n");
+        goto end;
+    }
+    if (PacketAlertCheck(p, 2) != 1) {
+        printf("if (PacketAlertCheck(p, 1) != 2) failure\n");
+        goto end;
+    }
+
+    result = 1;
+end:
+    if (de_ctx != NULL) {
+        SigGroupCleanup(de_ctx);
+        SigCleanSignatures(de_ctx);
+
+        DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
+        DetectEngineCtxFree(de_ctx);
+    }
+
+    UTHFreePackets(&p, 1);
+    return result;
+}
+
 #endif /* UNITTESTS */
 
 void SCACTileRegisterTests(void)
@@ -2778,6 +2835,7 @@ void SCACTileRegisterTests(void)
     UtRegisterTest("SCACTileTest26", SCACTileTest26, 1);
     UtRegisterTest("SCACTileTest27", SCACTileTest27, 1);
     UtRegisterTest("SCACTileTest28", SCACTileTest28, 1);
+    UtRegisterTest("SCACTileTest29", SCACTileTest29, 1);
 #endif
 
     return;