Browse Source

[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.
JINMEI Tatuya 13 years ago
parent
commit
6c0da87a7b

+ 3 - 5
src/lib/log/tests/log_formatter_unittest.cc

@@ -15,9 +15,7 @@
 #include "config.h"
 #include <gtest/gtest.h>
 
-#ifdef EXPECT_DEATH
-#include <testutils/resource.h>
-#endif /* EXPECT_DEATH */
+#include <util/unittests/resource.h>
 
 #include <log/log_formatter.h>
 #include <log/logger_level.h>
@@ -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");
     }, ".*");
 }

+ 2 - 4
src/lib/log/tests/logger_unittest.cc

@@ -17,9 +17,7 @@
 
 #include <gtest/gtest.h>
 
-#ifdef EXPECT_DEATH
-#include <testutils/resource.h>
-#endif /* EXPECT_DEATH */
+#include <util/unittests/resource.h>
 
 #include <log/logger.h>
 #include <log/logger_manager.h>
@@ -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());

+ 2 - 4
src/lib/log/tests/message_initializer_2_unittest.cc

@@ -15,9 +15,7 @@
 #include <log/message_initializer.h>
 #include <gtest/gtest.h>
 
-#ifdef EXPECT_DEATH
-#include <testutils/resource.h>
-#endif /* EXPECT_DEATH */
+#include <util/unittests/resource.h>
 
 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);
       }, ".*");

+ 3 - 5
src/lib/server_common/tests/portconfig_unittest.cc

@@ -18,9 +18,7 @@
 #include <testutils/socket_request.h>
 #include <testutils/mockups.h>
 
-#ifdef EXPECT_DEATH
-#include <testutils/resource.h>
-#endif /* EXPECT_DEATH */
+#include <util/unittests/resource.h>
 
 #include <cc/data.h>
 #include <exceptions/exceptions.h>
@@ -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.

+ 1 - 1
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

+ 2 - 2
src/lib/util/tests/buffer_unittest.cc

@@ -17,7 +17,7 @@
 #include <exceptions/exceptions.h>
 
 #ifdef EXPECT_DEATH
-#include <testutils/resource.h>
+#include <util/unittests/resource.h>
 #endif /* EXPECT_DEATH */
 
 #include <util/buffer.h>
@@ -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)];

+ 1 - 0
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

+ 35 - 0
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 <gtest/gtest.h>
+
+#include <sys/time.h>
+#include <sys/resource.h>
+
+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

+ 12 - 31
src/lib/testutils/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 <sys/time.h>
-#include <sys/resource.h>
-
-#include <gtest/gtest.h>
+#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: