diff options
author | Ruediger Meier | 2015-04-09 17:12:34 +0200 |
---|---|---|
committer | Ruediger Meier | 2015-04-13 13:24:34 +0200 |
commit | c9813f2cbe1f4c92f5ebecdd5a22d9ff94affe82 (patch) | |
tree | ca6d91e03e946e9620cd857114fb8cf61ef06999 /tests/functions.sh | |
parent | tests: simplify common logger options (diff) | |
download | kernel-qcow2-util-linux-c9813f2cbe1f4c92f5ebecdd5a22d9ff94affe82.tar.gz kernel-qcow2-util-linux-c9813f2cbe1f4c92f5ebecdd5a22d9ff94affe82.tar.xz kernel-qcow2-util-linux-c9813f2cbe1f4c92f5ebecdd5a22d9ff94affe82.zip |
tests: logger with socat device
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'tests/functions.sh')
-rw-r--r-- | tests/functions.sh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/functions.sh b/tests/functions.sh index 55b92738c..44e087cdb 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -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 +} |