From: Nathan Bronson Date: Fri, 22 Sep 2017 19:01:30 +0000 (-0700) Subject: fix ASAN stl_tests:stl_vector_test X-Git-Tag: v2017.09.25.00~3 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=aee7113e8140c5b873c56be29a429acdbb9a5268;p=folly.git fix ASAN stl_tests:stl_vector_test Summary: folly/test/stl_tests/StlVectorTest.cpp was too slow under mode/dev-asan, resulting in timeouts, and the relinquish test allocated with malloc and freed with operator delete. This diff reduces the vector size for testing under ASAN, and fixes the allocation mismatch. Reviewed By: Orvid Differential Revision: D5890969 fbshipit-source-id: 49a9498f6c0c4b3c7165906efd1262e518fea810 --- diff --git a/folly/test/stl_tests/StlVectorTest.cpp b/folly/test/stl_tests/StlVectorTest.cpp index 7e0139d6..b80b8dfe 100644 --- a/folly/test/stl_tests/StlVectorTest.cpp +++ b/folly/test/stl_tests/StlVectorTest.cpp @@ -657,9 +657,9 @@ struct Alloc : AllocTracker, Ticker { int id; explicit Alloc(int i = 8) : a(), id(i) {} Alloc(const Alloc& o) : a(o.a), id(o.id) {} - Alloc(Alloc&& o) : a(move(o.a)), id(o.id) {} + Alloc(Alloc&& o) noexcept : a(move(o.a)), id(o.id) {} Alloc& operator=(const Alloc&) = default; - Alloc& operator=(Alloc&&) = default; + Alloc& operator=(Alloc&&) noexcept = default; bool operator==(const Alloc& o) const { return a == o.a && id == o.id; } bool operator!=(const Alloc& o) const { return !(*this == o); } @@ -1179,7 +1179,9 @@ static const vector> VectorSizes = { { 1, -1}, { 2, -1}, { 10, -1}, { 10, 1}, { 10, 0}, +#if !FOLLY_SANITIZE_ADDRESS {100, -1}, {100, 1}, +#endif //{ 10, -1}, { 10, 0}, { 10, 1}, { 10, 2}, { 10, 10}, //{ 100, -1}, { 100, 0}, { 100, 1}, { 100, 2}, { 100, 10}, { 100, 100}, @@ -2817,10 +2819,18 @@ STL_TEST("relinquish", relinquish, is_destructible, a) { ASSERT_EQ(0, a.capacity()); auto alloc = a.get_allocator(); - for (size_t i = 0; i < sz; ++i) + for (size_t i = 0; i < sz; ++i) { std::allocator_traits::destroy(alloc, guts + i); - if (guts != nullptr) - std::allocator_traits::deallocate(alloc, guts, cap); + } + if (guts != nullptr) { + if (std::is_same< + decltype(alloc), + std::allocator>::value) { + free(guts); + } else { + std::allocator_traits::deallocate(alloc, guts, cap); + } + } } STL_TEST("attach", attach, is_destructible, a) {