mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 05:27:55 +00:00
[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.
This commit is contained in:
parent
36e95aa116
commit
f3395938a1
@ -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
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@ -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)) {
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user