########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2012 AT&T Intellectual Property #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# David Korn <dgk@research.att.com> #
# #
########################################################################
# test the behavior of co-processes
function err_exit
{
print -u2 -n "\t"
let Errors+=1
}
alias err_exit='err_exit $LINENO'
integer Errors=0
if [[ -d /cygdrive ]]
then err_exit cygwin detected - coprocess tests disabled - enable at the risk of wedging your system
fi
bintrue=$(whence -p true)
{
integer x=0
while ((x++ < 5))
do read -r
print -r "$1 $REPLY"
done
}
builtin cat
do
$cat |&
print -p "hello"
read -p line
exec 5>&p 6<&p
exec 5<&- 6<&-
wait $!
exec 3>&p
exec 4>&p
integer count
do case $i in
esac
done
read -p
set -- $REPLY
if [[ $1 != $2 ]]
fi
case $1 in
three) ;;
four) ;;
pipe) ;;
esac
done
$cat |&
!
sleep 10 |&
exec 5<&p 6>&p
exec 5<&- 6>&-
cop=$!
read -t 5 -p
read -t 5 -p
fi
exec 5<&p 6>&p
exec 5<&- 6>&-
spy=$!
fi
wait
{
} |&
while read -p -t 10 line
done
fi
wait $!
wait $!
unset N r e
integer N=5
e=12345
(
integer i
for ((i = 1; i <= N; i++))
do print $i |&
read -p r
print -n $r
wait $!
done
print
r=
(
integer i
for ((i = 1; i <= N; i++))
do print $i |&
sleep 0.01
r=$r$($cat <&p)
wait $!
done
print $r
(
$cat |&
sleep 0.01
exec 6>&p
exec 6>&-
sleep 2
$cat |&
pid=\$!
(
sleep 2
kill -\$sig \$\$
sleep 2
kill -\$sig \$\$
kill \$pid
sleep 2
kill \$\$
) &
while read -p || ((\$? > 256))
do :
done
++EOF++
fi
break
fi
done
sleep_pid=$!
$cat |&
pid=$!
exec 5<&p 6>&p
[[ $REPLY == "$exp" ]] || err_exit "REPLY from $cat coprocess failed -- expected '$exp', got '$REPLY'"
exec 6>&-
wait $pid
trap - TERM
[[ $sleep_pid ]] && kill $sleep_pid
sleep_pid=$!
$cat |&
pid=$!
kill $pid
trap - TERM
[[ $sleep_pid ]] && kill $sleep_pid
sleep_pid=$!
$cat |&
pid=$!
print -p foo
print -p bar
kill $pid
trap - TERM
[[ $sleep_pid ]] && kill $sleep_pid
done
COATTRIBUTES=\'label=make \'
# @(#)$Id: libcoshell (AT&T Research) 2008-04-28 $
_COSHELL_msgfd=5
{ { (eval \'function fun { trap \":\" 0; return 1; }; trap \"exit 0\" 0; fun; exit 1\') && PATH= print -u$_COSHELL_msgfd ksh; } || { times && echo bsh >&$_COSHELL_msgfd; } || { echo osh >&$_COSHELL_msgfd; }; } >/dev/null 2>&1' | $SHELL 5>&1)
[[ $got == $exp ]] || err_exit "coshell(3) identification sequence failed -- expected '$exp', got '$got'"
function cop
{
read
print ok
}
cop |&
pid=$!
then read -p got
else got='no coprocess'
fi
wait
cop |&
pid=$!
(
then read -p got
else got='no coprocess'
fi
)
wait
exp='no coprocess'
(
cop |&
)
then read -p got
fi
wait
(
cop |&
)
(
then read -p got
fi
[[ $got == $exp ]] || err_exit "subshell coprocess subshell query failed -- expected $exp, got '$got'"
wait
)
function mypipe
{
read; read
print -r -- "$REPLY"
}
mypipe |&
print -p "hello"
read -p
wait
function cop
{
read
print ok
}
cop |&
pid=$!
(
then read -p got
else got='no coprocess'
fi
)
wait
ls -l |&
pid=$!
wait $pid
x=$?
[[ $x == 0 ]] || err_exit "coprocess exitval should be 0, not $x"