35 #include <gtest/gtest.h>
42 #include <boost/thread.hpp>
44 #if __unix__ && !APPLE
48 using namespace rosrt;
61 TEST(MallocWrappers, statsMainThread)
68 for (uint32_t i = 1; i <= 1000; ++i)
76 ASSERT_EQ(info.
frees, i);
88 for (uint32_t i = 1; i <= 1000; ++i)
111 TEST(MallocWrappers, statsNewThread)
114 boost::thread t(boost::bind(
statsThread, boost::ref(failed)));
117 ASSERT_FALSE(failed.load());
121 #if __unix__ && !APPLE
122 TEST(MallocWrappers, sharedObjectDynamicallyOpened)
124 void* handle = dlopen(
"libtest_malloc_wrappers_so.so", RTLD_LAZY|RTLD_GLOBAL);
126 void*(*alloc_func)(size_t) = (
void*(*)(size_t))dlsym(handle, "
myTestMalloc");
128 void(*free_func)(
void*) = (
void(*)(
void*))dlsym(handle, "
myTestFree");
129 ASSERT_TRUE(free_func);
132 void* mem = alloc_func(500);
136 ASSERT_EQ(info.mallocs, 1U);
137 ASSERT_EQ(info.frees, 1U);
151 TEST(MallocWrappersDeathTest, breakOnAllocFree)
159 int main(
int argc,
char** argv)
161 testing::InitGoogleTest(&argc, argv);
162 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
163 return RUN_ALL_TESTS();