From: Steve Chew (stechew) Date: Wed, 20 Apr 2022 21:49:22 +0000 (+0000) Subject: Pull request #3389: host_cache: fix unit test broken on some platforms X-Git-Tag: 3.1.28.0~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cbed3e7eebcdfb7ade340c352695a21c3bf36b81;p=thirdparty%2Fsnort3.git Pull request #3389: host_cache: fix unit test broken on some platforms Merge in SNORT/snort3 from ~SMINUT/snort3:host_cache_test_fix to master Squashed commit of the following: commit f15830798d33af96629bfac0ead75ee2cd743209 Author: Silviu Minut Date: Wed Apr 20 10:59:58 2022 -0400 host_cache: fix unit test broken on some platforms --- diff --git a/src/host_tracker/test/host_cache_module_test.cc b/src/host_tracker/test/host_cache_module_test.cc index 9c1724dfd..4e0d2e5d0 100644 --- a/src/host_tracker/test/host_cache_module_test.cc +++ b/src/host_tracker/test/host_cache_module_test.cc @@ -104,6 +104,9 @@ static void try_reload_prune(bool is_not_locked) // This method is a friend of LruCacheSharedMemcap class. TEST(host_cache_module, misc) { + // memory chunk, computed as in the base cache class + static constexpr size_t mc = sizeof(HostCacheIp::Data) + sizeof(HostCacheIp::ValueType); + const PegInfo* ht_pegs = module.get_pegs(); const PegCount* ht_stats = module.get_counts(); @@ -132,19 +135,19 @@ TEST(host_cache_module, misc) host_cache.find_else_create(ip3, nullptr); module.sum_stats(true); // does not call reset CHECK(ht_stats[0] == 3); - CHECK(ht_stats[2] == 1992); // bytes_in_use + CHECK(ht_stats[2] == 3*mc); // bytes_in_use CHECK(ht_stats[3] == 3); // items_in_use // no pruning needed for resizing higher than current size CHECK(host_cache.reload_resize(host_cache.mem_chunk * 10) == false); module.sum_stats(true); - CHECK(ht_stats[2] == 1992); // bytes_in_use unchanged + CHECK(ht_stats[2] == 3*mc); // bytes_in_use unchanged CHECK(ht_stats[3] == 3); // items_in_use unchanged // pruning needed for resizing lower than current size CHECK(host_cache.reload_resize(host_cache.mem_chunk * 1.5) == true); module.sum_stats(true); - CHECK(ht_stats[2] == 1992); // bytes_in_use still unchanged + CHECK(ht_stats[2] == 3*mc); // bytes_in_use still unchanged CHECK(ht_stats[3] == 3); // items_in_use still unchanged // pruning in thread is not done when reload_mutex is already locked @@ -153,7 +156,7 @@ TEST(host_cache_module, misc) test_negative.join(); host_cache.reload_mutex.unlock(); module.sum_stats(true); - CHECK(ht_stats[2] == 1992); // no pruning yet + CHECK(ht_stats[2] == 3*mc); // no pruning yet CHECK(ht_stats[3] == 3); // no pruning_yet // prune 2 entries in thread when reload_mutex is not locked @@ -161,7 +164,7 @@ TEST(host_cache_module, misc) test_positive.join(); module.sum_stats(true); - CHECK(ht_stats[2] == 664); + CHECK(ht_stats[2] == mc); CHECK(ht_stats[3] == 1); // one left // alloc_prune 1 entry