]> git.ipfire.org Git - thirdparty/util-linux.git/blob - tests/ts/logger/errors
tests: split stdout and stderr
[thirdparty/util-linux.git] / tests / ts / logger / errors
1 #!/bin/bash
2
3 #
4 # Copyright (C) 2015 Sami Kerola <kerolasa@iki.fi>
5 #
6 # This file is part of util-linux.
7 #
8 # This file is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This file is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18
19 TS_TOPDIR="${0%/*}/../.."
20 TS_DESC="errors"
21
22 . $TS_TOPDIR/functions.sh
23
24 ts_init "$*"
25
26 ts_check_test_command "$TS_HELPER_LOGGER"
27
28 export TZ="GMT"
29 export LOGGER_TEST_TIMEOFDAY="1234567890.123456"
30 export LOGGER_TEST_HOSTNAME="test-hostname"
31 export LOGGER_TEST_GETPID="98765"
32
33 DEVLOG="$(mktemp "/tmp/ultest-$TS_COMPONENT-$TS_TESTNAME-XXXXXX")" \
34 || ts_die "mktemp failed"
35 SOCKIN="${TS_OUTDIR}/${TS_TESTNAME}_socketin"
36 ts_init_socket_to_file $DEVLOG $SOCKIN
37 SOCAT_PID="$!"
38
39 function logger_fun {
40 # logger without --no-act to write all data to the socket
41 echo "socket data, ${TS_SUBNAME}:" |socat -u - UNIX-CONNECT:$DEVLOG
42 $TS_HELPER_LOGGER -u $DEVLOG --stderr "$@" >> $TS_OUTPUT 2>> $TS_ERRLOG
43 echo "ret: $?" >> "$TS_OUTPUT"
44 echo |socat -u - UNIX-CONNECT:$DEVLOG
45 }
46
47 function logger_printf {
48 # logger without --no-act to write all data to the socket
49 local fmt="$1"
50 shift
51 echo "socket data, ${TS_SUBNAME}:" |socat -u - UNIX-CONNECT:$DEVLOG
52 printf "$fmt" | $TS_HELPER_LOGGER -u $DEVLOG --stderr "$@" >> $TS_OUTPUT 2>> $TS_ERRLOG
53 echo "ret: $?" >> "$TS_OUTPUT"
54 echo |socat -u - UNIX-CONNECT:$DEVLOG
55 }
56
57 ts_init_subtest "kern_priority"
58 logger_fun -t "prio" -p kern.emerg "message"
59 ts_finalize_subtest
60
61 ts_init_subtest "kern_priority_numeric"
62 logger_fun -t "prio" -p 0 "message"
63 ts_finalize_subtest
64
65 ts_init_subtest "invalid_prio"
66 logger_fun -t "prio" -p 8 "message"
67 ts_finalize_subtest
68
69 # should truncate
70 ts_init_subtest "rfc5424_exceed_size"
71 logger_fun -t "rfc5424_exceed_size" --rfc5424 --size 3 "abcd"
72 ts_finalize_subtest
73
74 ts_init_subtest "id_with_space"
75 logger_fun -t "id_with_space" --id="A B" "message"
76 logger_fun -t "rfc5424_id_with_space" --rfc5424 --id="A B" "message"
77 logger_fun -t "id_with_space" --id="1 23" "message"
78 logger_fun -t "id_with_leading space" --id=" 123" "message"
79 logger_fun -t "id_with_trailing space" --id="123 " "message"
80
81 ts_finalize_subtest
82
83 # should not fail
84 ts_init_subtest "tag_with_space"
85 logger_fun -t "A B" "tag_with_space"
86 logger_fun -t "A B" --rfc5424 "tag_with_space_rfc5424"
87 ts_finalize_subtest
88
89 ts_init_subtest "tcp"
90 logger_fun --tcp -t "tcp" "message"
91 ts_finalize_subtest
92
93 ts_init_subtest "multi-line"
94 logger_printf "AAA\nBBB\nCCC\n" -t "multi"
95 ts_finalize_subtest
96
97 ts_init_subtest "rfc5424_msgid_with_space"
98 logger_fun -t "rfc5424_msgid_with_space" --rfc5424 --msgid="A B" "message"
99 ts_finalize_subtest
100
101 ts_init_subtest "invalid_socket"
102 logger_fun -u /bad/boy -t "invalid_socket" "message"
103 ts_finalize_subtest
104
105 ts_init_subtest "check_socket"
106 ts_log "Check written socket data of all subtests."
107 sleep 1
108 kill $SOCAT_PID
109 wait $SOCAT_PID &>/dev/null
110 cat "$SOCKIN" >> $TS_OUTPUT 2>> $TS_ERRLOG
111 rm -f "$DEVLOG" "$SOCKIN"
112 ts_finalize_subtest
113
114 ts_finalize