]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2236] Don't use PTHREAD_MUTEX_ERRORCHECK in non-debug builds
authorMukund Sivaraman <muks@isc.org>
Tue, 23 Oct 2012 04:06:26 +0000 (09:36 +0530)
committerMukund Sivaraman <muks@isc.org>
Tue, 23 Oct 2012 04:22:40 +0000 (09:52 +0530)
Also disable tests in non-debug builds that depend on
PTHREAD_MUTEX_ERRORCHECK.

src/bin/auth/tests/auth_srv_unittest.cc
src/lib/util/threads/sync.cc
src/lib/util/threads/tests/condvar_unittest.cc
src/lib/util/threads/tests/lock_unittest.cc

index 396b247491bb8bc139a54bb455d73678a7d2710e..cde4c8169ba401d51a37521e1a0797e49c95ff19 100644 (file)
@@ -1824,6 +1824,8 @@ TEST_F(AuthSrvTest, clientList) {
     EXPECT_FALSE(server.getDataSrcClientList(RRClass::CH()));
 }
 
+#ifdef ENABLE_DEBUG
+
 // We just test the mutex can be locked (exactly once).
 TEST_F(AuthSrvTest, mutex) {
     isc::util::thread::Mutex::Locker l1(server.getDataSrcClientListMutex());
@@ -1837,4 +1839,6 @@ TEST_F(AuthSrvTest, mutex) {
     }, isc::InvalidOperation);
 }
 
+#endif // ENABLE_DEBUG
+
 }
index c2f4fed48c960ba653ec994da8b1ab6f09c1597b..ca467b63d41ab076f2ef0043a84752e6f2565c39 100644 (file)
@@ -76,12 +76,15 @@ Mutex::Mutex() :
             isc_throw(isc::InvalidOperation, std::strerror(result));
     }
     Deinitializer deinitializer(attributes);
+
+#ifdef ENABLE_DEBUG
     // TODO: Distinguish if debug mode is enabled in compilation.
-    // If so, it should be PTHREAD_MUTEX_NORMAL or NULL
     result = pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_ERRORCHECK);
     if (result != 0) {
         isc_throw(isc::InvalidOperation, std::strerror(result));
     }
+#endif // ENABLE_DEBUG
+
     auto_ptr<Impl> impl(new Impl);
     result = pthread_mutex_init(&impl->mutex, &attributes);
     switch (result) {
index 6cec0dc9b86dc03b7fd510d3d50f491683448495..8b1fe5445eeda130702cd8c513695541af86daa4 100644 (file)
@@ -149,15 +149,15 @@ TEST_F(CondVarTest, DISABLED_destroyWhileWait) {
         }, "");
 }
 
+#ifdef ENABLE_DEBUG
+
 TEST_F(CondVarTest, badWait) {
     // In our implementation, wait() requires acquiring the lock beforehand.
-#ifdef ENABLE_DEBUG
     EXPECT_THROW(condvar_.wait(mutex_), isc::InvalidOperation);
-#else
-    EXPECT_THROW(condvar_.wait(mutex_), isc::BadValue);
-#endif // ENABLE_DEBUG
 }
 
+#endif // ENABLE_DEBUG
+
 TEST_F(CondVarTest, emptySignal) {
     // It's okay to call signal when no one waits.
     EXPECT_NO_THROW(condvar_.signal());
index abd0f607d8a431df1fad302376d0087e230092e7..40af7eee6c14f2a70f8edb6c06550d79a2398d5b 100644 (file)
@@ -26,28 +26,28 @@ using namespace isc::util::thread;
 
 namespace {
 
-// If we try to lock the debug mutex multiple times, it should throw.
+#ifdef ENABLE_DEBUG
+
+// If we try to lock the debug mutex multiple times, it should
+// throw. This test will complete properly only when pthread debugging
+// facilities are enabled by configuring the code for debug build.
 TEST(MutexTest, lockMultiple) {
     // TODO: Once we support non-debug mutexes, disable the test if we compile
     // with them.
     Mutex mutex;
-#ifdef ENABLE_DEBUG
     EXPECT_FALSE(mutex.locked()); // Debug-only build
-#endif // ENABLE_DEBUG
 
     Mutex::Locker l1(mutex);
-#ifdef ENABLE_DEBUG
     EXPECT_TRUE(mutex.locked()); // Debug-only build
-#endif // ENABLE_DEBUG
 
     EXPECT_THROW({
         Mutex::Locker l2(mutex); // Attempt to lock again.
     }, isc::InvalidOperation);
-#ifdef ENABLE_DEBUG
     EXPECT_TRUE(mutex.locked()); // Debug-only build
-#endif // ENABLE_DEBUG
 }
 
+#endif // ENABLE_DEBUG
+
 // Destroying a locked mutex is a bad idea as well
 #ifdef EXPECT_DEATH
 TEST(MutexTest, destroyLocked) {