Browse Source

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.
pull/185/merge
Vladimír Vondruš 10 years ago
parent
commit
1eb26bd1a5
  1. 5
      package/ci/leaksanitizer.conf
  2. 2
      package/ci/travis-desktop.sh
  3. 13
      src/Magnum/Test/ResourceManagerTest.cpp

5
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

2
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

13
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<Int>(rm.get<Int>("blah"));
rm.clear();

Loading…
Cancel
Save