| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright (C) 2015 Sami Kerola <[email protected]> |
| 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 |
ts_check_prog "socat" |
| 28 |
ts_check_prog "mktemp" |
| 29 |
|
| 30 |
export TZ="GMT" |
| 31 |
export LOGGER_TEST_TIMEOFDAY="1234567890.123456" |
| 32 |
export LOGGER_TEST_HOSTNAME="test-hostname" |
| 33 |
export LOGGER_TEST_GETPID="98765" |
| 34 |
|
| 35 |
DEVLOG="$(mktemp "/tmp/ultest-$TS_COMPONENT-$TS_TESTNAME-XXXXXX")" \ |
| 36 |
|| ts_die "mktemp failed" |
| 37 |
SOCKIN="${TS_OUTDIR}/${TS_TESTNAME}_socketin" |
| 38 |
ts_init_socket_to_file $DEVLOG $SOCKIN |
| 39 |
SOCAT_PID="$!" |
| 40 |
|
| 41 |
function logger_fun { |
| 42 |
# logger without --no-act to write all data to the socket |
| 43 |
echo "socket data, ${TS_SUBNAME}:" |socat -u - UNIX-CONNECT:$DEVLOG |
| 44 |
$TS_HELPER_LOGGER --socket $DEVLOG --stderr "$@" >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 45 |
echo "ret: $?" >> "$TS_OUTPUT" |
| 46 |
echo |socat -u - UNIX-CONNECT:$DEVLOG |
| 47 |
} |
| 48 |
|
| 49 |
function logger_printf { |
| 50 |
# logger without --no-act to write all data to the socket |
| 51 |
local fmt="$1" |
| 52 |
shift |
| 53 |
echo "socket data, ${TS_SUBNAME}:" |socat -u - UNIX-CONNECT:$DEVLOG |
| 54 |
printf "$fmt" | $TS_HELPER_LOGGER --socket $DEVLOG --stderr "$@" >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 55 |
echo "ret: $?" >> "$TS_OUTPUT" |
| 56 |
echo |socat -u - UNIX-CONNECT:$DEVLOG |
| 57 |
} |
| 58 |
|
| 59 |
ts_init_subtest "kern_priority" |
| 60 |
logger_fun --tag "prio" --priority kern.emerg "message" |
| 61 |
ts_finalize_subtest |
| 62 |
|
| 63 |
ts_init_subtest "kern_priority_numeric" |
| 64 |
logger_fun --tag "prio" --priority 0 "message" |
| 65 |
ts_finalize_subtest |
| 66 |
|
| 67 |
ts_init_subtest "invalid_prio" |
| 68 |
logger_fun --tag "prio" --priority 8 "message" |
| 69 |
ts_finalize_subtest |
| 70 |
|
| 71 |
# should truncate |
| 72 |
ts_init_subtest "rfc5424_exceed_size" |
| 73 |
logger_fun --tag "rfc5424_exceed_size" --rfc5424 --size 3 "abcd" |
| 74 |
ts_finalize_subtest |
| 75 |
|
| 76 |
ts_init_subtest "id_with_space" |
| 77 |
logger_fun --tag "id_with_space" --id="A B" "message" |
| 78 |
logger_fun --tag "rfc5424_id_with_space" --rfc5424 --id="A B" "message" |
| 79 |
logger_fun --tag "id_with_space" --id="1 23" "message" |
| 80 |
logger_fun --tag "id_with_leading space" --id=" 123" "message" |
| 81 |
logger_fun --tag "id_with_trailing space" --id="123 " "message" |
| 82 |
|
| 83 |
ts_finalize_subtest |
| 84 |
|
| 85 |
# should not fail |
| 86 |
ts_init_subtest "tag_with_space" |
| 87 |
logger_fun --tag "A B" "tag_with_space" |
| 88 |
logger_fun --tag "A B" --rfc5424 "tag_with_space_rfc5424" |
| 89 |
ts_finalize_subtest |
| 90 |
|
| 91 |
ts_init_subtest "tcp" |
| 92 |
logger_fun --tcp --tag "tcp" "message" |
| 93 |
ts_finalize_subtest |
| 94 |
|
| 95 |
ts_init_subtest "multi-line" |
| 96 |
logger_printf "AAA\nBBB\nCCC\n" --tag "multi" |
| 97 |
ts_finalize_subtest |
| 98 |
|
| 99 |
ts_init_subtest "rfc5424_msgid_with_space" |
| 100 |
logger_fun --tag "rfc5424_msgid_with_space" --rfc5424 --msgid="A B" "message" |
| 101 |
ts_finalize_subtest |
| 102 |
|
| 103 |
ts_init_subtest "invalid_socket" |
| 104 |
logger_fun --socket /bad/boy --tag "invalid_socket" "message" |
| 105 |
ts_finalize_subtest |
| 106 |
|
| 107 |
ts_init_subtest "check_socket" |
| 108 |
ts_log "Check written socket data of all subtests." |
| 109 |
sleep 1 |
| 110 |
kill $SOCAT_PID |
| 111 |
wait $SOCAT_PID &>/dev/null |
| 112 |
cat "$SOCKIN" >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 113 |
rm -f "$DEVLOG" "$SOCKIN" |
| 114 |
ts_finalize_subtest |
| 115 |
|
| 116 |
ts_finalize |