From f3395938a1ead66ef30ab1d261e3a38fea16faa4 Mon Sep 17 00:00:00 2001 From: Stephen Morris Date: Fri, 27 May 2011 14:41:22 +0100 Subject: [PATCH] [trac555] Reorganisation of stand-along logger tests Renamed the logger_support_test program to the more descriptive (and accurate) logger_example, and separated out the different tests into different shell scripts. --- configure.ac | 3 +- src/lib/log/logger_manager.h | 18 +++++----- src/lib/log/tests/Makefile.am | 17 ++++----- src/lib/log/tests/console_test.sh.in | 13 ++++--- ...gger_support_test.cc => logger_example.cc} | 15 ++++---- ...me_init_test.sh.in => severity_test.sh.in} | 36 ++++++------------- 6 files changed, 47 insertions(+), 55 deletions(-) rename src/lib/log/tests/{logger_support_test.cc => logger_example.cc} (94%) rename src/lib/log/tests/{run_time_init_test.sh.in => severity_test.sh.in} (67%) diff --git a/configure.ac b/configure.ac index f6908a7f97..771391fced 100644 --- a/configure.ac +++ b/configure.ac @@ -892,7 +892,8 @@ AC_OUTPUT([doc/version.ent src/lib/cc/session_config.h.pre src/lib/cc/tests/session_unittests_config.h src/lib/log/tests/console_test.sh - src/lib/log/tests/run_time_init_test.sh + src/lib/log/tests/local_file_test.sh + src/lib/log/tests/severity_test.sh src/lib/util/python/mkpywrapper.py src/lib/server_common/tests/data_path.h tests/system/conf.sh diff --git a/src/lib/log/logger_manager.h b/src/lib/log/logger_manager.h index f36e493d7a..010c764458 100644 --- a/src/lib/log/logger_manager.h +++ b/src/lib/log/logger_manager.h @@ -82,6 +82,15 @@ public: isc::log::Severity severity = isc::log::INFO, int dbglevel = 0); + /// \brief Read local message file + /// + /// Reads the local message file into the global dictionary, overwriting + /// existing messages. If the file contained any message IDs not in the + /// dictionary, they are listed in a warning message. + /// + /// \param file Name of the local message file + static void readLocalMessageFile(const char* file); + private: /// \brief Initialize Processing /// @@ -102,15 +111,6 @@ private: /// TODO: Check that the root logger has something enabled void processEnd(); - /// \brief Read local message file - /// - /// Reads the local message file into the global dictionary, overwriting - /// existing messages. If the file contained any message IDs not in the - /// dictionary, they are listed in a warning message. - /// - /// \param file Name of the local message file - static void readLocalMessageFile(const char* file); - // Members LoggerManagerImpl* impl_; ///< Pointer to implementation }; diff --git a/src/lib/log/tests/Makefile.am b/src/lib/log/tests/Makefile.am index a66dc83e48..549d53c34b 100644 --- a/src/lib/log/tests/Makefile.am +++ b/src/lib/log/tests/Makefile.am @@ -36,17 +36,18 @@ run_unittests_LDADD += $(top_builddir)/src/lib/util/libutil.la run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la endif -TESTS += logger_support_test -logger_support_test_SOURCES = logger_support_test.cc -logger_support_test_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) -logger_support_test_LDFLAGS = $(AM_LDFLAGS) $(LOG4CPLUS_LDFLAGS) -logger_support_test_LDADD = $(top_builddir)/src/lib/log/liblog.la -logger_support_test_LDADD += $(top_builddir)/src/lib/util/libutil.la +TESTS += logger_example +logger_example_SOURCES = logger_example.cc +logger_example_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) +logger_example_LDFLAGS = $(AM_LDFLAGS) $(LOG4CPLUS_LDFLAGS) +logger_example_LDADD = $(top_builddir)/src/lib/log/liblog.la +logger_example_LDADD += $(top_builddir)/src/lib/util/libutil.la noinst_PROGRAMS = $(TESTS) # Additional test using the shell -PYTESTS = run_time_init_test.sh console_test.sh +PYTESTS = console_test.sh local_file_test.sh severity_test.sh check-local: - $(SHELL) $(abs_builddir)/run_time_init_test.sh $(SHELL) $(abs_builddir)/console_test.sh + $(SHELL) $(abs_builddir)/local_file_test.sh + $(SHELL) $(abs_builddir)/severity_test.sh diff --git a/src/lib/log/tests/console_test.sh.in b/src/lib/log/tests/console_test.sh.in index ea2e4591b0..e499dfdfa4 100755 --- a/src/lib/log/tests/console_test.sh.in +++ b/src/lib/log/tests/console_test.sh.in @@ -13,6 +13,11 @@ # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. +# \brief +# +# The logger supports the idea of a "console" logger than logs to either stdout +# or stderr. This test checks that both these options work. + testname="Console output test" echo $testname @@ -32,22 +37,22 @@ passfail() { echo "1. Checking that console output to stdout goes to stdout:" rm -f $tempfile -./logger_support_test -s error -c stdout 1> $tempfile +./logger_example -s error -c stdout 1> $tempfile passfail 2 echo "2. Checking that console output to stdout does not go to stderr:" rm -f $tempfile -./logger_support_test -s error -c stdout 2> $tempfile +./logger_example -s error -c stdout 2> $tempfile passfail 0 echo "3. Checking that console output to stderr goes to stderr:" rm -f $tempfile -./logger_support_test -s error -c stderr 2> $tempfile +./logger_example -s error -c stderr 2> $tempfile passfail 2 echo "4. Checking that console output to stderr does not go to stdout:" rm -f $tempfile -./logger_support_test -s error -c stderr 1> $tempfile +./logger_example -s error -c stderr 1> $tempfile passfail 0 rm -f $tempfile diff --git a/src/lib/log/tests/logger_support_test.cc b/src/lib/log/tests/logger_example.cc similarity index 94% rename from src/lib/log/tests/logger_support_test.cc rename to src/lib/log/tests/logger_example.cc index 2200183179..fb86ad470f 100644 --- a/src/lib/log/tests/logger_support_test.cc +++ b/src/lib/log/tests/logger_example.cc @@ -14,7 +14,11 @@ /// \brief Example Program /// -/// Simple example program showing how to use the logger. +/// Simple example program showing how to use the logger. The various +/// command-line options let most aspects of the logger be exercised, so +/// making this a useful tool for testing. +/// +/// See the usage() method for details of use. #include #include @@ -75,16 +79,13 @@ int main(int argc, char** argv) { bool f_found = false; // Set true if "-f" found bool l_found = false; // Set true if "-l" found - const char* localfile = NULL; // Local message file int option; // For getopt() processing LoggerSpecification spec(ROOT_NAME); // Logger specification OutputOption outopt; // Logger output option // Initialize loggers (to set the root name and initialize logging); - // We'll reset them later. - setRootLoggerName(ROOT_NAME); - Logger rootLogger(ROOT_NAME); + LoggerManager::init(ROOT_NAME); // Parse options while ((option = getopt(argc, argv, "hc:d:f:s:")) != -1) { @@ -145,12 +146,12 @@ int main(int argc, char** argv) { } } + // Set the local file if (optind < argc) { - localfile = argv[optind]; + LoggerManager::readLocalMessageFile(argv[optind]); } // Update the logging parameters - LoggerManager::init(ROOT_NAME, localfile, isc::log::INFO, 0); // Set an output option if we have not done so already. if (! (c_found || f_found || l_found)) { diff --git a/src/lib/log/tests/run_time_init_test.sh.in b/src/lib/log/tests/severity_test.sh.in similarity index 67% rename from src/lib/log/tests/run_time_init_test.sh.in rename to src/lib/log/tests/severity_test.sh.in index 45c3774740..bee041dc33 100755 --- a/src/lib/log/tests/run_time_init_test.sh.in +++ b/src/lib/log/tests/severity_test.sh.in @@ -13,12 +13,16 @@ # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. -testname="Run-time initialization test" +# \brief Severity test +# +# Checks that the logger will limit the output of messages less severy than +# the severity/debug setting. + +testname="Severity test" echo $testname failcount=0 -localmes=@abs_builddir@/localdef_mes_$$ -tempfile=@abs_builddir@/run_time_init_test_tempfile_$$ +tempfile=@abs_builddir@/severity_test_tempfile_$$ passfail() { if [ $1 -eq 0 ]; then @@ -29,15 +33,6 @@ passfail() { fi } -# Create the local message file for testing - -cat > $localmes << . -\$PREFIX MSG_ -% NOTHERE this message is not in the global dictionary -% READERR replacement read error, parameters: '%1' and '%2' -% RDLOCMES replacement read local message file, parameter is '%1' -. - echo "1. runInitTest default parameters: " cat > $tempfile << . FATAL [alpha.example] MSG_WRITERR, error writing to test1: 42 @@ -45,7 +40,7 @@ ERROR [alpha.example] MSG_RDLOCMES, reading local message file dummy/file WARN [alpha.dlm] MSG_READERR, error reading from message file a.txt: dummy reason INFO [alpha.dlm] MSG_OPENIN, unable to open message file example.msg for input: dummy reason . -./logger_support_test | cut -d' ' -f3- | diff $tempfile - +./logger_example | cut -d' ' -f3- | diff $tempfile - passfail $? echo "2. Severity filter: " @@ -53,7 +48,7 @@ cat > $tempfile << . FATAL [alpha.example] MSG_WRITERR, error writing to test1: 42 ERROR [alpha.example] MSG_RDLOCMES, reading local message file dummy/file . -./logger_support_test -s error | cut -d' ' -f3- | diff $tempfile - +./logger_example -s error | cut -d' ' -f3- | diff $tempfile - passfail $? echo "3. Debug level: " @@ -66,20 +61,9 @@ DEBUG [alpha.example] MSG_RDLOCMES, reading local message file dummy/0 DEBUG [alpha.example] MSG_RDLOCMES, reading local message file dummy/24 DEBUG [alpha.example] MSG_RDLOCMES, reading local message file dummy/25 . -./logger_support_test -s debug -d 25 | cut -d' ' -f3- | diff $tempfile - +./logger_example -s debug -d 25 | cut -d' ' -f3- | diff $tempfile - passfail $? -echo "4. Local message replacement: " -cat > $tempfile << . -WARN [alpha.log] MSG_IDNOTFND, could not replace message text for 'MSG_NOTHERE': no such message -FATAL [alpha.example] MSG_WRITERR, error writing to test1: 42 -ERROR [alpha.example] MSG_RDLOCMES, replacement read local message file, parameter is 'dummy/file' -WARN [alpha.dlm] MSG_READERR, replacement read error, parameters: 'a.txt' and 'dummy reason' -. -./logger_support_test -s warn $localmes | cut -d' ' -f3- | diff $tempfile - -passfail $? - -rm -f $localmes rm -f $tempfile if [ $failcount -eq 0 ]; then