From 1eb26bd1a571ade4f74f539e8986268bbb18d422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 26 Nov 2016 12:41:20 +0100 Subject: [PATCH] Test: workaround/suppress leaks when ResourceManager is asserting. The code is bad (yes, I know), but these should be harmless as the leaks are really only when asserting. --- package/ci/leaksanitizer.conf | 5 +++++ package/ci/travis-desktop.sh | 2 +- src/Magnum/Test/ResourceManagerTest.cpp | 13 ++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 package/ci/leaksanitizer.conf diff --git a/package/ci/leaksanitizer.conf b/package/ci/leaksanitizer.conf new file mode 100644 index 000000000..2a5e330ca --- /dev/null +++ b/package/ci/leaksanitizer.conf @@ -0,0 +1,5 @@ +# Configuration file for LeakSanitizer run on the Travis CI + +# The test case intentionally leaks because there is currently no other way to +# trigger given behavior without asserting elsewhere +leak:Magnum::Test::ResourceManagerTest::clearWhileReferenced diff --git a/package/ci/travis-desktop.sh b/package/ci/travis-desktop.sh index 63ebee512..f1cc52d26 100755 --- a/package/ci/travis-desktop.sh +++ b/package/ci/travis-desktop.sh @@ -38,4 +38,4 @@ cmake .. \ -DBUILD_TESTS=ON \ -DBUILD_GL_TESTS=ON make -j${JOBS_LIMIT} -ASAN_OPTIONS="color=always" LSAN_OPTIONS="color=always" CORRADE_TEST_COLOR=ON ctest -V -E GLTest +ASAN_OPTIONS="color=always" LSAN_OPTIONS="color=always suppressions=$TRAVIS_BUILD_DIR/package/ci/leaksanitizer.conf" CORRADE_TEST_COLOR=ON ctest -V -E GLTest diff --git a/src/Magnum/Test/ResourceManagerTest.cpp b/src/Magnum/Test/ResourceManagerTest.cpp index c35b07ffe..af3234011 100644 --- a/src/Magnum/Test/ResourceManagerTest.cpp +++ b/src/Magnum/Test/ResourceManagerTest.cpp @@ -132,7 +132,8 @@ void ResourceManagerTest::stateDisallowed() { std::ostringstream out; Error redirectError{&out}; - rm.set("data", Data(), ResourceDataState::Loading, ResourcePolicy::Resident); + Data d; /* Done this way to prevent memory leak on assertion (yes, the code is bad) */ + rm.set("data", &d, ResourceDataState::Loading, ResourcePolicy::Resident); CORRADE_COMPARE(out.str(), "ResourceManager::set(): data should be null if and only if state is NotFound or Loading\n"); out.str({}); @@ -161,7 +162,8 @@ void ResourceManagerTest::basic() { /* Cannot change already final resource */ std::ostringstream out; Error redirectError{&out}; - rm.set(answerKey, 43, ResourceDataState::Mutable, ResourcePolicy::Resident); + int a = 43; /* Done this way to prevent a memory leak on assert (yes, the code is bad) */ + rm.set(answerKey, &a, ResourceDataState::Mutable, ResourcePolicy::Resident); CORRADE_COMPARE(*theAnswer, 42); CORRADE_COMPARE(out.str(), "ResourceManager::set(): cannot change already final resource " + answerKey.hexString() + '\n'); @@ -263,9 +265,10 @@ void ResourceManagerTest::clearWhileReferenced() { Error redirectError{&out}; ResourceManager rm; - rm.set("blah", Int()); - /** @todo this will leak, is there any better solution without hitting - assertion in decrementReferenceCount()? */ + int a{}; /* Done this way to prevent leak on assertion (yes, the code is bad) */ + rm.set("blah", &a); + /** @todo this will leak, is there any better solution without hitting assertion in decrementReferenceCount()? */ + /** @todo remove the suppression from package/ci/leaksanitizer.conf then */ new Resource(rm.get("blah")); rm.clear();