You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by cm...@apache.org on 2024/03/19 15:06:25 UTC
(trafficserver) 06/06: Fix asan and valgrind issue with libswoc unit test (#11138)
This is an automated email from the ASF dual-hosted git repository.
cmcfarlen pushed a commit to branch 10.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit edd59eae0cdbae01597be7df3fcce454ee37c839
Author: Bryan Call <bc...@apache.org>
AuthorDate: Wed Mar 13 08:42:46 2024 -0700
Fix asan and valgrind issue with libswoc unit test (#11138)
(cherry picked from commit 0bde81a7fac7513ee19e0b6ce4f3c42cf27bc7ea)
---
lib/swoc/unit_tests/ex_IntrusiveDList.cc | 6 +++++
lib/swoc/unit_tests/ex_MemArena.cc | 3 +++
lib/swoc/unit_tests/test_IntrusiveDList.cc | 37 ++++++++++++++++++++++++++++
lib/swoc/unit_tests/test_IntrusiveHashMap.cc | 13 +++++++++-
lib/swoc/unit_tests/test_ip.cc | 2 +-
5 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/lib/swoc/unit_tests/ex_IntrusiveDList.cc b/lib/swoc/unit_tests/ex_IntrusiveDList.cc
index 3c59a9ed47..a26f386662 100644
--- a/lib/swoc/unit_tests/ex_IntrusiveDList.cc
+++ b/lib/swoc/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/lib/swoc/unit_tests/ex_MemArena.cc b/lib/swoc/unit_tests/ex_MemArena.cc
index a6f7098e57..e0e9a038f9 100644
--- a/lib/swoc/unit_tests/ex_MemArena.cc
+++ b/lib/swoc/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/lib/swoc/unit_tests/test_IntrusiveDList.cc b/lib/swoc/unit_tests/test_IntrusiveDList.cc
index 51f57a09e8..96c3e6f61e 100644
--- a/lib/swoc/unit_tests/test_IntrusiveDList.cc
+++ b/lib/swoc/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/lib/swoc/unit_tests/test_IntrusiveHashMap.cc b/lib/swoc/unit_tests/test_IntrusiveHashMap.cc
index aa228ba8e0..cd4db95329 100644
--- a/lib/swoc/unit_tests/test_IntrusiveHashMap.cc
+++ b/lib/swoc/unit_tests/test_IntrusiveHashMap.cc
@@ -158,9 +158,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;
@@ -269,6 +272,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/lib/swoc/unit_tests/test_ip.cc b/lib/swoc/unit_tests/test_ip.cc
index 178e85b72a..2c7aa7ce39 100644
--- a/lib/swoc/unit_tests/test_ip.cc
+++ b/lib/swoc/unit_tests/test_ip.cc
@@ -1094,7 +1094,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}},