1#!/bin/sh
2
3# Copyright (C) 2011-2020 Internet Systems Consortium, Inc. ("ISC")
4#
5# This Source Code Form is subject to the terms of the Mozilla Public
6# License, v. 2.0. If a copy of the MPL was not distributed with this
7# file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
9# Checks that the logger will limit the output of messages less severe than
10# the severity/debug setting.
11
12# Exit with error if commands exit with non-zero and if undefined variables are
13# used.
14set -eu
15
16# Include common test library.
17# shellcheck disable=SC1091
18# SC1091: Not following: ... was not specified as input (see shellcheck -x).
19. "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"
20
21tempfile="@abs_builddir@/severity_test_tempfile_$$"
22
23test_start 'severity.default-parameters'
24cat > $tempfile << .
25FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
26ERROR [example] LOG_READING_LOCAL_FILE reading local message file dummy/file
27WARN  [example] LOG_BAD_STREAM bad log console output stream: example
28WARN  [example.alpha] LOG_READ_ERROR error reading from message file a.txt: dummy reason
29INFO  [example.alpha] LOG_INPUT_OPEN_FAIL unable to open message file example.msg for input: dummy reason
30FATAL [example.beta] LOG_BAD_SEVERITY unrecognized log severity: beta_fatal
31ERROR [example.beta] LOG_BAD_DESTINATION unrecognized log destination: beta_error
32WARN  [example.beta] LOG_BAD_STREAM bad log console output stream: beta_warn
33INFO  [example.beta] LOG_READ_ERROR error reading from message file beta: info
34.
35./logger_example -c stdout | \
36    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
37    cut -d' ' -f3- | diff $tempfile -
38test_finish $?
39
40test_start 'severity.filter'
41cat > $tempfile << .
42FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
43ERROR [example] LOG_READING_LOCAL_FILE reading local message file dummy/file
44FATAL [example.beta] LOG_BAD_SEVERITY unrecognized log severity: beta_fatal
45ERROR [example.beta] LOG_BAD_DESTINATION unrecognized log destination: beta_error
46.
47./logger_example -c stdout -s error | \
48    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
49    cut -d' ' -f3- | diff $tempfile -
50test_finish $?
51
52test_start 'severity.debug-level'
53cat > $tempfile << .
54FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
55ERROR [example] LOG_READING_LOCAL_FILE reading local message file dummy/file
56WARN  [example] LOG_BAD_STREAM bad log console output stream: example
57WARN  [example.alpha] LOG_READ_ERROR error reading from message file a.txt: dummy reason
58INFO  [example.alpha] LOG_INPUT_OPEN_FAIL unable to open message file example.msg for input: dummy reason
59DEBUG [example] LOG_READING_LOCAL_FILE reading local message file example/0
60DEBUG [example] LOG_READING_LOCAL_FILE reading local message file example/24
61DEBUG [example] LOG_READING_LOCAL_FILE reading local message file example/25
62FATAL [example.beta] LOG_BAD_SEVERITY unrecognized log severity: beta_fatal
63ERROR [example.beta] LOG_BAD_DESTINATION unrecognized log destination: beta_error
64WARN  [example.beta] LOG_BAD_STREAM bad log console output stream: beta_warn
65INFO  [example.beta] LOG_READ_ERROR error reading from message file beta: info
66DEBUG [example.beta] LOG_BAD_SEVERITY unrecognized log severity: beta/25
67.
68./logger_example -c stdout -s debug -d 25 | \
69    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
70    cut -d' ' -f3- | diff $tempfile -
71test_finish $?
72
73# Tidy up
74rm -f $tempfile
75