BIND 10 trac976, updated. 2e386bd4b400b73103900bcccb8b5166258448a6 [trac976] Reformat shell test output

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Jun 8 18:04:38 UTC 2011


The branch, trac976 has been updated
       via  2e386bd4b400b73103900bcccb8b5166258448a6 (commit)
       via  dd46abf659db56f51b981ff675ef02ea92d70ed5 (commit)
       via  cbe4f685dbfcef07a17c6cef56d35abf12fd677b (commit)
      from  a4b89470c575878fbd0d3e1bddd45ed2a3289e6b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 2e386bd4b400b73103900bcccb8b5166258448a6
Author: Stephen Morris <stephen at isc.org>
Date:   Wed Jun 8 19:04:17 2011 +0100

    [trac976] Reformat shell test output

commit dd46abf659db56f51b981ff675ef02ea92d70ed5
Author: Stephen Morris <stephen at isc.org>
Date:   Wed Jun 8 18:45:34 2011 +0100

    [trac976] Ensure unit tests reset back to original logging state

commit cbe4f685dbfcef07a17c6cef56d35abf12fd677b
Author: Stephen Morris <stephen at isc.org>
Date:   Wed Jun 8 18:45:16 2011 +0100

    [trac976] Ensure reset() resets back to state passed by init()

-----------------------------------------------------------------------

Summary of changes:
 src/lib/log/logger_manager.cc                |   32 ++++++++++++++++++++++++-
 src/lib/log/logger_manager.h                 |    3 +-
 src/lib/log/tests/console_test.sh.in         |   12 +++++-----
 src/lib/log/tests/destination_test.sh.in     |   14 ++++++++---
 src/lib/log/tests/local_file_test.sh.in      |    8 +++---
 src/lib/log/tests/logger_level_unittest.cc   |   11 +--------
 src/lib/log/tests/logger_manager_unittest.cc |    6 +----
 src/lib/log/tests/logger_name_unittest.cc    |   25 ++++++++++++++++++-
 src/lib/log/tests/logger_unittest.cc         |    8 +-----
 src/lib/log/tests/severity_test.sh.in        |   10 ++++----
 10 files changed, 83 insertions(+), 46 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/log/logger_manager.cc b/src/lib/log/logger_manager.cc
index c0fe7ed..52e4236 100644
--- a/src/lib/log/logger_manager.cc
+++ b/src/lib/log/logger_manager.cc
@@ -35,8 +35,28 @@ namespace {
 
 // Logger used for logging messages within the logging code itself.
 isc::log::Logger logger("log");
+
+// Static stores for the initialization severity and debug level.
+// These are put in methods to avoid a "static initialization fiasco".
+
+isc::log::Severity& initSeverity() {
+    static isc::log::Severity severity = isc::log::INFO;
+    return (severity);
 }
 
+int& initDebugLevel() {
+    static int dbglevel = 0;
+    return (dbglevel);
+}
+
+std::string& initRootName() {
+    static std::string root("b10root");
+    return (root);
+}
+
+} // Anonymous namespace
+
+
 namespace isc {
 namespace log {
 
@@ -75,6 +95,13 @@ void
 LoggerManager::init(const std::string& root, isc::log::Severity severity,
                     int dbglevel, const char* file)
 {
+    // Save name, severity and debug level for later.  No need to save the
+    // file name as once the local message file is read the messages will
+    // not be lost.
+    initRootName() = root;
+    initSeverity() = severity;
+    initDebugLevel() = dbglevel;
+
     // Create the BIND 10 root logger and set the default severity and
     // debug level.  This is the logger that has the name of the application.
     // All other loggers created in this application will be its children.
@@ -145,10 +172,11 @@ LoggerManager::readLocalMessageFile(const char* file) {
     }
 }
 
-// Reset logging
+// Reset logging to settings passed to init()
 void
 LoggerManager::reset() {
-    LoggerManagerImpl::reset();
+    setRootLoggerName(initRootName());
+    LoggerManagerImpl::reset(initSeverity(), initDebugLevel());
 }
 
 } // namespace log
diff --git a/src/lib/log/logger_manager.h b/src/lib/log/logger_manager.h
index a870340..dece0c9 100644
--- a/src/lib/log/logger_manager.h
+++ b/src/lib/log/logger_manager.h
@@ -97,8 +97,7 @@ public:
 
     /// \brief Reset logging
     ///
-    /// Resets logging to default (just the root logger output INFO or above
-    /// messages to the console.
+    /// Resets logging to whatever was set in the call to init().
     static void reset();
 
     /// \brief Read local message file
diff --git a/src/lib/log/tests/console_test.sh.in b/src/lib/log/tests/console_test.sh.in
index 7117a0c..7ef2684 100755
--- a/src/lib/log/tests/console_test.sh.in
+++ b/src/lib/log/tests/console_test.sh.in
@@ -28,29 +28,29 @@ tempfile=@abs_builddir@/console_test_tempfile_$$
 passfail() {
     count=`wc -l $tempfile | awk '{print $1}'`
     if [ $count -eq $1 ]; then
-        echo " -- pass"
+        echo " pass"
     else
-        echo " ** FAIL"
+        echo " FAIL"
         failcount=`expr $failcount + $1`
     fi
 }
 
-echo "1. Checking that console output to stdout goes to stdout:"
+echo -n "1. Checking that console output to stdout goes to stdout:"
 rm -f $tempfile
 ./logger_example -c stdout -s error 1> $tempfile 2> /dev/null
 passfail 4
 
-echo "2. Checking that console output to stdout does not go to stderr:"
+echo -n "2. Checking that console output to stdout does not go to stderr:"
 rm -f $tempfile
 ./logger_example -c stdout -s error 1> /dev/null 2> $tempfile
 passfail 0
 
-echo "3. Checking that console output to stderr goes to stderr:"
+echo -n "3. Checking that console output to stderr goes to stderr:"
 rm -f $tempfile
 ./logger_example -c stderr -s error 1> /dev/null 2> $tempfile
 passfail 4
 
-echo "4. Checking that console output to stderr does not go to stdout:"
+echo -n "4. Checking that console output to stderr does not go to stdout:"
 rm -f $tempfile
 ./logger_example -c stderr -s error 1> $tempfile 2> /dev/null
 passfail 0
diff --git a/src/lib/log/tests/destination_test.sh.in b/src/lib/log/tests/destination_test.sh.in
index 9198184..ff2d3fb 100755
--- a/src/lib/log/tests/destination_test.sh.in
+++ b/src/lib/log/tests/destination_test.sh.in
@@ -28,14 +28,14 @@ destfile2=@abs_builddir@/destination_test_destfile_2_$$
 
 passfail() {
     if [ $1 -eq 0 ]; then
-        echo " -- pass"
+        echo " pass"
     else
-        echo " ** FAIL"
+        echo " FAIL"
         failcount=`expr $failcount + $1`
     fi
 }
 
-echo "1. One logger, multiple destinations"
+echo "1. One logger, multiple destinations:"
 cat > $tempfile << .
 FATAL [example] MSG_WRITERR, error writing to test1: 42
 ERROR [example] MSG_RDLOCMES, reading local message file dummy/file
@@ -44,12 +44,16 @@ ERROR [example.beta] MSG_BADDESTINATION, unrecognized log destination: beta_erro
 .
 rm -f $destfile1 $destfile2
 ./logger_example -s error -f $destfile1 -f $destfile2
+
+echo -n  "   - destination 1:"
 cut -d' ' -f3- $destfile1 | diff $tempfile -
 passfail $?
+
+echo -n  "   - destination 2:"
 cut -d' ' -f3- $destfile2 | diff $tempfile -
 passfail $?
 
-echo "2. Two loggers, different destinations and severities"
+echo     "2. Two loggers, different destinations and severities"
 rm -f $destfile1 $destfile2
 ./logger_example -l example -s info -f $destfile1 -l alpha -s warn -f $destfile2
 
@@ -65,9 +69,11 @@ ERROR [example.beta] MSG_BADDESTINATION, unrecognized log destination: beta_erro
 WARN  [example.beta] MSG_BADSTREAM, bad log console output stream: beta_warn
 INFO  [example.beta] MSG_READERR, error reading from message file beta: info
 .
+echo -n  "   - destination 1:"
 cut -d' ' -f3- $destfile1 | diff $tempfile -
 passfail $?
 
+echo -n  "   - destination 2:"
 cat > $tempfile << .
 WARN  [example.alpha] MSG_READERR, error reading from message file a.txt: dummy reason
 .
diff --git a/src/lib/log/tests/local_file_test.sh.in b/src/lib/log/tests/local_file_test.sh.in
index f763192..53b0c2f 100755
--- a/src/lib/log/tests/local_file_test.sh.in
+++ b/src/lib/log/tests/local_file_test.sh.in
@@ -27,9 +27,9 @@ tempfile=@abs_builddir@/run_time_init_test_tempfile_$$
 
 passfail() {
     if [ $1 -eq 0 ]; then
-        echo " -- pass"
+        echo " pass"
     else
-        echo " ** FAIL"
+        echo " FAIL"
         failcount=`expr $failcount + $1`
     fi
 }
@@ -43,7 +43,7 @@ cat > $localmes << .
 % RDLOCMES    replacement read local message file, parameter is '%1'
 .
 
-echo "1. Local message replacement:"
+echo -n "1. Local message replacement:"
 cat > $tempfile << .
 WARN  [example.log] MSG_IDNOTFND, could not replace message text for 'MSG_NOTHERE': no such message
 FATAL [example] MSG_WRITERR, error writing to test1: 42
@@ -57,7 +57,7 @@ WARN  [example.beta] MSG_BADSTREAM, bad log console output stream: beta_warn
 ./logger_example -c stdout -s warn $localmes | cut -d' ' -f3- | diff $tempfile -
 passfail $?
 
-echo "2. Report error if unable to read local message file:"
+echo -n "2. Report error if unable to read local message file:"
 cat > $tempfile << .
 ERROR [example.log] MSG_OPENIN, unable to open message file $localmes for input: No such file or directory
 FATAL [example] MSG_WRITERR, error writing to test1: 42
diff --git a/src/lib/log/tests/logger_level_unittest.cc b/src/lib/log/tests/logger_level_unittest.cc
index b97282a..13d33b2 100644
--- a/src/lib/log/tests/logger_level_unittest.cc
+++ b/src/lib/log/tests/logger_level_unittest.cc
@@ -26,14 +26,10 @@ using namespace isc;
 using namespace isc::log;
 using namespace std;
 
-namespace {
-string ROOT_NAME("logleveltest");
-}
-
 class LoggerLevelTest : public ::testing::Test {
 protected:
     LoggerLevelTest() {
-        LoggerManager::init(ROOT_NAME);
+        // Logger initialization is done in main()
     }
     ~LoggerLevelTest() {
         LoggerManager::reset();
@@ -62,11 +58,6 @@ TEST_F(LoggerLevelTest, Creation) {
 }
 
 TEST(LoggerLevel, getSeverity) {
-    // Should initialize logger as getSeverity() may output
-    // a message.  This gives a properly-qualified logger
-    // name.
-    LoggerManager::init(ROOT_NAME);
-
     EXPECT_EQ(DEBUG, getSeverity("DEBUG"));
     EXPECT_EQ(DEBUG, getSeverity("debug"));
     EXPECT_EQ(DEBUG, getSeverity("DeBuG"));
diff --git a/src/lib/log/tests/logger_manager_unittest.cc b/src/lib/log/tests/logger_manager_unittest.cc
index a9a3a5e..115c928 100644
--- a/src/lib/log/tests/logger_manager_unittest.cc
+++ b/src/lib/log/tests/logger_manager_unittest.cc
@@ -40,15 +40,11 @@ using namespace isc;
 using namespace isc::log;
 using namespace std;
 
-namespace {
-string ROOT_NAME("logmgrtest");
-}
-
 /// \brief LoggerManager Test
 class LoggerManagerTest : public ::testing::Test {
 public:
     LoggerManagerTest() {
-        LoggerManager::init(ROOT_NAME);
+        // Initialization of logging is done in main()
     }
 
     ~LoggerManagerTest() {
diff --git a/src/lib/log/tests/logger_name_unittest.cc b/src/lib/log/tests/logger_name_unittest.cc
index 2f538ca..51fead5 100644
--- a/src/lib/log/tests/logger_name_unittest.cc
+++ b/src/lib/log/tests/logger_name_unittest.cc
@@ -21,9 +21,30 @@
 using namespace isc;
 using namespace isc::log;
 
+// Test class.  To avoid disturbing the root logger configuration in other
+// tests in the suite, the root logger name is saved in the constructor and
+// restored in the destructor.  However, this is a bit chicken and egg, as the
+// functions used to do the save and restore are those being tested...
+//
+// Note that the root name is originally set by the initialization of the
+// logging configuration done in main().
+
+class LoggerNameTest : public ::testing::Test {
+public:
+    LoggerNameTest() {
+        name_ = getRootLoggerName();
+    }
+    ~LoggerNameTest() {
+        setRootLoggerName(name_);
+    }
+
+private:
+    std::string     name_;  ///< Saved name
+};
+
 // Check setting and getting of root name
 
-TEST(LoggerNameTest, RootNameSetGet) {
+TEST_F(LoggerNameTest, RootNameSetGet) {
     const std::string name1 = "test1";
     const std::string name2 = "test2";
 
@@ -44,7 +65,7 @@ TEST(LoggerNameTest, RootNameSetGet) {
 
 // Check expansion of name
 
-TEST(LoggerNameTest, ExpandLoggerName) {
+TEST_F(LoggerNameTest, ExpandLoggerName) {
     const std::string ROOT = "example";
     const std::string NAME = "something";
     const std::string FULL_NAME = ROOT + "." + NAME;
diff --git a/src/lib/log/tests/logger_unittest.cc b/src/lib/log/tests/logger_unittest.cc
index 2b4a3b6..b7858e5 100644
--- a/src/lib/log/tests/logger_unittest.cc
+++ b/src/lib/log/tests/logger_unittest.cc
@@ -26,10 +26,6 @@ using namespace isc;
 using namespace isc::log;
 using namespace std;
 
-namespace {
-string ROOT_NAME = "loggertest";
-}
-
 /// \brief Logger Test
 ///
 /// As the logger is only a shell around the implementation, this tests also
@@ -38,7 +34,7 @@ string ROOT_NAME = "loggertest";
 class LoggerTest : public ::testing::Test {
 public:
     LoggerTest() {
-        LoggerManager::init(ROOT_NAME);
+        // Initialization of logging is done in main()
     }
     ~LoggerTest() {
         LoggerManager::reset();
@@ -54,7 +50,7 @@ TEST_F(LoggerTest, Name) {
     Logger logger("alpha");
 
     // ... and check the name
-    EXPECT_EQ(ROOT_NAME + string(".alpha"), logger.getName());
+    EXPECT_EQ(getRootLoggerName() + string(".alpha"), logger.getName());
 }
 
 // This test attempts to get two instances of a logger with the same name
diff --git a/src/lib/log/tests/severity_test.sh.in b/src/lib/log/tests/severity_test.sh.in
index 7f5c649..6f4d27a 100755
--- a/src/lib/log/tests/severity_test.sh.in
+++ b/src/lib/log/tests/severity_test.sh.in
@@ -26,14 +26,14 @@ tempfile=@abs_builddir@/severity_test_tempfile_$$
 
 passfail() {
     if [ $1 -eq 0 ]; then
-        echo " -- pass"
+        echo " pass"
     else
-        echo " ** FAIL"
+        echo " FAIL"
         failcount=`expr $failcount + $1`
     fi
 }
 
-echo "1. runInitTest default parameters: "
+echo -n "1. runInitTest default parameters:"
 cat > $tempfile << .
 FATAL [example] MSG_WRITERR, error writing to test1: 42
 ERROR [example] MSG_RDLOCMES, reading local message file dummy/file
@@ -48,7 +48,7 @@ INFO  [example.beta] MSG_READERR, error reading from message file beta: info
 ./logger_example -c stdout | cut -d' ' -f3- | diff $tempfile -
 passfail $?
 
-echo "2. Severity filter: "
+echo -n "2. Severity filter:"
 cat > $tempfile << .
 FATAL [example] MSG_WRITERR, error writing to test1: 42
 ERROR [example] MSG_RDLOCMES, reading local message file dummy/file
@@ -58,7 +58,7 @@ ERROR [example.beta] MSG_BADDESTINATION, unrecognized log destination: beta_erro
 ./logger_example -c stdout -s error | cut -d' ' -f3- | diff $tempfile -
 passfail $?
 
-echo "3. Debug level: "
+echo -n "3. Debug level:"
 cat > $tempfile << .
 FATAL [example] MSG_WRITERR, error writing to test1: 42
 ERROR [example] MSG_RDLOCMES, reading local message file dummy/file




More information about the bind10-changes mailing list