This is an automated email from the ASF dual-hosted git repository. bneradt pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git
commit 5914a4759bf5c77cd2edfe3a81ba906a4e9c6c63 Author: Brian Neradt <[email protected]> AuthorDate: Tue Mar 19 18:16:28 2024 +0000 Fix asan and valgrind issue with libswoc unit test (#11138) (cherry picked from commit 0bde81a7fac7513ee19e0b6ce4f3c42cf27bc7ea) --- unit_tests/ex_IntrusiveDList.cc | 6 ++++++ unit_tests/ex_MemArena.cc | 3 +++ unit_tests/test_IntrusiveDList.cc | 37 +++++++++++++++++++++++++++++++++++++ unit_tests/test_IntrusiveHashMap.cc | 13 ++++++++++++- unit_tests/test_ip.cc | 2 +- 5 files changed, 59 insertions(+), 2 deletions(-) diff --git a/unit_tests/ex_IntrusiveDList.cc b/unit_tests/ex_IntrusiveDList.cc index 3c59a9e..a26f386 100644 --- a/unit_tests/ex_IntrusiveDList.cc +++ b/unit_tests/ex_IntrusiveDList.cc @@ -212,4 +212,10 @@ TEST_CASE("IntrusiveDList Inheritance", "[libswoc][IntrusiveDList][example]") { } REQUIRE(priv2_list.head()->payload() == "Item 1"); REQUIRE(priv2_list.tail()->payload() == "Item 23"); + + // Delete everything in priv_list. + priv_list.apply([](PrivateThing *thing) { delete thing; }); + + // Delete everything in priv2_list. + priv2_list.apply([](PrivateThing2 *thing) { delete thing; }); } diff --git a/unit_tests/ex_MemArena.cc b/unit_tests/ex_MemArena.cc index a6f7098..e0e9a03 100644 --- a/unit_tests/ex_MemArena.cc +++ b/unit_tests/ex_MemArena.cc @@ -221,4 +221,7 @@ TEST_CASE("MemArena example", "[libswoc][MemArena][example]") { REQUIRE(arena.contains(ihm)); REQUIRE(arena.contains(thing)); REQUIRE(arena.contains(thing->name.data())); + + // Call the destructor for the IntrusiveHashMap to free anything it allocated. + ihm->~Map(); }; diff --git a/unit_tests/test_IntrusiveDList.cc b/unit_tests/test_IntrusiveDList.cc index 51f57a0..96c3e6f 100644 --- a/unit_tests/test_IntrusiveDList.cc +++ b/unit_tests/test_IntrusiveDList.cc @@ -118,6 +118,7 @@ TEST_CASE("IntrusiveDList", "[libswoc][IntrusiveDList]") { list.append(thing); list.erase(list.tail()); + delete thing; // this deletes "two" REQUIRE(list.count() == 3); REQUIRE(list.tail() != nullptr); REQUIRE(list.tail()->_payload == "muddle"); @@ -126,6 +127,9 @@ TEST_CASE("IntrusiveDList", "[libswoc][IntrusiveDList]") { list.insert_before(list.end(), new Thing("trailer")); REQUIRE(list.count() == 4); REQUIRE(list.tail()->_payload == "trailer"); + + // Delete everything in list. + list.apply([](Thing *thing) { delete thing; }); } TEST_CASE("IntrusiveDList list prefix", "[libswoc][IntrusiveDList]") { @@ -174,6 +178,21 @@ TEST_CASE("IntrusiveDList list prefix", "[libswoc][IntrusiveDList]") { REQUIRE(list_rest.head()->_payload == "16"); REQUIRE(list.count() == 0); REQUIRE(list.head() == nullptr); + + // Delete everything in list. + list.apply([](Thing *thing) { delete thing; }); + + // Delete everything in list_1. + list_1.apply([](Thing *thing) { delete thing; }); + + // Delete everything in list_5. + list_5.apply([](Thing *thing) { delete thing; }); + + // Delete everything in list_most. + list_most.apply([](Thing *thing) { delete thing; }); + + // Delete everything in list_rest. + list_rest.apply([](Thing *thing) { delete thing; }); } TEST_CASE("IntrusiveDList list suffix", "[libswoc][IntrusiveDList]") { @@ -230,6 +249,21 @@ TEST_CASE("IntrusiveDList list suffix", "[libswoc][IntrusiveDList]") { REQUIRE(list.tail()->_payload == "20"); REQUIRE(list.nth(7)->_payload == "8"); REQUIRE(list.nth(17)->_payload == "18"); + + // Delete everything in list. + list.apply([](Thing *thing) { delete thing; }); + + // Delete everything in list_1. + list_1.apply([](Thing *thing) { delete thing; }); + + // Delete everything in list_5. + list_5.apply([](Thing *thing) { delete thing; }); + + // Delete everything in list_most. + list_most.apply([](Thing *thing) { delete thing; }); + + // Delete everything in list_rest. + list_rest.apply([](Thing *thing) { delete thing; }); } TEST_CASE("IntrusiveDList Extra", "[libswoc][IntrusiveDList]") { @@ -269,4 +303,7 @@ TEST_CASE("IntrusiveDList Extra", "[libswoc][IntrusiveDList]") { bwprint(tmp, "{}", idx); REQUIRE(spot->_payload == tmp); } + + // Delete everything in list. + list.apply([](Thing *thing) { delete thing; }); } diff --git a/unit_tests/test_IntrusiveHashMap.cc b/unit_tests/test_IntrusiveHashMap.cc index 1844ae3..e3fa247 100644 --- a/unit_tests/test_IntrusiveHashMap.cc +++ b/unit_tests/test_IntrusiveHashMap.cc @@ -122,9 +122,12 @@ TEST_CASE("IntrusiveHashMap", "[libts][IntrusiveHashMap]") { // Erase all the non-"dup" and see if the range is still correct. map.apply([&map](Thing &thing) { - if (thing._payload != "dup"sv) + if (thing._payload != "dup"sv) { map.erase(map.iterator_for(&thing)); + delete &thing; + } }); + r = map.equal_range("dup"sv); REQUIRE(r.first != r.second); idx = r.first; @@ -225,6 +228,14 @@ TEST_CASE("IntrusiveHashMapManyStrings", "[IntrusiveHashMap]") { } } REQUIRE(miss_p == false); + + // Delete everything in strings. + for (auto &&s : strings) { + free(const_cast<char *>(s.data())); + } + + // Delete everything in ihm. + ihm.apply([](Thing *thing) { delete thing; }); }; TEST_CASE("IntrusiveHashMap Utilities", "[IntrusiveHashMap]") {} diff --git a/unit_tests/test_ip.cc b/unit_tests/test_ip.cc index f848978..b41c1a0 100644 --- a/unit_tests/test_ip.cc +++ b/unit_tests/test_ip.cc @@ -1093,7 +1093,7 @@ TEST_CASE("IPSpace bitset", "[libswoc][ipspace][bitset]") { using PAYLOAD = std::bitset<32>; using Space = swoc::IPSpace<PAYLOAD>; - std::array<std::tuple<TextView, std::initializer_list<unsigned>>, 6> ranges = { + std::vector<std::tuple<TextView, std::vector<unsigned>>> ranges = { {{"172.28.56.12-172.28.56.99"_tv, {0, 2, 3}}, {"10.10.35.0/24"_tv, {1, 2}}, {"192.168.56.0/25"_tv, {10, 12, 31}},
