]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
separate piglet, check, and catch tests; add catch tests for sfrim
authorruss <rucombs@cisco.com>
Tue, 8 Sep 2015 15:48:59 +0000 (11:48 -0400)
committerruss <rucombs@cisco.com>
Tue, 8 Sep 2015 15:48:59 +0000 (11:48 -0400)
src/detection/sfrim.cc
src/main.cc
src/main/snort_module.cc
src/test/unit_test.cc
src/test/unit_test.h

index 828b2107855e0f4fa77c978c9e54d640f0c3c5ce..a8553ba99a0d92c7ef4638be30861662c39fbebd 100644 (file)
 
 #include "sfrim.h"
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 
 #include <vector>
 
-#include "utils/util.h"
+#ifdef UNIT_TEST
+#include "test/catch.hpp"
+#endif
 
 struct rule_number_t
 {
@@ -80,3 +86,37 @@ bool RuleIndexMapGet(rule_index_map_t* rim, int index, unsigned& gid, unsigned&
     return false;
 }
 
+//--------------------------------------------------------------------------
+// unit tests
+//--------------------------------------------------------------------------
+
+#ifdef UNIT_TEST
+
+TEST_CASE("basic", "[RuleIndexMap]")
+{
+    rule_index_map_t* rim = RuleIndexMapCreate();
+    unsigned gid, sid;
+
+    CHECK(RuleIndexMapAdd(rim, 1, 2) == 0);
+    CHECK(RuleIndexMapAdd(rim, 2, 4) == 1);
+    CHECK(RuleIndexMapAdd(rim, 4, 8) == 2);
+
+    SECTION("valid")
+    {
+        CHECK(RuleIndexMapGet(rim, 1, gid, sid));
+
+        CHECK(gid == 2);
+        CHECK(sid == 4);
+    }
+    SECTION("invalid")
+    {
+        CHECK(!RuleIndexMapGet(rim, 3, gid, sid));
+
+        CHECK(gid == 0);
+        CHECK(sid == 0);
+    }
+    RuleIndexMapFree(rim);
+}
+
+#endif
+
index e20aec3f3c9ab60733f8dd43bb226a39cafd8f00..3fc10665fbf569c33014131acd5abb292930719f 100644 (file)
@@ -692,24 +692,16 @@ static bool just_validate()
 static bool set_mode()
 {
 #ifdef PIGLET
-#ifdef UNIT_TEST
-    if ( unit_test_enabled() )
-    {
-        if ( Piglet::piglet_mode() )
-            exit(unit_test() || Piglet::main());
-        else
-            exit(unit_test());
-    }
-    else 
-#endif // UNIT_TEST
     if ( Piglet::piglet_mode() )
         exit(Piglet::main());
-#else
+#endif
 #ifdef UNIT_TEST
-    if ( unit_test_enabled() )
-        exit(unit_test());
-#endif // UNIT_TEST
-#endif // PIGLET
+    if ( check_enabled() )
+        exit(check_test());
+
+    if ( catch_enabled() )
+        exit(catch_test());
+#endif
 
     if ( int k = get_parse_errors() )
     {
index 7a95afbea7c8b74cb36a8c28b5fd45a1a3d17476..6483790599c5e3b1a294603715ef6c56a9c0b34d 100644 (file)
@@ -441,11 +441,12 @@ static const Parameter s_params[] =
       "use drop, sdrop, and reject rules to ignore session traffic when not inline" },
 
 #ifdef UNIT_TEST
-    { "--unit-test", Parameter::PT_SELECT,
+    { "--check-test", Parameter::PT_SELECT,
       "silent | minimal | normal | verbose | env (export CK_VERBOSITY)", nullptr,
       "<verbosity> run unit tests with given libcheck output mode" },
-    { "--catch-tags", Parameter::PT_STRING, nullptr, nullptr,
-        "comma separated list of cat unit test tags" },
+
+    { "--catch-test", Parameter::PT_STRING, nullptr, nullptr,
+        "comma separated list of cat unit test tags or 'all'" },
 #endif
     { "--version", Parameter::PT_IMPLIED, nullptr, nullptr,
       "show version number (same as -V)" },
@@ -834,9 +835,10 @@ bool SnortModule::set(const char*, Value& v, SnortConfig* sc)
         ConfigTreatDropAsIgnore(sc, v.get_string());
 
 #ifdef UNIT_TEST
-    else if ( v.is("--unit-test") )
+    else if ( v.is("--check-test") )
         unit_test_mode(v.get_string());
-    else if ( v.is("--catch-tags") )
+
+    else if ( v.is("--catch-test") )
         unit_test_catch_test_filter(v.get_string());
 #endif
     else if ( v.is("--version") )
index 616b45ca65bf32cb274956e67675fa73fea02676..6f4bfee5f17b5d9696e1c9a30cda9976af296b34 100644 (file)
@@ -39,6 +39,7 @@
 #include "suite_decl.h"
 
 static print_output s_mode = CK_LAST;
+static bool s_catch = false;
 static std::vector<std::string> test_tags;
 
 typedef Suite* (* SuiteCtor_f)();
@@ -72,14 +73,22 @@ void unit_test_mode(const char* s)
 
 void unit_test_catch_test_filter(const char* s)
 {
-    test_tags.push_back( s );
+    if ( s && strcmp(s, "all") )
+        test_tags.push_back( s );
+
+    s_catch = true;
 }
 
-bool unit_test_enabled()
+bool check_enabled()
 {
     return s_mode != CK_LAST;
 }
 
+bool catch_enabled()
+{
+    return s_catch;
+}
+
 static bool run_check()
 {
     int nErr;
@@ -127,25 +136,30 @@ static bool run_check()
 static bool run_catch()
 {
   Catch::Session session;
+
   // write to session.configData() or session.Config() to customize
   if( s_mode == CK_VERBOSE )
       session.configData().showSuccessfulTests = true;
+
   if( test_tags.size() > 0 )
       session.configData().testsOrTags = test_tags;
 
   return session.run() == 0;
 }
 
-int unit_test()
+int check_test()
 {
-    int ok = 0;
-
     if ( !run_check() )
-        ok = -1;
+        return -1;
 
+    return 0;
+}
+
+int catch_test()
+{
     if ( !run_catch() )
-        ok = -1;
+        return -1;
 
-    return ok;
+    return 0;
 }
 
index 9598f2af069b0ce0bce3ab39a3ae873a100978f3..74c7fd3571568a1b89a6bb096aed0430dfa2ecae 100644 (file)
 #define UNIT_TEST_MODE_ENVVAR "CK_VERBOSITY"
 
 void unit_test_mode(const char* = nullptr);
-bool unit_test_enabled();
-int unit_test();
 void unit_test_catch_test_filter(const char* s);
 
+bool check_enabled();
+bool catch_enabled();
+
+int check_test();
+int catch_test();
 #endif