Commit 408043d9 authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[1880] Use a helper function instead of repeating code

parent d7191f1b
......@@ -67,6 +67,7 @@ run_unittests_CPPFLAGS = $(AM_CPPFLAGS)
run_unittests_CXXFLAGS = $(AM_CXXFLAGS)
run_unittests_LDADD = $(AM_LDADD)
run_unittests_LDFLAGS = $(AM_LDFLAGS)
run_unittests_LDFLAGS += $(top_builddir)/src/lib/testutils/libtestutils.la
# logging initialization tests. These are put in separate programs to
# ensure that the initialization status at the start of each test is known,
......@@ -90,6 +91,7 @@ initializer_unittests_2_CPPFLAGS = $(AM_CPPFLAGS)
initializer_unittests_2_CXXFLAGS = $(AM_CXXFLAGS)
initializer_unittests_2_LDADD = $(AM_LDADD)
initializer_unittests_2_LDFLAGS = $(AM_LDFLAGS)
initializer_unittests_2_LDFLAGS += $(top_builddir)/src/lib/testutils/libtestutils.la
noinst_PROGRAMS += $(TESTS)
endif
......
......@@ -14,11 +14,11 @@
#include <iostream>
#include <string>
#include <sys/time.h>
#include <sys/resource.h>
#include <gtest/gtest.h>
#include <testutils/resource.h>
#include <log/logger.h>
#include <log/logger_manager.h>
#include <log/logger_name.h>
......@@ -372,14 +372,7 @@ TEST_F(LoggerTest, LoggerNameLength) {
// Note that we just check that it dies - we don't check what message is
// output.
EXPECT_DEATH({
/* 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. */
rlimit core_limit;
core_limit.rlim_cur = 0;
core_limit.rlim_max = 0;
EXPECT_EQ(setrlimit(RLIMIT_CORE, &core_limit), 0);
isc::testutils::dontCreateCoreDumps();
string ok3(Logger::MAX_LOGGER_NAME_SIZE + 1, 'x');
Logger l3(ok3.c_str());
......
......@@ -12,10 +12,9 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <sys/time.h>
#include <sys/resource.h>
#include <log/message_initializer.h>
#include <gtest/gtest.h>
#include <testutils/resource.h>
using namespace isc::log;
......@@ -44,14 +43,7 @@ TEST(MessageInitializerTest2, MessageLoadTest) {
#ifdef EXPECT_DEATH
// Adding one more should take us over the limit.
EXPECT_DEATH({
/* 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. */
rlimit core_limit;
core_limit.rlim_cur = 0;
core_limit.rlim_max = 0;
EXPECT_EQ(setrlimit(RLIMIT_CORE, &core_limit), 0);
isc::testutils::dontCreateCoreDumps();
MessageInitializer initializer2(values);
}, ".*");
......
......@@ -48,6 +48,7 @@ run_unittests_LDADD += $(top_builddir)/src/lib/util/unittests/libutil_unittests.
run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
run_unittests_LDADD += $(top_builddir)/src/lib/config/libcfgclient.la
run_unittests_LDADD += $(top_builddir)/src/lib/config/tests/libfake_session.la
run_unittests_LDADD += $(top_builddir)/src/lib/testutils/libtestutils.la
endif
noinst_PROGRAMS = $(TESTS)
......
......@@ -12,12 +12,10 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <sys/time.h>
#include <sys/resource.h>
#include <server_common/portconfig.h>
#include <testutils/socket_request.h>
#include <testutils/mockups.h>
#include <testutils/resource.h>
#include <cc/data.h>
#include <exceptions/exceptions.h>
......@@ -316,14 +314,7 @@ TEST_F(InstallListenAddressesDeathTest, inconsistent) {
// Make sure it actually kills the application (there should be an abort
// in this case)
EXPECT_DEATH({
/* 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. */
rlimit core_limit;
core_limit.rlim_cur = 0;
core_limit.rlim_max = 0;
EXPECT_EQ(setrlimit(RLIMIT_CORE, &core_limit), 0);
isc::testutils::dontCreateCoreDumps();
try {
installListenAddresses(deathAddresses, store_, dnss_);
......@@ -342,14 +333,7 @@ TEST_F(InstallListenAddressesDeathTest, cantClose) {
// Instruct it to fail on close
sock_requestor_.break_release_ = true;
EXPECT_DEATH({
/* 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. */
rlimit core_limit;
core_limit.rlim_cur = 0;
core_limit.rlim_max = 0;
EXPECT_EQ(setrlimit(RLIMIT_CORE, &core_limit), 0);
isc::testutils::dontCreateCoreDumps();
try {
// Setting to empty will close all current sockets.
......
......@@ -9,6 +9,7 @@ noinst_LTLIBRARIES = libtestutils.la
libtestutils_la_SOURCES = srv_test.h srv_test.cc
libtestutils_la_SOURCES += dnsmessage_test.h dnsmessage_test.cc
libtestutils_la_SOURCES += resource.cc resource.h
libtestutils_la_SOURCES += mockups.h
libtestutils_la_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
libtestutils_la_LIBADD = $(top_builddir)/src/lib/asiolink/libasiolink.la
......
// 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 <sys/time.h>
#include <sys/resource.h>
#include <gtest/gtest.h>
namespace isc {
namespace testutils {
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. */
rlimit core_limit = {0, 0};
EXPECT_EQ(setrlimit(RLIMIT_CORE, &core_limit), 0);
}
} // end of namespace testutils
} // end of namespace isc
// 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.
#ifndef __ISC_TESTUTILS_RESOURCE_H
#define __ISC_TESTUTILS_RESOURCE_H
namespace isc {
namespace testutils {
/// Don't create core dumps.
///
/// This function sets the core size to 0, inhibiting the creation of
/// core dumps. It is meant to be used in testcases where EXPECT_DEATH
/// 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.
void
dontCreateCoreDumps(void);
} // end of namespace testutils
} // end of namespace isc
#endif /* __ISC_TESTUTILS_RESOURCE_H */
......@@ -44,6 +44,7 @@ run_unittests_LDADD += $(top_builddir)/src/lib/util/io/libutil_io.la
run_unittests_LDADD += \
$(top_builddir)/src/lib/util/unittests/libutil_unittests.la
run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
run_unittests_LDADD += $(top_builddir)/src/lib/testutils/libtestutils.la
endif
noinst_PROGRAMS = $(TESTS)
......@@ -12,10 +12,8 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <sys/time.h>
#include <sys/resource.h>
#include <exceptions/exceptions.h>
#include <testutils/resource.h>
#include <util/buffer.h>
......@@ -188,14 +186,7 @@ TEST_F(BufferTest, outputBufferReadat) {
#ifdef EXPECT_DEATH
// We use assert now, so we check it dies
EXPECT_DEATH({
/* 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. */
rlimit core_limit;
core_limit.rlim_cur = 0;
core_limit.rlim_max = 0;
EXPECT_EQ(setrlimit(RLIMIT_CORE, &core_limit), 0);
isc::testutils::dontCreateCoreDumps();
try {
obuffer[sizeof(testdata)];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment