]> git.ipfire.org Git - thirdparty/util-linux.git/blob - tests/functions.sh
tests: ts_fdisk_clean(), remove optimal iosize
[thirdparty/util-linux.git] / tests / functions.sh
1 #
2 # Copyright (C) 2007 Karel Zak <kzak@redhat.com>
3 #
4 # This file is part of util-linux.
5 #
6 # This file is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This file is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16
17
18 function ts_abspath {
19 cd $1
20 pwd
21 }
22
23 function ts_canonicalize {
24 P="$1"
25 C=$(readlink -f $P)
26
27 if [ -n "$C" ]; then
28 echo "$C"
29 else
30 echo "$P"
31 fi
32 }
33
34 function ts_cd {
35 if [ $# -eq 0 ]; then
36 ts_failed "ul_cd: not enough arguments"
37 fi
38 DEST=$(readlink -f "$1" 2>/dev/null)
39 if [ "x$DEST" = "x" ] || [ ! -d "$DEST" ]; then
40 ts_failed "ul_cd: $1: no such directory"
41 fi
42 cd "$DEST" 2>/dev/null || ts_failed "ul_cd: $1: cannot change directory"
43 if [ "$PWD" != "$DEST" ]; then
44 ts_failed "ul_cd: $PWD is not $DEST"
45 fi
46 }
47
48 function ts_report {
49 if [ "$TS_PARALLEL" == "yes" ]; then
50 echo "$TS_TITLE $1"
51 else
52 echo "$1"
53 fi
54 }
55
56 function ts_check_test_command {
57 if [ ! -x "$1" ]; then
58 ts_skip "${1##*/} not found"
59 fi
60 }
61
62 function ts_check_prog {
63 local cmd=$1
64 type "$cmd" >/dev/null 2>&1 || ts_skip "missing in PATH: $cmd"
65 }
66
67 function ts_check_losetup {
68 local tmp
69 ts_check_test_command "$TS_CMD_LOSETUP"
70
71 if [ "$TS_SKIP_LOOPDEVS" = "yes" ]; then
72 ts_skip "loop-device tests disabled"
73 fi
74
75 # assuming that losetup -f works ... to be checked somewhere else
76 tmp=$($TS_CMD_LOSETUP -f 2>/dev/null)
77 if test -b "$tmp"; then
78 return 0
79 fi
80 ts_skip "no loop-device support"
81 }
82
83 function ts_skip_subtest {
84 ts_report " SKIPPED ($1)"
85 }
86
87 function ts_skip {
88 ts_skip_subtest "$1"
89
90 ts_cleanup_on_exit
91 exit 0
92 }
93
94 function ts_skip_nonroot {
95 if [ $UID -ne 0 ]; then
96 ts_skip "no root permissions"
97 fi
98 }
99
100 function ts_failed_subtest {
101 local msg="FAILED"
102 local ret=1
103 if [ "$TS_KNOWN_FAIL" = "yes" ]; then
104 msg="KNOWN FAILED"
105 ret=0
106 fi
107
108 if [ x"$1" == x"" ]; then
109 ts_report " $msg ($TS_NS)"
110 else
111 ts_report " $msg ($1)"
112 fi
113
114 return $ret
115 }
116
117 function ts_failed {
118 ts_failed_subtest "$1"
119 exit $?
120 }
121
122 function ts_ok_subtest {
123 if [ x"$1" == x"" ]; then
124 ts_report " OK"
125 else
126 ts_report " OK ($1)"
127 fi
128 }
129
130 function ts_ok {
131 ts_ok_subtest "$1"
132 exit 0
133 }
134
135 function ts_log {
136 echo "$1" >> $TS_OUTPUT
137 [ "$TS_VERBOSE" == "yes" ] && echo "$1"
138 }
139
140 function ts_has_option {
141 NAME="$1"
142 ALL="$2"
143
144 # user may set options by env for a single test or whole component
145 # e.g. TS_OPT_ipcs_limits2_fake="yes" or TS_OPT_ipcs_fake="yes"
146 local v_test=${TS_TESTNAME//[-.]/_}
147 local v_comp=${TS_COMPONENT//[-.]/_}
148 local v_name=${NAME//[-.]/_}
149 eval local env_opt_test=\$TS_OPT_${v_comp}_${v_test}_${v_name}
150 eval local env_opt_comp=\$TS_OPT_${v_comp}_${v_name}
151 if [ "$env_opt_test" = "yes" \
152 -o "$env_opt_comp" = "yes" -a "$env_opt_test" != "no" ]; then
153 echo "yes"
154 return
155 elif [ "$env_opt_test" = "no" \
156 -o "$env_opt_comp" = "no" -a "$env_opt_test" != "yes" ]; then
157 return
158 fi
159
160 # or just check the global command line options
161 echo -n $ALL | sed 's/ //g' | awk 'BEGIN { FS="="; RS="--" } /('$NAME'$|'$NAME'=)/ { print "yes" }'
162 }
163
164 function ts_option_argument {
165 NAME="$1"
166 ALL="$2"
167 echo -n $ALL | sed 's/ //g' | awk 'BEGIN { FS="="; RS="--" } /'$NAME'=/ { print $2 }'
168 }
169
170 function ts_init_core_env {
171 TS_NS="$TS_COMPONENT/$TS_TESTNAME"
172 TS_OUTPUT="$TS_OUTDIR/$TS_TESTNAME"
173 TS_VGDUMP="$TS_OUTDIR/$TS_TESTNAME.vgdump"
174 TS_DIFF="$TS_DIFFDIR/$TS_TESTNAME"
175 TS_EXPECTED="$TS_TOPDIR/expected/$TS_NS"
176 TS_MOUNTPOINT="$TS_OUTDIR/${TS_TESTNAME}-mnt"
177 }
178
179 function ts_init_core_subtest_env {
180 TS_NS="$TS_COMPONENT/$TS_TESTNAME-$TS_SUBNAME"
181 TS_OUTPUT="$TS_OUTDIR/$TS_TESTNAME-$TS_SUBNAME"
182 TS_VGDUMP="$TS_OUTDIR/$TS_TESTNAME-$TS_SUBNAME.vgdump"
183 TS_DIFF="$TS_DIFFDIR/$TS_TESTNAME-$TS_SUBNAME"
184 TS_EXPECTED="$TS_TOPDIR/expected/$TS_NS"
185 TS_MOUNTPOINT="$TS_OUTDIR/${TS_TESTNAME}-${TS_SUBNAME}-mnt"
186
187 rm -f $TS_OUTPUT $TS_VGDUMP
188 [ -d "$TS_OUTDIR" ] || mkdir -p "$TS_OUTDIR"
189
190 touch $TS_OUTPUT
191 [ -n "$TS_VALGRIND_CMD" ] && touch $TS_VGDUMP
192 }
193
194 function ts_init_env {
195 local mydir=$(ts_abspath ${0%/*})
196 local tmp
197
198 LANG="POSIX"
199 LANGUAGE="POSIX"
200 LC_ALL="POSIX"
201 CHARSET="UTF-8"
202
203 export LANG LANGUAGE LC_ALL CHARSET
204
205 mydir=$(ts_canonicalize "$mydir")
206
207 # automake directories
208 top_srcdir=$(ts_option_argument "srcdir" "$*")
209 top_builddir=$(ts_option_argument "builddir" "$*")
210
211 # where is this script
212 TS_TOPDIR=$(ts_abspath $mydir/../../)
213
214 # default
215 if [ -z "$top_srcdir" ]; then
216 top_srcdir="$TS_TOPDIR/.."
217 fi
218 if [ -z "$top_builddir" ]; then
219 top_builddir="$TS_TOPDIR/.."
220 fi
221
222 top_srcdir=$(ts_abspath $top_srcdir)
223 top_builddir=$(ts_abspath $top_builddir)
224
225 # some ul commands search other ul commands in $PATH
226 export PATH="$top_builddir:$PATH"
227
228 TS_SCRIPT="$mydir/$(basename $0)"
229 TS_SUBDIR=$(dirname $TS_SCRIPT)
230 TS_TESTNAME=$(basename $TS_SCRIPT)
231 TS_COMPONENT=$(basename $TS_SUBDIR)
232 TS_DESC=${TS_DESC:-$TS_TESTNAME}
233
234 TS_NSUBTESTS=0
235 TS_NSUBFAILED=0
236
237 TS_SELF="$TS_SUBDIR"
238
239 TS_OUTDIR="$top_builddir/tests/output/$TS_COMPONENT"
240 TS_DIFFDIR="$top_builddir/tests/diff/$TS_COMPONENT"
241
242 ts_init_core_env
243
244 TS_VERBOSE=$(ts_has_option "verbose" "$*")
245 TS_PARALLEL=$(ts_has_option "parallel" "$*")
246 TS_KNOWN_FAIL=$(ts_has_option "known-fail" "$*")
247 TS_SKIP_LOOPDEVS=$(ts_has_option "skip-loopdevs" "$*")
248
249 tmp=$( ts_has_option "memcheck" "$*")
250 if [ "$tmp" == "yes" -a -f /usr/bin/valgrind ]; then
251 TS_VALGRIND_CMD="/usr/bin/valgrind"
252 fi
253
254 BLKID_FILE="$TS_OUTDIR/${TS_TESTNAME}.blkidtab"
255
256 declare -a TS_SUID_PROGS
257 declare -a TS_SUID_USER
258 declare -a TS_SUID_GROUP
259 declare -a TS_LOOP_DEVS
260
261 if [ -f $TS_TOPDIR/commands.sh ]; then
262 . $TS_TOPDIR/commands.sh
263 fi
264
265 export BLKID_FILE
266
267 rm -f $TS_OUTPUT $TS_VGDUMP
268 [ -d "$TS_OUTDIR" ] || mkdir -p "$TS_OUTDIR"
269
270 touch $TS_OUTPUT
271 [ -n "$TS_VALGRIND_CMD" ] && touch $TS_VGDUMP
272
273 if [ "$TS_VERBOSE" == "yes" ]; then
274 echo
275 echo " script: $TS_SCRIPT"
276 echo " sub dir: $TS_SUBDIR"
277 echo " top dir: $TS_TOPDIR"
278 echo " self: $TS_SELF"
279 echo " test name: $TS_TESTNAME"
280 echo " test desc: $TS_DESC"
281 echo " component: $TS_COMPONENT"
282 echo " namespace: $TS_NS"
283 echo " verbose: $TS_VERBOSE"
284 echo " output: $TS_OUTPUT"
285 echo " valgrind: $TS_VGDUMP"
286 echo " expected: $TS_EXPECTED"
287 echo " mountpoint: $TS_MOUNTPOINT"
288 echo
289 fi
290 }
291
292 function ts_init_subtest {
293
294 TS_SUBNAME="$1"
295
296 ts_init_core_subtest_env
297
298 [ $TS_NSUBTESTS -eq 0 ] && echo
299 TS_NSUBTESTS=$(( $TS_NSUBTESTS + 1 ))
300
301 if [ "$TS_PARALLEL" == "yes" ]; then
302 TS_TITLE=$(printf "%13s: %-30s ...\n%16s: %-27s ..." "$TS_COMPONENT" "$TS_DESC" "" "$TS_SUBNAME")
303 else
304 TS_TITLE=$(printf "%16s: %-27s ..." "" "$TS_SUBNAME")
305 echo -n "$TS_TITLE"
306 fi
307 }
308
309 function ts_init {
310 ts_init_env "$*"
311
312 local is_fake=$( ts_has_option "fake" "$*")
313 local is_force=$( ts_has_option "force" "$*")
314
315 if [ "$TS_PARALLEL" == "yes" ]; then
316 TS_TITLE=$(printf "%13s: %-30s ..." "$TS_COMPONENT" "$TS_DESC")
317 else
318 TS_TITLE=$(printf "%13s: %-30s ..." "$TS_COMPONENT" "$TS_DESC")
319 echo -n "$TS_TITLE"
320 fi
321
322 [ "$is_fake" == "yes" ] && ts_skip "fake mode"
323 [ "$TS_OPTIONAL" == "yes" -a "$is_force" != "yes" ] && ts_skip "optional"
324 }
325
326 function ts_init_suid {
327 PROG="$1"
328 ct=${#TS_SUID_PROGS[*]}
329
330 # Save info about original setting
331 TS_SUID_PROGS[$ct]=$PROG
332 TS_SUID_USER[$ct]=$(stat --printf="%U" $PROG)
333 TS_SUID_GROUP[$ct]=$(stat --printf="%G" $PROG)
334
335 chown root.root $PROG &> /dev/null
336 chmod u+s $PROG &> /dev/null
337 }
338
339 function ts_init_py {
340 LIBNAME="$1"
341
342 [ -f "$top_builddir/py${LIBNAME}.la" ] || ts_skip "py${LIBNAME} not compiled"
343
344 export LD_LIBRARY_PATH="$top_builddir/.libs:$LD_LIBRARY_PATH"
345 export PYTHONPATH="$top_builddir/$LIBNAME/python:$top_builddir/.libs:$PYTHONPATH"
346
347 export PYTHON_VERSION=$(awk '/^PYTHON_VERSION/ { print $3 }' $top_builddir/Makefile)
348 export PYTHON_MAJOR_VERSION=$(echo $PYTHON_VERSION | sed 's/\..*//')
349
350 export PYTHON="python${PYTHON_MAJOR_VERSION}"
351 }
352
353 function ts_valgrind {
354 if [ -z "$TS_VALGRIND_CMD" ]; then
355 $*
356 else
357 $TS_VALGRIND_CMD --tool=memcheck --leak-check=full \
358 --leak-resolution=high --num-callers=20 \
359 --log-file="$TS_VGDUMP" $*
360 fi
361 }
362
363 function ts_gen_diff {
364 local res=0
365
366 if [ -s "$TS_OUTPUT" ]; then
367
368 # remove libtool lt- prefixes
369 sed --in-place 's/^lt\-\(.*\: \)/\1/g' $TS_OUTPUT
370
371 [ -d "$TS_DIFFDIR" ] || mkdir -p "$TS_DIFFDIR"
372 diff -u $TS_EXPECTED $TS_OUTPUT > $TS_DIFF
373
374 if [ -s $TS_DIFF ]; then
375 res=1
376 else
377 rm -f $TS_DIFF;
378 fi
379 else
380 res=1
381 fi
382 return $res
383 }
384
385 function tt_gen_mem_report {
386 [ -z "$TS_VALGRIND_CMD" ] && echo "$1"
387
388 grep -q -E 'ERROR SUMMARY: [1-9]' $TS_VGDUMP &> /dev/null
389 if [ $? -eq 0 ]; then
390 echo "mem-error detected!"
391 fi
392 }
393
394 function ts_finalize_subtest {
395 local res=0
396
397 if [ -s "$TS_EXPECTED" ]; then
398 ts_gen_diff
399 if [ $? -eq 1 ]; then
400 ts_failed_subtest "$1"
401 res=1
402 else
403 ts_ok_subtest "$(tt_gen_mem_report "$1")"
404 fi
405 else
406 ts_skip_subtest "output undefined"
407 fi
408
409 [ $res -ne 0 ] && TS_NSUBFAILED=$(( $TS_NSUBFAILED + 1 ))
410
411 # reset environment back to parental test
412 ts_init_core_env
413
414 return $res
415 }
416
417 function ts_finalize {
418 ts_cleanup_on_exit
419
420 if [ $TS_NSUBTESTS -ne 0 ]; then
421 printf "%11s..."
422 if [ $TS_NSUBFAILED -ne 0 ]; then
423 ts_failed "$TS_NSUBFAILED from $TS_NSUBTESTS sub-tests"
424 else
425 ts_ok "all $TS_NSUBTESTS sub-tests PASSED"
426 fi
427 fi
428
429 if [ -s $TS_EXPECTED ]; then
430 ts_gen_diff
431 if [ $? -eq 1 ]; then
432 ts_failed "$1"
433 fi
434 ts_ok "$1"
435 fi
436
437 ts_skip "output undefined"
438 }
439
440 function ts_die {
441 ts_log "$1"
442 ts_finalize
443 }
444
445 function ts_cleanup_on_exit {
446
447 for idx in $(seq 0 $((${#TS_SUID_PROGS[*]} - 1))); do
448 PROG=${TS_SUID_PROGS[$idx]}
449 chmod a-s $PROG &> /dev/null
450 chown ${TS_SUID_USER[$idx]}.${TS_SUID_GROUP[$idx]} $PROG &> /dev/null
451 done
452
453 for dev in "${TS_LOOP_DEVS[@]}"; do
454 ts_device_deinit "$dev"
455 done
456 unset TS_LOOP_DEVS
457 }
458
459 function ts_image_md5sum {
460 local img=${1:-"$TS_OUTDIR/${TS_TESTNAME}.img"}
461 echo $(md5sum "$img" | awk '{printf $1}') $(basename "$img")
462 }
463
464 function ts_image_init {
465 local mib=${1:-"5"} # size in MiBs
466 local img=${2:-"$TS_OUTDIR/${TS_TESTNAME}.img"}
467
468 rm -f $img
469 truncate -s "${mib}M" "$img"
470 echo "$img"
471 return 0
472 }
473
474 function ts_register_loop_device {
475 local ct=${#TS_LOOP_DEVS[*]}
476 TS_LOOP_DEVS[$ct]=$1
477 }
478
479 function ts_device_init {
480 local img
481 local dev
482
483 img=$(ts_image_init $1 $2)
484 dev=$($TS_CMD_LOSETUP --show -f "$img")
485 if [ "$?" != "0" -o "$dev" = "" ]; then
486 ts_die "Cannot init device"
487 fi
488
489 ts_register_loop_device "$dev"
490 TS_LODEV=$dev
491 }
492
493 # call from ts_cleanup_on_exit() only because of TS_LOOP_DEVS maintenance
494 function ts_device_deinit {
495 local DEV="$1"
496
497 if [ -b "$DEV" ]; then
498 $TS_CMD_UMOUNT "$DEV" &> /dev/null
499 $TS_CMD_LOSETUP -d "$DEV" &> /dev/null
500 fi
501 }
502
503 function ts_uuid_by_devname {
504 echo $($TS_CMD_BLKID -p -s UUID -o value $1)
505 }
506
507 function ts_label_by_devname {
508 echo $($TS_CMD_BLKID -p -s LABEL -o value $1)
509 }
510
511 function ts_fstype_by_devname {
512 echo $($TS_CMD_BLKID -p -s TYPE -o value $1)
513 }
514
515 function ts_device_has {
516 local TAG="$1"
517 local VAL="$2"
518 local DEV="$3"
519 local vl=""
520
521 case $TAG in
522 "TYPE") vl=$(ts_fstype_by_devname $DEV);;
523 "LABEL") vl=$(ts_label_by_devname $DEV);;
524 "UUID") vl=$(ts_uuid_by_devname $DEV);;
525 *) return 1;;
526 esac
527
528 if [ "$vl" == "$VAL" ]; then
529 return 0
530 fi
531 return 1
532 }
533
534 function ts_device_has_uuid {
535 ts_uuid_by_devname "$1" | egrep -q '^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$'
536 return $?
537 }
538
539 function ts_mount {
540 local out
541 local result
542 local msg
543 local fs
544 local fs_exp=$1
545 shift
546
547 out=$($TS_CMD_MOUNT "$@" 2>&1)
548 result=$?
549 echo -n "$out" >> $TS_OUTPUT
550
551 if [ $result != 0 ] \
552 && msg=$(echo "$out" | grep -m1 "unknown filesystem type")
553 then
554 # skip only if reported fs correctly and if it's not available
555 fs=$(echo "$msg" | sed -n "s/.*type '\(.*\)'$/\1/p")
556 [ "$fs" = "fs_exp" ] \
557 && grep -qe "[[:space:]]${fs}$" /proc/filesystems &>/dev/null \
558 || ts_skip "$msg"
559 fi
560 return $result
561 }
562
563 function ts_is_mounted {
564 local DEV=$(ts_canonicalize "$1")
565
566 grep -q $DEV /proc/mounts && return 0
567
568 if [ "${DEV#/dev/loop/}" != "$DEV" ]; then
569 grep -q "/dev/loop${DEV#/dev/loop/}" /proc/mounts && return 0
570 fi
571 return 1
572 }
573
574 function ts_fstab_open {
575 echo "# <!-- util-linux test entry" >> /etc/fstab
576 }
577
578 function ts_fstab_close {
579 echo "# -->" >> /etc/fstab
580 }
581
582 function ts_fstab_addline {
583 local SPEC="$1"
584 local MNT=${2:-"$TS_MOUNTPOINT"}
585 local FS=${3:-"auto"}
586 local OPT=${4:-"defaults"}
587
588 echo "$SPEC $MNT $FS $OPT 0 0" >> /etc/fstab
589 }
590
591 function ts_fstab_add {
592 ts_fstab_open
593 ts_fstab_addline $*
594 ts_fstab_close
595 }
596
597 function ts_fstab_clean {
598 sed --in-place "
599 /# <!-- util-linux/!b
600 :a
601 /# -->/!{
602 N
603 ba
604 }
605 s/# <!-- util-linux.*-->//;
606 /^$/d" /etc/fstab
607 }
608
609 function ts_fdisk_clean {
610 local DEVNAME=$1
611
612 # remove non comparable parts of fdisk output
613 if [ -n "${DEVNAME}" ]; then
614 sed -i -e "s@${DEVNAME}@<removed>@;" $TS_OUTPUT
615 fi
616
617 sed -i \
618 -e 's/Disk identifier:.*/Disk identifier: <removed>/' \
619 -e 's/Created a new.*/Created a new <removed>./' \
620 -e 's/^Device[[:blank:]]*Start/Device Start/' \
621 -e 's/^Device[[:blank:]]*Boot/Device Boot/' \
622 -e 's/Welcome to fdisk.*/Welcome to fdisk <removed>./' \
623 -e 's/typescript file.*/typescript file <removed>./' \
624 -e 's@^\(I/O size (minimum/op.* bytes /\) [1-9][0-9]* @\1 <removed> @' \
625 $TS_OUTPUT
626 }
627
628 function ts_scsi_debug_init {
629 local devname
630 TS_DEVICE="none"
631
632 # dry run is not really reliable, real modprobe may still fail
633 modprobe --dry-run --quiet scsi_debug &>/dev/null \
634 || ts_skip "missing scsi_debug module (dry-run)"
635
636 # skip if still in use or removal of modules not supported at all
637 modprobe -r scsi_debug &>/dev/null \
638 || ts_skip "cannot remove scsi_debug module (rmmod)"
639
640 modprobe -b scsi_debug "$@" &>/dev/null \
641 || ts_skip "cannot load scsi_debug module (modprobe)"
642
643 # it might be still not loaded, modprobe.conf or whatever
644 lsmod | grep -q "^scsi_debug " \
645 || ts_skip "scsi_debug module not loaded (lsmod)"
646
647 udevadm settle
648
649 devname=$(grep --with-filename scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}')
650 [ "x${devname}" == "x" ] && ts_die "cannot find scsi_debug device"
651
652 TS_DEVICE="/dev/${devname}"
653 }
654
655 function ts_resolve_host {
656 local host="$1"
657 local tmp
658
659 # currently we just resolve default records (might be "A", ipv4 only)
660 if type "dig" >/dev/null 2>&1; then
661 tmp=$(dig "$host" +short 2>/dev/null) || return 1
662 elif type "nslookup" >/dev/null 2>&1; then
663 tmp=$(nslookup "$host" 2>/dev/null) || return 1
664 tmp=$(echo "$tmp"| grep -A1 "^Name:"| grep "^Address:"| cut -d" " -f2)
665 elif type "host" >/dev/null 2>&1; then
666 tmp=$(host "$host" 2>/dev/null) || return 1
667 tmp=$(echo "$tmp" | grep " has address " | cut -d " " -f4)
668 elif type "getent" >/dev/null 2>&1; then
669 tmp=$(getent ahosts "$host" 2>/dev/null) || return 1
670 tmp=$(echo "$tmp" | cut -d " " -f 1 | sort -u)
671 fi
672
673 # we return 1 if tmp is empty
674 test -n "$tmp" || return 1
675 echo "$tmp" | sort -R | head -n 1
676 }
677
678 # listen to unix socket (background socat)
679 function ts_init_socket_to_file {
680 local socket=$1
681 local outfile=$2
682 local pid="0"
683
684 ts_check_prog "socat"
685 rm -f "$socket" "$outfile"
686
687 socat -u UNIX-LISTEN:$socket,fork,max-children=1,backlog=128 \
688 STDOUT > "$outfile" &
689 pid=$!
690
691 # check for running background process
692 if [ "$pid" -le "0" ] || ! kill -s 0 "$pid"; then
693 ts_skip "unable to run socat"
694 fi
695 # wait for the socket listener
696 if ! socat -u /dev/null UNIX-CONNECT:$socket,retry=30,interval=0.1; then
697 kill -9 "$pid"
698 ts_skip "timeout waiting for socket"
699 fi
700 # check socket again
701 if ! socat -u /dev/null UNIX-CONNECT:$socket; then
702 kill -9 "$pid"
703 ts_skip "socket stopped listening"
704 fi
705 }