]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1407 in SNORT/snort3 from ips_context_unit_test_fix to master
authorRuss Combs (rucombs) <rucombs@cisco.com>
Fri, 26 Oct 2018 18:00:59 +0000 (14:00 -0400)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Fri, 26 Oct 2018 18:00:59 +0000 (14:00 -0400)
Squashed commit of the following:

commit b63007603bd955f92551d3ec4f011e5d22460f30
Author: Bhagya Tholpady <bbantwal@cisco.com>
Date:   Fri Oct 26 13:19:55 2018 -0400

    detection : add function to clear ips_id from unit tests

src/detection/ips_context.cc
src/detection/ips_context_data.cc
src/detection/ips_context_data.h
src/service_inspectors/gtp/gtp_inspect.cc

index 194cf63721bbd0ecb10b63b2762dce5648894c0f..e22495780cd7d5d3272c001dc5ec8a300375e962 100644 (file)
@@ -134,11 +134,10 @@ public:
 };
 
 int TestData::count = 0;
-static unsigned ips_id = 0;
 
 TEST_CASE("IpsContext basic", "[IpsContext]")
 {
-    ips_id = 0;
+    IpsContextData::clear_ips_id();
     IpsContext ctx(4);
     int num_data = 0;
 
index 44e38a5c4e34fa0d6f464dfde4e3be58dbec1e7d..230619b585c6f6edb12f6e4546ec2e609ff1a278 100644 (file)
@@ -37,9 +37,7 @@ using namespace snort;
 // context data
 //--------------------------------------------------------------------------
 
-// ips_id is not a member of context data so that
-// tests (and only tests) can reset the id
-static unsigned ips_id = 0;
+unsigned IpsContextData::ips_id = 0;
 static unsigned max_id = IpsContext::max_ips_id;
 
 unsigned IpsContextData::get_ips_id()
@@ -49,6 +47,11 @@ unsigned IpsContextData::get_ips_id()
     return ips_id; 
 }
 
+void IpsContextData::clear_ips_id()
+{
+    ips_id = 0;
+}
+
 //--------------------------------------------------------------------------
 // unit tests
 //--------------------------------------------------------------------------
@@ -57,7 +60,7 @@ unsigned IpsContextData::get_ips_id()
 
 TEST_CASE("IpsContextData id", "[IpsContextData]")
 {
-    ips_id = 0;
+    IpsContextData::clear_ips_id();
 
     auto id1 = IpsContextData::get_ips_id();
     auto id2 = IpsContextData::get_ips_id();
index 5b79df8631ce8e586108fe1ce456eae48db62f54..437b55ce5b47685b2b26cd4cd720cf7689041d00 100644 (file)
@@ -33,6 +33,9 @@ public:
     virtual ~IpsContextData() = default;
 
     static unsigned get_ips_id();
+    // Only unit tests can call this function to clear the id
+    static void clear_ips_id();
+
     template<typename T>
     static T* get(unsigned ips_id)
     {
@@ -48,6 +51,9 @@ public:
 
 protected:
     IpsContextData() = default;
+
+private:
+    static unsigned ips_id;
 };
 }
 #endif
index a6b3b239e28d21ba5c04ed2d8e6f65f4ee3e2ed6..e7edc3bbefccf9d70bb0c979191569edf4c20b31 100644 (file)
@@ -65,7 +65,7 @@ GtpFlowData::~GtpFlowData()
 // ips context stuff
 //-------------------------------------------------------------------------
 
-static unsigned ips_id = 0;
+static unsigned gtp_ips_id = 0;
 
 // This table stores all the information elements in a packet
 // To save memory, only one table for each ips context.
@@ -80,14 +80,14 @@ public:
     { memset(gtp_ies, 0, sizeof(gtp_ies)); }
 
     static void init()
-    { ips_id = IpsContextData::get_ips_id(); }
+    { gtp_ips_id = IpsContextData::get_ips_id(); }
 
     GTP_IEData gtp_ies[MAX_GTP_IE_CODE + 1];
 };
 
 GTP_IEData* get_infos()
 {
-    GtpContextData* gcd = IpsContextData::get<GtpContextData>(ips_id);
+    GtpContextData* gcd = IpsContextData::get<GtpContextData>(gtp_ips_id);
 
     return gcd->gtp_ies;
 }