]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1995 in SNORT/snort3 from ~MASHASAN/snort3:fix_reload_tests to...
authorMike Stepanek (mstepane) <mstepane@cisco.com>
Wed, 12 Feb 2020 15:22:24 +0000 (15:22 +0000)
committerMike Stepanek (mstepane) <mstepane@cisco.com>
Wed, 12 Feb 2020 15:22:24 +0000 (15:22 +0000)
Squashed commit of the following:

commit c3ae82898a061d84054fe286738848186b25dd1b
Author: Masud Hasan <mashasan@cisco.com>
Date:   Mon Feb 10 22:04:34 2020 -0500

    host_tracker: Checking lock in a separate thread in unit-test

src/host_tracker/test/CMakeLists.txt
src/host_tracker/test/host_cache_module_test.cc

index b22a7ba6ec3a6dad8b2b5a75216e71bb2d6117c5..a32afdf283be989aeee921ac06c9f3072d718461 100644 (file)
@@ -16,6 +16,8 @@ add_cpputest( host_cache_module_test
         ../../hash/lru_cache_shared.cc
         ../../sfip/sf_ip.cc
         $<TARGET_OBJECTS:catch_tests>
+    LIBS
+        ${CMAKE_THREAD_LIBS_INIT}
 )
 
 add_cpputest( host_tracker_test
index 06972676f14706f58d3d614e930f91f73e6ae667..cdf88c939c826811de49b4404d200f8e8b04e397 100644 (file)
@@ -24,6 +24,7 @@
 #endif
 
 #include <cstdarg>
+#include <thread>
 
 #include "host_tracker/host_cache_module.h"
 #include "host_tracker/host_cache.h"
@@ -88,6 +89,18 @@ TEST_GROUP(host_cache_module)
     }
 };
 
+void try_reload_prune(bool is_not_locked)
+{
+    if ( is_not_locked )
+    {
+        CHECK(host_cache.reload_prune(256, 2) == true);
+    }
+    else
+    {
+        CHECK(host_cache.reload_prune(256, 2) == false);
+    }
+}
+
 // Test stats when HostCacheModule sets/changes host_cache size.
 // This method is a friend of LruCacheSharedMemcap class.
 TEST(host_cache_module, misc)
@@ -121,13 +134,15 @@ TEST(host_cache_module, misc)
     // pruning needed for resizing lower than current size
     CHECK(host_cache.reload_resize(256) == true);
 
-    // pruning is not done when when reload_mutex is already locked
+    // pruning in thread is not done when reload_mutex is already locked
     host_cache.reload_mutex.lock();
-    CHECK(host_cache.reload_prune(256, 2) == false);
+    std::thread test_negative(try_reload_prune, false);
+    test_negative.join();
     host_cache.reload_mutex.unlock();
 
-    // prune 2 entries when reload_mutex is not locked
-    CHECK(host_cache.reload_prune(256, 2) == true);
+    // prune 2 entries in thread when reload_mutex is not locked
+    std::thread test_positive(try_reload_prune, true);
+    test_positive.join();
 
     // alloc_prune 1 entry
     host_cache.find_else_create(ip1, nullptr);