Kea 2.5.8
lib_load_test_fixture.h
Go to the documentation of this file.
1// Copyright (C) 2022-2024 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>
14
15namespace isc {
16namespace test {
17
19class LibLoadTest : public ::testing::Test {
20public:
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
49 libraries_.clear();
50 }
51
57 bool result(false);
58 EXPECT_NO_THROW(result = isc::hooks::HooksManager::loadLibraries(libraries_));
59 return result;
60 }
61
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,
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
111 void invalidDaemonTest(const std::string& daemon_name,
112 uint16_t family = AF_INET,
114 // Set family and daemon's proc name.
117
119
120 // Adding the library to the list of libraries should work.
122
123 // Loading the library should fail.
124 ASSERT_FALSE(loadLibraries()) << "library: " << lib_so_name_
125 << ", should not have loaded for: " << daemon_name;
126 }
127
131 }
132
134 std::string lib_so_name_;
135
138
141};
142
143} // namespace test
144} // namespace isc
145
146#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:304
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:28
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.