From: Francis Dupont Date: Wed, 23 Oct 2019 21:06:55 +0000 (+0200) Subject: [947-mt-compatibility-for-hooks] Checkpoint: waiting for MTCS #970 stuff X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3657cb6cff98d6840207867d84e4ce2887b6403;p=thirdparty%2Fkea.git [947-mt-compatibility-for-hooks] Checkpoint: waiting for MTCS #970 stuff --- diff --git a/src/lib/hooks/library_manager.cc b/src/lib/hooks/library_manager.cc index b7f719aaa2..b370258523 100644 --- a/src/lib/hooks/library_manager.cc +++ b/src/lib/hooks/library_manager.cc @@ -7,9 +7,6 @@ #include #include -#if 0 -#include -#endif #include #include #include @@ -20,6 +17,7 @@ #include #include #include +#include #include #include @@ -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& 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.) diff --git a/src/lib/hooks/tests/library_manager_unittest.cc b/src/lib/hooks/tests/library_manager_unittest.cc index d10b447582..78f3c0cff0 100644 --- a/src/lib/hooks/tests/library_manager_unittest.cc +++ b/src/lib/hooks/tests/library_manager_unittest.cc @@ -18,9 +18,7 @@ #include #include -#if 0 #include -#endif #include @@ -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(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(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.