]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[947-mt-compatibility-for-hooks] Checkpoint: waiting for MTCS #970 stuff
authorFrancis Dupont <fdupont@isc.org>
Wed, 23 Oct 2019 21:06:55 +0000 (23:06 +0200)
committerFrancis Dupont <fdupont@isc.org>
Tue, 5 Nov 2019 15:56:02 +0000 (16:56 +0100)
src/lib/hooks/library_manager.cc
src/lib/hooks/tests/library_manager_unittest.cc

index b7f719aaa28e578dfa0c096ed75d0efbf0d7343b..b3702585235eab1251b597e4497571bfd0e5f912 100644 (file)
@@ -7,9 +7,6 @@
 #include <config.h>
 
 #include <exceptions/exceptions.h>
-#if 0
-#include <util/multi_threading_mgr.h>
-#endif
 #include <hooks/hooks.h>
 #include <hooks/hooks_log.h>
 #include <hooks/callout_manager.h>
@@ -20,6 +17,7 @@
 #include <log/logger_manager.h>
 #include <log/logger_support.h>
 #include <log/message_initializer.h>
+#include <util/multi_threading_mgr.h>
 
 #include <string>
 #include <vector>
@@ -31,7 +29,6 @@ using namespace std;
 namespace isc {
 namespace hooks {
 
-
 // Constructor (used by external agency)
 LibraryManager::LibraryManager(const std::string& name, int index,
                                const boost::shared_ptr<CalloutManager>& manager)
@@ -143,11 +140,9 @@ bool
 LibraryManager::checkMultiThreadingCompatible() const {
 
     // Compatible with single-threaded.
-#if 0
-    if (!MultiThreadingMgr::instance().getMode()) {
+    if (!util::MultiThreadingMgr::instance().getMode()) {
         return (true);
     }
-#endif
 
     // Get the pointer to the "multi_threading_compatible" function.
     PointerConverter pc(dlsym(dl_handle_, MULTI_THREADING_COMPATIBLE_FUNCTION_NAME));
@@ -315,11 +310,7 @@ LibraryManager::loadLibrary() {
 
         // Library opened OK, see if a version function is present and if so,
         // check what value it returns. Check multi-threading compatibility.
-#if 0
         if (checkVersion() && checkMultiThreadingCompatible()) {
-#else
-        if (checkVersion()) {
-#endif
             // Version OK, so now register the standard callouts and call the
             // library's load() function if present.
             registerStandardCallouts();
@@ -402,12 +393,8 @@ LibraryManager::validateLibrary(const std::string& name) {
     LibraryManager manager(name);
 
     // Try to open it and, if we succeed, check the version.
-#if 0
     bool validated = manager.openLibrary() && manager.checkVersion() &&
-        checkMultiThreadingCompatible();
-#else
-    bool validated = manager.openLibrary() && manager.checkVersion();
-#endif
+        manager.checkMultiThreadingCompatible();
 
     // Regardless of whether the version checked out, close the library. (This
     // is a no-op if the library failed to open.)
index d10b447582a418c95104266eecddc7bbbcaa3941..78f3c0cff059368685cedabfd155b985f82ecb9b 100644 (file)
@@ -18,9 +18,7 @@
 #include <log/message_dictionary.h>
 #include <log/message_initializer.h>
 
-#if 0
 #include <util/multi_threading_mgr.h>
-#endif
 
 #include <gtest/gtest.h>
 
@@ -34,6 +32,7 @@
 using namespace isc;
 using namespace isc::hooks;
 using namespace isc::log;
+using namespace isc::util;
 using namespace std;
 
 namespace {
@@ -53,6 +52,8 @@ public:
 
         // Ensure the marker file is not present at the start of a test.
         static_cast<void>(remove(MARKER_FILE));
+
+        // Disable multi-threading.
     }
 
     /// @brief Destructor
@@ -60,6 +61,7 @@ public:
     /// Ensures a marker file is removed after each test.
     ~LibraryManagerTest() {
         static_cast<void>(remove(MARKER_FILE));
+        MultiThreadingMgr::instance().setMode(false);
     }
 
     /// @brief Marker file present
@@ -251,14 +253,12 @@ TEST_F(LibraryManagerTest, NoMultiThreadingCompatible) {
     // Open should succeed.
     EXPECT_TRUE(lib_manager.openLibrary());
 
-#if 0
     // Not multi-threading compatible: does not matter without MT.
     EXPECT_TRUE(lib_manager.checkMultiThreadingCompatible());
 
     // Not multi-threading compatible: does matter with MT.
-    //// set MT
+    MultiThreadingMgr::instance().setMode(true);
     EXPECT_FALSE(lib_manager.checkMultiThreadingCompatible());
-#endif
 
     // Tidy up.
     EXPECT_TRUE(lib_manager.closeLibrary());
@@ -274,14 +274,12 @@ TEST_F(LibraryManagerTest, multiThreadingNotCompatible) {
     // Open should succeed.
     EXPECT_TRUE(lib_manager.openLibrary());
 
-#if 0
     // Not multi-threading compatible: does not matter without MT.
     EXPECT_TRUE(lib_manager.checkMultiThreadingCompatible());
 
     // Not multi-threading compatible: does matter with MT.
-    //// set MT
+    MultiThreadingMgr::instance().setMode(true);
     EXPECT_FALSE(lib_manager.checkMultiThreadingCompatible());
-#endif
 
     // Tidy up.
     EXPECT_TRUE(lib_manager.closeLibrary());
@@ -301,7 +299,7 @@ TEST_F(LibraryManagerTest, multiThreadingCompatible) {
     EXPECT_TRUE(lib_manager.checkMultiThreadingCompatible());
 
     // Multi-threading compatible: does matter with MT.
-    //// set MT
+    MultiThreadingMgr::instance().setMode(true);
     EXPECT_TRUE(lib_manager.checkMultiThreadingCompatible());
 
     // Tidy up.
@@ -318,13 +316,11 @@ TEST_F(LibraryManagerTest, multiThreadingCompatibleException) {
     // Open should succeed.
     EXPECT_TRUE(lib_manager.openLibrary());
 
-#if 0
     // Throw exception: does not matter without MT.
-    EXPECT_FALSE(lib_manager.checkMultiThreadingCompatible());
-#endif
+    EXPECT_TRUE(lib_manager.checkMultiThreadingCompatible());
 
     // Throw exception: does matter with MT.
-    //// set MT
+    MultiThreadingMgr::instance().setMode(true);
     EXPECT_FALSE(lib_manager.checkMultiThreadingCompatible());
 
     // Tidy up.
@@ -694,6 +690,19 @@ TEST_F(LibraryManagerTest, validateLibraries) {
     EXPECT_FALSE(LibraryManager::validateLibrary(NO_VERSION_LIBRARY));
     EXPECT_TRUE(LibraryManager::validateLibrary(UNLOAD_CALLOUT_LIBRARY));
     EXPECT_TRUE(LibraryManager::validateLibrary(CALLOUT_PARAMS_LIBRARY));
+
+    MultiThreadingMgr::instance().setMode(true);
+
+    EXPECT_FALSE(LibraryManager::validateLibrary(BASIC_CALLOUT_LIBRARY));
+    EXPECT_TRUE(LibraryManager::validateLibrary(FULL_CALLOUT_LIBRARY));
+    EXPECT_FALSE(LibraryManager::validateLibrary(FRAMEWORK_EXCEPTION_LIBRARY));
+    EXPECT_FALSE(LibraryManager::validateLibrary(INCORRECT_VERSION_LIBRARY));
+    EXPECT_FALSE(LibraryManager::validateLibrary(LOAD_CALLOUT_LIBRARY));
+    EXPECT_FALSE(LibraryManager::validateLibrary(LOAD_ERROR_CALLOUT_LIBRARY));
+    EXPECT_FALSE(LibraryManager::validateLibrary(NOT_PRESENT_LIBRARY));
+    EXPECT_FALSE(LibraryManager::validateLibrary(NO_VERSION_LIBRARY));
+    EXPECT_FALSE(LibraryManager::validateLibrary(UNLOAD_CALLOUT_LIBRARY));
+    EXPECT_FALSE(LibraryManager::validateLibrary(CALLOUT_PARAMS_LIBRARY));
 }
 
 // Check that log messages are properly registered and unregistered.