Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
e61a5182
Commit
e61a5182
authored
Jun 19, 2013
by
Stephen Morris
Browse files
[2980] Added runUnload tests
runUnload() still has to be added.
parent
8e94ab0a
Changes
7
Hide whitespace changes
Inline
Side-by-side
configure.ac
View file @
e61a5182
...
...
@@ -1403,6 +1403,7 @@ AC_OUTPUT([doc/version.ent
src/lib/cc/tests/session_unittests_config.h
src/lib/datasrc/datasrc_config.h.pre
src/lib/hooks/tests/library_manager_unittest.cc
src/lib/hooks/tests/marker_file.h
src/lib/log/tests/console_test.sh
src/lib/log/tests/destination_test.sh
src/lib/log/tests/init_logger_test.sh
...
...
src/lib/hooks/library_manager.h
View file @
e61a5182
...
...
@@ -164,6 +164,15 @@ protected:
/// have been output.
bool
runLoad
();
/// @brief Run the unload function if present
///
/// Searches for the "unload" framework function and, if present, runs it.
///
/// @return bool true if not found or found and run successfully,
/// false on an error. In this case, an error message will
/// have been output.
bool
runUnload
()
{
return
false
;}
private:
void
*
dl_handle_
;
///< Handle returned by dlopen
int
index_
;
///< Index associated with this library
...
...
src/lib/hooks/tests/Makefile.am
View file @
e61a5182
...
...
@@ -24,8 +24,11 @@ CLEANFILES = *.gcno *.gcda
TESTS_ENVIRONMENT
=
\
$(LIBTOOL)
--mode
=
execute
$(VALGRIND_COMMAND)
TESTS
=
if
HAVE_GTEST
# Build shared libraries for testing.
lib_LTLIBRARIES
=
libnvl.la libivl.la libbcl.la liblcl.la liblecl.la
lib_LTLIBRARIES
=
libnvl.la libivl.la libbcl.la liblcl.la liblecl.la
\
libucl.la
# No version function
libnvl_la_SOURCES
=
no_version_library.cc
...
...
@@ -53,8 +56,12 @@ liblecl_la_SOURCES = load_error_callout_library.cc
liblecl_la_CXXFLAGS
=
$(AM_CXXFLAGS)
liblecl_la_CPPFLAGS
=
$(AM_CPPFLAGS)
$(LOG4CPLUS_INCLUDES)
TESTS
=
if
HAVE_GTEST
# The unload callout library - contains an unload function that
# creates a marker file.
libucl_la_SOURCES
=
unload_callout_library.cc
libucl_la_CXXFLAGS
=
$(AM_CXXFLAGS)
libucl_la_CPPFLAGS
=
$(AM_CPPFLAGS)
$(LOG4CPLUS_INCLUDES)
TESTS
+=
run_unittests
run_unittests_SOURCES
=
run_unittests.cc
run_unittests_SOURCES
+=
callout_handle_unittest.cc
...
...
@@ -75,3 +82,5 @@ run_unittests_LDADD += $(top_builddir)/src/lib/util/unittests/libutil_unittests.
endif
noinst_PROGRAMS
=
$(TESTS)
EXTRA_DIST
=
library_manager_unittest.cc.in marker_file.h.in
src/lib/hooks/tests/library_manager_unittest.cc.in
View file @
e61a5182
...
...
@@ -16,14 +16,16 @@
#include <hooks/callout_manager.h>
#include <hooks/library_manager.h>
#include <hooks/server_hooks.h>
#include <hooks/tests/marker_file.h>
#include <gtest/gtest.h>
#include <algorithm>
#include <fstream>
#include <string>
#include <vector>
#include <iostream>
#include <unistd.h>
using namespace isc;
using namespace isc::hooks;
...
...
@@ -52,6 +54,16 @@ public:
// Set up the callout handle.
callout_handle_.reset(new CalloutHandle(callout_manager_));
// Ensure the marker file is not present
static_cast<void>(unlink(MARKER_FILE));
}
/// @brief Destructor
///
/// Ensures a marker file is removed after the test.
~LibraryManagerTest() {
static_cast<void>(unlink(MARKER_FILE));
}
/// Hook indexes. These are somewhat ubiquitous, so are made public for
...
...
@@ -102,6 +114,7 @@ public:
using LibraryManager::checkVersion;
using LibraryManager::registerStandardCallouts;
using LibraryManager::runLoad;
using LibraryManager::runUnload;
};
// Names of the libraries used in these tests. These libraries are built using
...
...
@@ -115,6 +128,7 @@ static const char* LOAD_ERROR_CALLOUT_LIBRARY =
"@abs_builddir@/.libs/liblecl.so";
static const char* NOT_PRESENT_LIBRARY = "@abs_builddir@/.libs/libnothere.so";
static const char* NO_VERSION_LIBRARY = "@abs_builddir@/.libs/libnvl.so";
static const char* UNLOAD_CALLOUT_LIBRARY = "@abs_builddir@/.libs/libucl.so";
namespace {
...
...
@@ -327,4 +341,84 @@ TEST_F(LibraryManagerTest, CheckLoadError) {
EXPECT_TRUE(lib_manager.closeLibrary());
}
// TODO Check that unload is called. This causes problems with testing
// in that it can't communicate anything back to the caller. So we'll
// test a successful call by checking whether a marker file is created.
// No unload function
TEST_F(LibraryManagerTest, CheckNoUnload) {
// Load the only library, specifying the index of 0 as it's the only
// library. This should load all callouts.
PublicLibraryManager lib_manager(std::string(BASIC_CALLOUT_LIBRARY),
0, callout_manager_);
EXPECT_TRUE(lib_manager.openLibrary());
// Check that no unload function returns true.
EXPECT_TRUE(lib_manager.runUnload());
// Explicitly clear the callout_handle_ so that we can delete the library.
// This is the only object to contain memory allocated by it.
callout_handle_.reset();
// Tidy up
EXPECT_TRUE(lib_manager.closeLibrary());
}
// Unload function returns an error
TEST_F(LibraryManagerTest, CheckUnloadError) {
// Load the only library, specifying the index of 0 as it's the only
// library. This should load all callouts.
PublicLibraryManager lib_manager(std::string(LOAD_ERROR_CALLOUT_LIBRARY),
0, callout_manager_);
EXPECT_TRUE(lib_manager.openLibrary());
// Check that unload function returning an error returns false.
EXPECT_FALSE(lib_manager.runUnload());
// Explicitly clear the callout_handle_ so that we can delete the library.
// This is the only object to contain memory allocated by it.
callout_handle_.reset();
// Tidy up
EXPECT_TRUE(lib_manager.closeLibrary());
}
// Unload function works
TEST_F(LibraryManagerTest, CheckUnload) {
// Load the only library, specifying the index of 0 as it's the only
// library. This should load all callouts.
PublicLibraryManager lib_manager(std::string(UNLOAD_CALLOUT_LIBRARY),
0, callout_manager_);
EXPECT_TRUE(lib_manager.openLibrary());
// Check that the marker file is not present (at least that the file
// open fails).
fstream marker;
marker.open(MARKER_FILE, fstream::in);
EXPECT_TRUE(marker.fail());
// Check that unload function runs and returns a success
EXPECT_TRUE(lib_manager.runUnload());
// Check that the open succeeded
marker.open(MARKER_FILE, fstream::in);
EXPECT_TRUE(marker.is_open());
// Tidy up
marker.close();
// Explicitly clear the callout_handle_ so that we can delete the library.
// This is the only object to contain memory allocated by it.
callout_handle_.reset();
// Tidy up
EXPECT_TRUE(lib_manager.closeLibrary());
}
} // Anonymous namespace
src/lib/hooks/tests/load_error_callout_library.cc
View file @
e61a5182
...
...
@@ -20,8 +20,8 @@
///
/// The characteristics of this library are:
///
/// -
The "version" and "load"
framework functions are supplied. "version"
///
returns the correct
value, but "load" return
s
an error.
/// -
All
framework functions are supplied. "version"
returns the correct
/// value, but "load"
and unload
return an error.
#include <hooks/hooks.h>
#include <iostream>
...
...
@@ -37,7 +37,13 @@ version() {
return
(
BIND10_HOOKS_VERSION
);
}
int
load
(
LibraryHandle
&
)
{
int
load
(
LibraryHandle
&
)
{
return
(
1
);
}
int
unload
()
{
return
(
1
);
}
...
...
src/lib/hooks/tests/marker_file.h.in
0 → 100644
View file @
e61a5182
// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef MARKER_FILE_H
#define MARKER_FILE_H
/// @file
/// Define a marker file that is used in tests to prove that an "unload"
/// function has been called.
namespace {
const char* MARKER_FILE = "@abs_builddir@/marker_file.dat";
}
#endif // MARKER_FILE_H
src/lib/hooks/tests/unload_callout_library.cc
0 → 100644
View file @
e61a5182
// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
/// @file
/// @brief Basic unload library
///
/// This is a test file for the LibraryManager test. It produces a library
/// that allows for tests of the basic library manager functions.
///
/// The characteristics of this library are:
///
/// - The "version" and "unload" framework functions are supplied. "version"
/// returns a valid value and "unload" creates a marker file and returns
/// success.
#include <hooks/hooks.h>
#include <hooks/tests/marker_file.h>
#include <fstream>
using
namespace
isc
::
hooks
;
extern
"C"
{
// Framework functions
int
version
()
{
return
(
BIND10_HOOKS_VERSION
);
}
int
unload
()
{
// Create the marker file.
std
::
fstream
marker
;
marker
.
open
(
MARKER_FILE
,
std
::
fstream
::
out
);
marker
.
close
();
return
(
0
);
}
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment