summaryrefslogtreecommitdiffstats
path: root/src/lib/log/tests/severity_test.sh.in
blob: 02376f8a1e9cf39bbff77bba9b76e879679438b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh

# Copyright (C) 2011-2020 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Checks that the logger will limit the output of messages less severe than
# the severity/debug setting.

# Exit with error if commands exit with non-zero and if undefined variables are
# used.
set -eu

# Include common test library.
# shellcheck disable=SC1091
# SC1091: Not following: ... was not specified as input (see shellcheck -x).
. "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"

tempfile="@abs_builddir@/severity_test_tempfile_$$"

test_start 'severity.default-parameters'
cat > $tempfile << .
FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
ERROR [example] LOG_READING_LOCAL_FILE reading local message file dummy/file
WARN  [example] LOG_BAD_STREAM bad log console output stream: example
WARN  [example.alpha] LOG_READ_ERROR error reading from message file a.txt: dummy reason
INFO  [example.alpha] LOG_INPUT_OPEN_FAIL unable to open message file example.msg for input: dummy reason
FATAL [example.beta] LOG_BAD_SEVERITY unrecognized log severity: beta_fatal
ERROR [example.beta] LOG_BAD_DESTINATION unrecognized log destination: beta_error
WARN  [example.beta] LOG_BAD_STREAM bad log console output stream: beta_warn
INFO  [example.beta] LOG_READ_ERROR error reading from message file beta: info
.
./logger_example -c stdout | \
    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
    cut -d' ' -f3- | diff $tempfile -
test_finish $?

test_start 'severity.filter'
cat > $tempfile << .
FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
ERROR [example] LOG_READING_LOCAL_FILE reading local message file dummy/file
FATAL [example.beta] LOG_BAD_SEVERITY unrecognized log severity: beta_fatal
ERROR [example.beta] LOG_BAD_DESTINATION unrecognized log destination: beta_error
.
./logger_example -c stdout -s error | \
    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
    cut -d' ' -f3- | diff $tempfile -
test_finish $?

test_start 'severity.debug-level'
cat > $tempfile << .
FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
ERROR [example] LOG_READING_LOCAL_FILE reading local message file dummy/file
WARN  [example] LOG_BAD_STREAM bad log console output stream: example
WARN  [example.alpha] LOG_READ_ERROR error reading from message file a.txt: dummy reason
INFO  [example.alpha] LOG_INPUT_OPEN_FAIL unable to open message file example.msg for input: dummy reason
DEBUG [example] LOG_READING_LOCAL_FILE reading local message file example/0
DEBUG [example] LOG_READING_LOCAL_FILE reading local message file example/24
DEBUG [example] LOG_READING_LOCAL_FILE reading local message file example/25
FATAL [example.beta] LOG_BAD_SEVERITY unrecognized log severity: beta_fatal
ERROR [example.beta] LOG_BAD_DESTINATION unrecognized log destination: beta_error
WARN  [example.beta] LOG_BAD_STREAM bad log console output stream: beta_warn
INFO  [example.beta] LOG_READ_ERROR error reading from message file beta: info
DEBUG [example.beta] LOG_BAD_SEVERITY unrecognized log severity: beta/25
.
./logger_example -c stdout -s debug -d 25 | \
    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
    cut -d' ' -f3- | diff $tempfile -
test_finish $?

# Tidy up
rm -f $tempfile