Browse Source

[2198] Check that the logger locks the LoggerManager mutex before calling log4cplus

Mukund Sivaraman 12 years ago
parent
commit
e642b05a1f

+ 7 - 0
src/lib/log/tests/Makefile.am

@@ -131,6 +131,13 @@ endif
 # output needs to be compared with stored output (where "cut" and
 # "diff" are useful utilities).
 
+noinst_SCRIPTS  = console_test.sh
+noinst_SCRIPTS += destination_test.sh
+noinst_SCRIPTS += init_logger_test.sh
+noinst_SCRIPTS += local_file_test.sh
+noinst_SCRIPTS += logger_lock_test.sh
+noinst_SCRIPTS += severity_test.sh
+
 check-local:
 	$(SHELL) $(abs_builddir)/console_test.sh
 	$(SHELL) $(abs_builddir)/destination_test.sh

+ 11 - 0
src/lib/log/tests/logger_lock_test.cc

@@ -14,6 +14,7 @@
 
 #include <log/macros.h>
 #include <log/logger_support.h>
+#include <log/logger_manager.h>
 #include <log/log_messages.h>
 #include "util/interprocess_sync.h"
 #include "log_test_messages.h"
@@ -21,6 +22,7 @@
 
 using namespace std;
 using namespace isc::log;
+using isc::util::thread::Mutex;
 
 class MockLoggingSync : public isc::util::InterprocessSync {
 public:
@@ -31,6 +33,15 @@ public:
 
 protected:
     virtual bool lock() {
+        // We first check if the logger acquired a lock on the
+        // LoggerManager mutex.
+        try {
+            // This lock attempt is non-blocking.
+            Mutex::Locker locker(LoggerManager::getMutex(), false);
+        } catch (Mutex::Locker::AlreadyLocked& e) {
+            cout << "FIELD1 FIELD2 LOGGER_LOCK_TEST: MUTEXLOCK\n";
+        }
+
         cout << "FIELD1 FIELD2 LOGGER_LOCK_TEST: LOCK\n";
         return (true);
     }

+ 1 - 0
src/lib/log/tests/logger_lock_test.sh.in

@@ -31,6 +31,7 @@ passfail() {
 
 echo -n  "Testing that logger acquires and releases locks correctly:"
 cat > $tempfile << .
+LOGGER_LOCK_TEST: MUTEXLOCK
 LOGGER_LOCK_TEST: LOCK
 INFO  [bind10.log] LOG_LOCK_TEST_MESSAGE this is a test message.
 LOGGER_LOCK_TEST: UNLOCK