Browse Source

More lib utils tests, found a small leak

tags/1.9.4
falkTX 10 years ago
parent
commit
08e3feac51
2 changed files with 34 additions and 3 deletions
  1. +26
    -1
      source/tests/CarlaUtils.cpp
  2. +8
    -2
      source/utils/CarlaLibCounter.hpp

+ 26
- 1
source/tests/CarlaUtils.cpp View File

@@ -36,7 +36,7 @@
#include "CarlaLv2Utils.hpp"
#include "CarlaVstUtils.hpp"

#include "CarlaLibUtils.hpp"
#include "CarlaLibCounter.hpp"
#include "CarlaShmUtils.hpp"

// used in dssi utils
@@ -622,6 +622,31 @@ static void test_CarlaLibUtils() noexcept

const bool closed = lib_close(lib);
CARLA_SAFE_ASSERT(closed);

LibCounter lc;
void* const test1 = lc.open("/usr/lib/liblo.so");
void* const test2 = lc.open("/usr/lib/liblo.so");
void* const test3 = lc.open("/usr/lib/liblo.so");
assert(test1 == test2);
assert(test2 == test3);
lc.close(test1); lc.close(test2); lc.close(test3);

// test if the pointer changes after all closed
void* const test1b = lc.open("/usr/lib/liblo.so");
assert(test1 != test1b);
lc.close(test1b);

// test non-delete flag
void* const test4 = lc.open("/usr/lib/liblrdf.so.0", false);
lc.close(test4);
void* const test5 = lc.open("/usr/lib/liblrdf.so.0");
assert(test4 == test5);
lc.close(test5);

// open non-delete a few times, tests for cleanup on destruction
lc.open("/usr/lib/liblrdf.so.0");
lc.open("/usr/lib/liblrdf.so.0");
lc.open("/usr/lib/liblrdf.so.0");
}

#if 0


+ 8
- 2
source/utils/CarlaLibCounter.hpp View File

@@ -38,6 +38,9 @@ public:
CARLA_SAFE_ASSERT_CONTINUE(lib.count > 0);
CARLA_SAFE_ASSERT_CONTINUE(lib.lib != nullptr);

// all libs should be closed by now except those explicitly marked non-delete
CARLA_SAFE_ASSERT(! lib.canDelete);

if (! lib_close(lib.lib))
carla_stderr("LibCounter cleanup failed, reason:\n%s", lib_error(lib.filename));

@@ -65,7 +68,7 @@ public:
}
CARLA_SAFE_EXCEPTION_RETURN("LibCounter::open", nullptr);

const CarlaMutexLocker sl(fMutex);
const CarlaMutexLocker cml(fMutex);

for (LinkedList<Lib>::Itenerator it = fLibs.begin(); it.valid(); it.next())
{
@@ -75,6 +78,9 @@ public:

if (std::strcmp(lib.filename, filename) == 0)
{
// will not be needed
delete[] dfilename;

++lib.count;
return lib.lib;
}
@@ -105,7 +111,7 @@ public:
{
CARLA_SAFE_ASSERT_RETURN(libPtr != nullptr, false);

const CarlaMutexLocker sl(fMutex);
const CarlaMutexLocker cml(fMutex);

for (LinkedList<Lib>::Itenerator it = fLibs.begin(); it.valid(); it.next())
{


Loading…
Cancel
Save