Commit 949d3d2f authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[1704] Check that logger acquires and releases locks correctly when logging messages

parent e04531f5
......@@ -1184,6 +1184,7 @@ AC_OUTPUT([doc/version.ent
src/lib/log/tests/destination_test.sh
src/lib/log/tests/init_logger_test.sh
src/lib/log/tests/local_file_test.sh
src/lib/log/tests/logger_lock_test.sh
src/lib/log/tests/severity_test.sh
src/lib/log/tests/tempdir.h
src/lib/util/python/mkpywrapper.py
......@@ -1232,6 +1233,7 @@ AC_OUTPUT([doc/version.ent
chmod +x src/lib/log/tests/destination_test.sh
chmod +x src/lib/log/tests/init_logger_test.sh
chmod +x src/lib/log/tests/local_file_test.sh
chmod +x src/lib/log/tests/logger_lock_test.sh
chmod +x src/lib/log/tests/severity_test.sh
chmod +x src/lib/util/python/mkpywrapper.py
chmod +x src/lib/util/python/gen_wiredata.py
......
......@@ -6,6 +6,8 @@
/initializer_unittests_2
/local_file_test.sh
/logger_example
/logger_lock_test
/logger_lock_test.sh
/log_test_messages.cc
/log_test_messages.h
/run_unittests
......
......@@ -35,6 +35,16 @@ init_logger_test_LDADD += $(top_builddir)/src/lib/util/libutil.la
init_logger_test_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
init_logger_test_LDADD += $(AM_LDADD) $(LOG4CPLUS_LIBS)
noinst_PROGRAMS += logger_lock_test
logger_lock_test_SOURCES = logger_lock_test.cc
logger_lock_test_SOURCES += log_test_messages.cc log_test_messages.h
logger_lock_test_CPPFLAGS = $(AM_CPPFLAGS)
logger_lock_test_LDFLAGS = $(AM_LDFLAGS)
logger_lock_test_LDADD = $(top_builddir)/src/lib/log/liblog.la
logger_lock_test_LDADD += $(top_builddir)/src/lib/util/libutil.la
logger_lock_test_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
logger_lock_test_LDADD += $(AM_LDADD) $(LOG4CPLUS_LIBS)
if HAVE_GTEST
TESTS =
......@@ -110,4 +120,5 @@ check-local:
$(SHELL) $(abs_builddir)/destination_test.sh
$(SHELL) $(abs_builddir)/init_logger_test.sh
$(SHELL) $(abs_builddir)/local_file_test.sh
$(SHELL) $(abs_builddir)/logger_lock_test.sh
$(SHELL) $(abs_builddir)/severity_test.sh
// 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 <log/macros.h>
#include <log/logger_support.h>
#include <log/log_messages.h>
#include "util/interprocess_sync.h"
#include "log_test_messages.h"
#include <iostream>
using namespace std;
using namespace isc::log;
class MockLoggingSync : public isc::util::InterprocessSync {
public:
/// \brief Constructor
MockLoggingSync(const std::string& component_name) :
InterprocessSync(component_name)
{}
protected:
bool lock() {
cout << "FIELD1 FIELD2 LOGGER_LOCK_TEST: LOCK\n";
return (true);
}
bool tryLock() {
cout << "FIELD1 FIELD2 LOGGER_LOCK_TEST: TRYLOCK\n";
return (true);
}
bool unlock() {
cout << "FIELD1 FIELD2 LOGGER_LOCK_TEST: UNLOCK\n";
return (true);
}
};
/// \brief Test InitLogger
///
/// A program used in testing the logger that initializes logging using
/// initLogger(), then outputs several messages at different severities and
/// debug levels. An external script sets the environment variables and checks
/// that they have the desired effect.
int
main(int, char**) {
initLogger();
Logger logger("log");
logger.setInterprocessSync(new MockLoggingSync("log"));
LOG_INFO(logger, LOG_LOCK_TEST_MESSAGE);
return (0);
}
#!/bin/sh
# 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.
# Checks that the locker interprocess sync locks are acquired and
# released correctly.
failcount=0
tempfile=@abs_builddir@/logger_lock_test_tempfile_$$
destfile=@abs_builddir@/logger_lock_test_destfile_$$
passfail() {
if [ $1 -eq 0 ]; then
echo " pass"
else
echo " FAIL"
failcount=`expr $failcount + $1`
fi
}
echo -n "Testing that logger acquires and releases locks correctly:"
cat > $tempfile << .
LOGGER_LOCK_TEST: LOCK
INFO [bind10.log] LOG_LOCK_TEST_MESSAGE this is a test message.
LOGGER_LOCK_TEST: UNLOCK
LOGGER_LOCK_TEST: UNLOCK
.
rm -f $destfile
B10_LOGGER_SEVERITY=INFO B10_LOGGER_DESTINATION=stdout ./logger_lock_test > $destfile
cut -d' ' -f3- $destfile | diff $tempfile -
passfail $?
# Tidy up.
rm -f $tempfile $destfile
exit $failcount
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