]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
applayer: convert to FAIL/PASS API
authorShivani Bhardwaj <shivanib134@gmail.com>
Fri, 11 Sep 2020 12:43:51 +0000 (18:13 +0530)
committerVictor Julien <victor@inliniac.net>
Wed, 9 Dec 2020 14:24:15 +0000 (15:24 +0100)
src/app-layer-parser.c

index 46385e3bd772824b5a80eedf2b74c5a0244f7883..f94c81ddebb1e527b0bd95c64b65510c6a642653 100644 (file)
@@ -1792,7 +1792,6 @@ static int AppLayerParserTest01(void)
 {
     AppLayerParserBackupParserTable();
 
-    int result = 0;
     Flow *f = NULL;
     uint8_t testbuf[] = { 0x11 };
     uint32_t testlen = sizeof(testbuf);
@@ -1811,37 +1810,24 @@ static int AppLayerParserTest01(void)
     AppLayerParserRegisterGetTxCnt(IPPROTO_TCP, ALPROTO_TEST, TestGetTxCnt);
 
     f = UTHBuildFlow(AF_INET, "1.2.3.4", "4.3.2.1", 20, 40);
-    if (f == NULL)
-        goto end;
+    FAIL_IF_NULL(f);
     f->protoctx = &ssn;
     f->alproto = ALPROTO_TEST;
     f->proto = IPPROTO_TCP;
 
     StreamTcpInitConfig(TRUE);
 
-    FLOWLOCK_WRLOCK(f);
     int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_TEST,
                                 STREAM_TOSERVER | STREAM_EOF, testbuf,
                                 testlen);
-    if (r != -1) {
-        printf("returned %" PRId32 ", expected -1: ", r);
-        FLOWLOCK_UNLOCK(f);
-        goto end;
-    }
-    FLOWLOCK_UNLOCK(f);
+    FAIL_IF(r != -1);
 
-    if (!(ssn.flags & STREAMTCP_FLAG_APP_LAYER_DISABLED)) {
-        printf("flag should have been set, but is not: ");
-        goto end;
-    }
+    FAIL_IF(!(ssn.flags & STREAMTCP_FLAG_APP_LAYER_DISABLED));
 
-    result = 1;
- end:
     AppLayerParserRestoreParserTable();
     StreamTcpFreeConfig(TRUE);
-
     UTHFreeFlow(f);
-    return result;
+    PASS;
 }
 
 /**
@@ -1852,7 +1838,6 @@ static int AppLayerParserTest02(void)
 {
     AppLayerParserBackupParserTable();
 
-    int result = 1;
     Flow *f = NULL;
     uint8_t testbuf[] = { 0x11 };
     uint32_t testlen = sizeof(testbuf);
@@ -1868,31 +1853,22 @@ static int AppLayerParserTest02(void)
     AppLayerParserRegisterGetTxCnt(IPPROTO_UDP, ALPROTO_TEST, TestGetTxCnt);
 
     f = UTHBuildFlow(AF_INET, "1.2.3.4", "4.3.2.1", 20, 40);
-    if (f == NULL)
-        goto end;
+    FAIL_IF_NULL(f);
     f->alproto = ALPROTO_TEST;
     f->proto = IPPROTO_UDP;
     f->protomap = FlowGetProtoMapping(f->proto);
 
     StreamTcpInitConfig(TRUE);
 
-    FLOWLOCK_WRLOCK(f);
     int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_TEST,
                                 STREAM_TOSERVER | STREAM_EOF, testbuf,
                                 testlen);
-    if (r != -1) {
-        printf("returned %" PRId32 ", expected -1: \n", r);
-        result = 0;
-        FLOWLOCK_UNLOCK(f);
-        goto end;
-    }
-    FLOWLOCK_UNLOCK(f);
+    FAIL_IF(r != -1);
 
- end:
     AppLayerParserRestoreParserTable();
     StreamTcpFreeConfig(TRUE);
     UTHFreeFlow(f);
-    return result;
+    PASS;
 }