Kea  2.5.3
lib_load_test_fixture.h
Go to the documentation of this file.
1 // Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef ISC_TESTUTILS_LIB_LOAD_TEST_FIXTURE_H
8 #define ISC_TESTUTILS_LIB_LOAD_TEST_FIXTURE_H
9 
10 #include <cc/data.h>
11 #include <dhcpsrv/cfgmgr.h>
12 #include <process/daemon.h>
13 #include <testutils/gtest_utils.h>
14 
15 namespace isc {
16 namespace test {
17 
19 class LibLoadTest : public ::testing::Test {
20 public:
24  LibLoadTest(const std::string lib_so_name = "no-lib-specified")
25  : lib_so_name_(lib_so_name) {
27  }
28 
29  virtual void SetUp() {
31  }
32 
36  }
37 
43  void addLibrary(const std::string& library,
44  isc::data::ConstElementPtr parameters) {
45  libraries_.push_back({library, parameters});
46  }
47 
48  void clearLibraries() {
49  libraries_.clear();
50  }
51 
56  bool loadLibraries() {
57  bool result(false);
58  EXPECT_NO_THROW(result = isc::hooks::HooksManager::loadLibraries(libraries_));
59  return result;
60  }
61 
66  bool unloadLibraries() {
67  bool result(false);
68  EXPECT_NO_THROW(result = isc::hooks::HooksManager::unloadLibraries());
69  return result;
70  }
71 
82  void validDaemonTest(const std::string& daemon_name,
83  uint16_t family = AF_INET,
84  const isc::data::ElementPtr& params = isc::data::ElementPtr()) {
85  // Set family and daemon's proc name.
88 
90 
91  // Adding the library to the list of libraries should work.
93 
94  // Should be able to load and unload the library more than once.
97 
100  }
101 
113  void invalidDaemonTest(const std::string& daemon_name,
114  uint16_t family = AF_INET,
115  const isc::data::ElementPtr& params = isc::data::ElementPtr()) {
116  // Set family and daemon's proc name.
119 
120  clearLibraries();
121 
122  // Adding the library to the list of libraries should work.
124 
125  // Loading the library should fail.
126  ASSERT_FALSE(loadLibraries()) << "library: " << lib_so_name_
127  << ", should not have loaded for: " << daemon_name;
128  }
129 
133  }
134 
136  std::string lib_so_name_;
137 
140 
143 };
144 
145 } // namespace test
146 } // namespace isc
147 
148 #endif // ISC_TESTUTILS_LIB_LOAD_TEST_FIXTURE_H
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition: data.cc:301
void setFamily(uint16_t family)
Sets address family (AF_INET or AF_INET6)
Definition: cfgmgr.h:275
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition: cfgmgr.cc:25
static bool unloadLibraries()
Unload libraries.
static bool loadLibraries(const HookLibsCollection &libraries, bool multi_threading_enabled=false)
Load and reload libraries.
static void setProcName(const std::string &proc_name)
Sets the process name.
Definition: daemon.cc:134
Test fixture for testing loading and unloading of hook libraries.
bool unloadLibraries()
Unloads all libraries.
LibLoadTest(const std::string lib_so_name="no-lib-specified")
Constructor.
isc::data::ElementPtr valid_params_
Contains a set configuration parameters valid for the library.
std::string lib_so_name_
full pathname to the library so file under test;
void addLibrary(const std::string &library, isc::data::ConstElementPtr parameters)
Adds a library along with its parameters to the list of libraries to be loaded.
bool loadLibraries()
Load all libraries.
virtual isc::data::ElementPtr validConfigParams()
Creates a set configuration parameters valid for the library.
void invalidDaemonTest(const std::string &daemon_name, uint16_t family=AF_INET, const isc::data::ElementPtr &params=isc::data::ElementPtr())
Verifies that an invalid daemon cannot load the library.
~LibLoadTest()
Destructor. Unloads any previously loaded libraries.
isc::hooks::HookLibsCollection libraries_
Libraries.
void validDaemonTest(const std::string &daemon_name, uint16_t family=AF_INET, const isc::data::ElementPtr &params=isc::data::ElementPtr())
Verifies that a valid daemon can load and unload a library multiple times.
#define ASSERT_NO_THROW_LOG(statement)
Generates a fatal failure with exception info, if the given expression throws.
Definition: gtest_utils.h:77
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:29
boost::shared_ptr< Element > ElementPtr
Definition: data.h:26
std::vector< HookLibInfo > HookLibsCollection
A storage for information about hook libraries.
Definition: libinfo.h:31
Defines the logger used by the top-level component of kea-lfc.