From: JINMEI Tatuya Date: Tue, 8 May 2012 22:11:55 +0000 (-0700) Subject: [1964] moved dontCreateCoreDumps to libutil_unittests. X-Git-Tag: trac2351_base~226^2~158^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6c0da87a7bdbb7be59fbac47b6c5f2ef0043aecb;p=thirdparty%2Fkea.git [1964] moved dontCreateCoreDumps to libutil_unittests. this solves various build troubles such as leaving it unused, causing circular dependcies, or the use of unnamed namespace in a public header file. --- diff --git a/src/lib/log/tests/log_formatter_unittest.cc b/src/lib/log/tests/log_formatter_unittest.cc index 1aa7e4e049..6bb2f02c7e 100644 --- a/src/lib/log/tests/log_formatter_unittest.cc +++ b/src/lib/log/tests/log_formatter_unittest.cc @@ -15,9 +15,7 @@ #include "config.h" #include -#ifdef EXPECT_DEATH -#include -#endif /* EXPECT_DEATH */ +#include #include #include @@ -107,12 +105,12 @@ TEST_F(FormatterTest, multiArg) { // don't match number of arguments. This causes it to abort. TEST_F(FormatterTest, mismatchedPlaceholders) { EXPECT_DEATH({ - isc::testutils::dontCreateCoreDumps(); + isc::util::unittests::dontCreateCoreDumps(); Formatter(isc::log::INFO, s("Missing the first %2"), this).arg("missing").arg("argument"); }, ".*"); EXPECT_DEATH({ - isc::testutils::dontCreateCoreDumps(); + isc::util::unittests::dontCreateCoreDumps(); Formatter(isc::log::INFO, s("Too many arguments in %1 %2"), this).arg("only one"); }, ".*"); } diff --git a/src/lib/log/tests/logger_unittest.cc b/src/lib/log/tests/logger_unittest.cc index 5dddf32d34..069205e1e0 100644 --- a/src/lib/log/tests/logger_unittest.cc +++ b/src/lib/log/tests/logger_unittest.cc @@ -17,9 +17,7 @@ #include -#ifdef EXPECT_DEATH -#include -#endif /* EXPECT_DEATH */ +#include #include #include @@ -374,7 +372,7 @@ TEST_F(LoggerTest, LoggerNameLength) { // Note that we just check that it dies - we don't check what message is // output. EXPECT_DEATH({ - isc::testutils::dontCreateCoreDumps(); + isc::util::unittests::dontCreateCoreDumps(); string ok3(Logger::MAX_LOGGER_NAME_SIZE + 1, 'x'); Logger l3(ok3.c_str()); diff --git a/src/lib/log/tests/message_initializer_2_unittest.cc b/src/lib/log/tests/message_initializer_2_unittest.cc index e848a6c4b2..b479eeed7c 100644 --- a/src/lib/log/tests/message_initializer_2_unittest.cc +++ b/src/lib/log/tests/message_initializer_2_unittest.cc @@ -15,9 +15,7 @@ #include #include -#ifdef EXPECT_DEATH -#include -#endif /* EXPECT_DEATH */ +#include using namespace isc::log; @@ -46,7 +44,7 @@ TEST(MessageInitializerTest2, MessageLoadTest) { #ifdef EXPECT_DEATH // Adding one more should take us over the limit. EXPECT_DEATH({ - isc::testutils::dontCreateCoreDumps(); + isc::util::unittests::dontCreateCoreDumps(); MessageInitializer initializer2(values); }, ".*"); diff --git a/src/lib/server_common/tests/portconfig_unittest.cc b/src/lib/server_common/tests/portconfig_unittest.cc index ad8d1e9d4c..ac880c0747 100644 --- a/src/lib/server_common/tests/portconfig_unittest.cc +++ b/src/lib/server_common/tests/portconfig_unittest.cc @@ -18,9 +18,7 @@ #include #include -#ifdef EXPECT_DEATH -#include -#endif /* EXPECT_DEATH */ +#include #include #include @@ -318,7 +316,7 @@ TEST_F(InstallListenAddressesDeathTest, inconsistent) { // Make sure it actually kills the application (there should be an abort // in this case) EXPECT_DEATH({ - isc::testutils::dontCreateCoreDumps(); + isc::util::unittests::dontCreateCoreDumps(); try { installListenAddresses(deathAddresses, store_, dnss_); @@ -337,7 +335,7 @@ TEST_F(InstallListenAddressesDeathTest, cantClose) { // Instruct it to fail on close sock_requestor_.break_release_ = true; EXPECT_DEATH({ - isc::testutils::dontCreateCoreDumps(); + isc::util::unittests::dontCreateCoreDumps(); try { // Setting to empty will close all current sockets. diff --git a/src/lib/testutils/Makefile.am b/src/lib/testutils/Makefile.am index 77f5a96616..7a4c8d79bc 100644 --- a/src/lib/testutils/Makefile.am +++ b/src/lib/testutils/Makefile.am @@ -14,4 +14,4 @@ libtestutils_la_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) libtestutils_la_LIBADD = $(top_builddir)/src/lib/asiolink/libasiolink.la endif -EXTRA_DIST = portconfig.h resource.h socket_request.h +EXTRA_DIST = portconfig.h socket_request.h diff --git a/src/lib/util/tests/buffer_unittest.cc b/src/lib/util/tests/buffer_unittest.cc index ae164ff524..ccd6989dda 100644 --- a/src/lib/util/tests/buffer_unittest.cc +++ b/src/lib/util/tests/buffer_unittest.cc @@ -17,7 +17,7 @@ #include #ifdef EXPECT_DEATH -#include +#include #endif /* EXPECT_DEATH */ #include @@ -189,7 +189,7 @@ TEST_F(BufferTest, outputBufferReadat) { #ifdef EXPECT_DEATH // We use assert now, so we check it dies EXPECT_DEATH({ - isc::testutils::dontCreateCoreDumps(); + isc::util::unittests::dontCreateCoreDumps(); try { obuffer[sizeof(testdata)]; diff --git a/src/lib/util/unittests/Makefile.am b/src/lib/util/unittests/Makefile.am index bbb0d49b87..28274712a6 100644 --- a/src/lib/util/unittests/Makefile.am +++ b/src/lib/util/unittests/Makefile.am @@ -6,6 +6,7 @@ libutil_unittests_la_SOURCES = fork.h fork.cc resolver.h libutil_unittests_la_SOURCES += newhook.h newhook.cc libutil_unittests_la_SOURCES += testdata.h testdata.cc if HAVE_GTEST +libutil_unittests_la_SOURCES += resource.h resource.cc libutil_unittests_la_SOURCES += run_all.h run_all.cc libutil_unittests_la_SOURCES += textdata.h endif diff --git a/src/lib/util/unittests/resource.cc b/src/lib/util/unittests/resource.cc new file mode 100644 index 0000000000..3e77e0d41a --- /dev/null +++ b/src/lib/util/unittests/resource.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2012 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. + +#include "resource.h" + +#include + +#include +#include + +namespace isc { +namespace util { +namespace unittests { + +void +dontCreateCoreDumps() { + const rlimit core_limit = {0, 0}; + + EXPECT_EQ(setrlimit(RLIMIT_CORE, &core_limit), 0); +} + +} // end of namespace unittests +} // end of namespace util +} // end of namespace isc diff --git a/src/lib/testutils/resource.h b/src/lib/util/unittests/resource.h similarity index 60% rename from src/lib/testutils/resource.h rename to src/lib/util/unittests/resource.h index 192d4a67a9..6430ab2bc1 100644 --- a/src/lib/testutils/resource.h +++ b/src/lib/util/unittests/resource.h @@ -12,16 +12,12 @@ // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. -#ifndef __ISC_TESTUTILS_RESOURCE_H -#define __ISC_TESTUTILS_RESOURCE_H - -#include -#include - -#include +#ifndef __UTIL_UNITTESTS_RESOURCE_H +#define __UTIL_UNITTESTS_RESOURCE_H 1 namespace isc { -namespace testutils { +namespace util { +namespace unittests { /// Don't create core dumps. /// @@ -30,29 +26,14 @@ namespace testutils { /// is used, where processes abort (and create cores in the process). /// As a new process is forked to run EXPECT_DEATH tests, the rlimits of /// the parent process that runs the other tests should be unaffected. -/// -/// This function definition is in the header file as otherwise there'd -/// be a circular dependency from -/// testutils->asiolink->log->testutils. See bug #1880. - -namespace { - -inline void -dontCreateCoreDumps(void) -{ - /* Set rlimits so that no coredumps are created. As a new - process is forked to run this EXPECT_DEATH test, the rlimits - of the parent process that runs the other tests should be - unaffected. */ +void dontCreateCoreDumps(); - rlimit core_limit = {0, 0}; - - EXPECT_EQ(setrlimit(RLIMIT_CORE, &core_limit), 0); -} - -} // end of anonymous namespace - -} // end of namespace testutils +} // end of namespace unittests +} // end of namespace util } // end of namespace isc -#endif /* __ISC_TESTUTILS_RESOURCE_H */ +#endif /* __UTIL_UNITTESTS_RESOURCE_H */ + +// Local Variables: +// mode: c++ +// End: