]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: logger with socat device
authorRuediger Meier <ruediger.meier@ga-group.nl>
Thu, 9 Apr 2015 15:12:34 +0000 (17:12 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 29 Apr 2015 10:32:43 +0000 (12:32 +0200)
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
tests/functions.sh
tests/ts/logger/errors
tests/ts/logger/formats
tests/ts/logger/options

index 55b92738c6bff56e8eaed8b4dd895001598ba6a3..44e087cdb474ec2b35b46a602f815ffe2d59dbd5 100644 (file)
@@ -652,3 +652,32 @@ function ts_resolve_host {
        test -n "$tmp" || return 1
        echo "$tmp" | sort -R | head -n 1
 }
+
+# listen to unix socket (background socat)
+function ts_init_socket_to_file {
+       local socket=$1
+       local outfile=$2
+       local pid="0"
+
+       ts_check_prog "socat"
+       rm -f "$socket" "$outfile"
+
+       socat -u UNIX-LISTEN:$socket,fork,max-children=1,backlog=128 \
+               STDOUT > "$outfile" &
+       pid=$!
+
+       # check for running background process
+       if [ "$pid" -le "0" ] || ! kill -s 0 "$pid"; then
+               ts_skip "unable to run socat"
+       fi
+       # wait for the socket listener
+       if ! socat -u /dev/null UNIX-CONNECT:$socket,retry=30,interval=0.1; then
+               kill -9 "$pid"
+               ts_skip "timeout waiting for socket"
+       fi
+       # check socket again
+       if ! socat -u /dev/null UNIX-CONNECT:$socket; then
+               kill -9 "$pid"
+               ts_skip "socket stopped listening"
+       fi
+}
index debce7eab3660e922ab27eb3273937ea1cc369c6..2dfb4109c2c4c98b506e5df5ccca0784d0753a12 100755 (executable)
@@ -30,8 +30,13 @@ export LOGGER_TEST_TIMEOFDAY="1234567890.123456"
 export LOGGER_TEST_HOSTNAME="test-hostname"
 export LOGGER_TEST_GETPID="98765"
 
+DEVLOG="${TS_OUTDIR}/${TS_TESTNAME}_devlog"
+SOCKIN="${TS_OUTDIR}/${TS_TESTNAME}_socketin"
+ts_init_socket_to_file $DEVLOG $SOCKIN
+SOCAT_PID="$!"
+
 function logger_fun {
-       $TS_HELPER_LOGGER -s --no-act "$@" >> "$TS_OUTPUT" 2>&1
+       $TS_HELPER_LOGGER -u $DEVLOG -s --no-act "$@" >> "$TS_OUTPUT" 2>&1
        echo "ret: $?" >> "$TS_OUTPUT"
 }
 
@@ -67,4 +72,7 @@ ts_init_subtest "rfc5424_msgid_with_space"
 logger_fun -t "rfc5424_msgid_with_space" --rfc5424 --msgid="A B" "message"
 ts_finalize_subtest
 
+sleep 1
+kill $SOCAT_PID
+
 ts_finalize
index d0e9d5c474f8a6172aa43d98a08054ac7b984e8c..203c4d6f67c3b2cb3998bba97689ad5c0c7d9cb0 100755 (executable)
@@ -30,8 +30,13 @@ export LOGGER_TEST_TIMEOFDAY="1234567890.123456"
 export LOGGER_TEST_HOSTNAME="test-hostname"
 export LOGGER_TEST_GETPID="98765"
 
+DEVLOG="${TS_OUTDIR}/${TS_TESTNAME}_devlog"
+SOCKIN="${TS_OUTDIR}/${TS_TESTNAME}_socketin"
+ts_init_socket_to_file $DEVLOG $SOCKIN
+SOCAT_PID="$!"
+
 function logger_fun {
-       $TS_HELPER_LOGGER -s --no-act "$@" >> "$TS_OUTPUT" 2>&1
+       $TS_HELPER_LOGGER -u $DEVLOG -s --no-act "$@" >> "$TS_OUTPUT" 2>&1
        echo "ret: $?" >> "$TS_OUTPUT"
 }
 
@@ -63,4 +68,7 @@ for facility in auth authpriv cron daemon ftp lpr mail news syslog user uucp loc
 done
 ts_finalize_subtest
 
+sleep 1
+kill $SOCAT_PID
+
 ts_finalize
index 6bd3236868ab77d29742c596da7506d2f1888351..c77c65565667ee725497b3aca154dd2017e68c8d 100755 (executable)
@@ -50,14 +50,26 @@ export LOGGER_TEST_TIMEOFDAY="1234567890.123456"
 export LOGGER_TEST_HOSTNAME="test-hostname"
 export LOGGER_TEST_GETPID="98765"
 
+DEVLOG="${TS_OUTDIR}/${TS_TESTNAME}_devlog"
+SOCKIN="${TS_OUTDIR}/${TS_TESTNAME}_socketin"
+ts_init_socket_to_file $DEVLOG $SOCKIN
+SOCAT_PID="$!"
+
+function logger_fun {
+       $TS_HELPER_LOGGER -u $DEVLOG --stderr --no-act "$@" >> "$TS_OUTPUT" 2>&1
+       echo "ret: $?" >> "$TS_OUTPUT"
+}
+
 for i in "${tests_array[@]}"; do
        name="${i%%:*}"
        options="${i##*:}"
 
        ts_init_subtest "$name"
-       $TS_HELPER_LOGGER --stderr --no-act -t "test_tag" $options > "$TS_OUTPUT" 2>&1
-       echo "ret: $?" >> "$TS_OUTPUT" 
+       logger_fun -t "test_tag" $options
        ts_finalize_subtest
 done
 
+sleep 1
+kill $SOCAT_PID
+
 ts_finalize