1# This file is part of GNU pies testsuite. -*- autotest -*- 2# Copyright (C) 2016-2020 Sergey Poznyakoff 3# 4# GNU pies is free software; you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation; either version 3, or (at your option) 7# any later version. 8# 9# GNU pies is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with GNU pies. If not, see <http://www.gnu.org/licenses/>. 16AT_BANNER([inetd built-in services]) 17 18# IT_BUILTIN([SERVICE],[INPUT],[OUTPUT]) 19m4_define([IT_BUILTIN], 20[AT_SETUP([$1]) 21AT_KEYWORDS([inetd builtin internal $1]) 22AT_CHECK([ 23PIES_XFAIL_CHECK 24PIES_CONTROL_INIT 25AT_DATA([input], 26[$2]) 27m4_if([$1],[qotd],[AT_DATA([qotd],[$3])]) 28: ${PIES_TEST_INET_SOCKET:=unix://$PWD/in.sock} 29cat > pies.conf <<_EOT 30m4_if([$1],[qotd],[qotd-file "$PWD/qotd"; 31]) 32component in { 33 mode inetd; 34 socket "$PIES_TEST_INET_SOCKET"; 35 flags internal; 36 service $1; 37 stderr file "$PWD/log.err"; 38} 39component controller { 40 command "nt -i input -o output $PIES_TEST_INET_SOCKET"; 41 return-code * { 42 action disable; 43 exec "piesctl --url '$PIES_CTLSOCK' --no-netrc shutdown"; 44 } 45} 46_EOT 47set -e 48to 10 \ 49 pies --foreground --stderr \ 50 --config-file control.conf --config-file pies.conf --debug 1 2>errlog 51 52cat output m4_if([$1],[qotd],[| tr -d '\r']) 53cat log.err >&2 54], 55[0], 56[$3]) 57AT_CLEANUP 58]) 59 60# IT_SPECIAL(SERVICE,COMMAND) 61m4_define([IT_SPECIAL], 62[AT_SETUP([$1]) 63AT_KEYWORDS([inetd builtin internal $1]) 64AT_CHECK([ 65PIES_XFAIL_CHECK 66PIES_CONTROL_INIT 67: ${PIES_TEST_INET_SOCKET:=unix://$PWD/in.sock} 68cat > pies.conf <<_EOT 69component in { 70 mode inetd; 71 socket "$PIES_TEST_INET_SOCKET"; 72 flags internal; 73 service $1; 74 stderr file "$PWD/in.err"; 75} 76component controller { 77 command "$2 '$PIES_TEST_INET_SOCKET'"; 78 stderr file "$PWD/controller.err"; 79 return-code * { 80 action disable; 81 exec "echo \$PIES_STATUS > $PWD/status ; piesctl --url '$PIES_CTLSOCK' --no-netrc shutdown"; 82 } 83} 84_EOT 85TZ=0 86export TZ 87set -e 88to 10 \ 89 pies --foreground --stderr \ 90 --config-file control.conf --config-file pies.conf --debug 1 2>errlog 91 92if test -s in.err; then 93 echo >&2 "in.err:" 94 cat controller.err >&2 95fi 96if test -s controller.err; then 97 echo >&2 "controller.err:" 98 cat controller.err >&2 99fi 100exit `cat status` 101], 102[0]) 103AT_CLEANUP 104]) 105 106# ## 107IT_BUILTIN([echo], 108[one 109two 110three 111], 112[one 113two 114three 115]) 116 117IT_BUILTIN([discard], 118[one 119two 120three 121]) 122 123IT_SPECIAL([time],[readtime]) 124IT_SPECIAL([daytime],[readtime -H]) 125IT_SPECIAL([chargen],[chargen]) 126IT_BUILTIN([qotd],[], 127[A useful debugging and measurement tool is a quote of the day service. 128A quote of the day service simply sends a short message without regard 129to the input. 130]) 131 132m4_popdef([IT_BUILTIN]) 133m4_popdef([IT_SPECIAL]) 134 135# IT_TCPMUX([KW],[ID],[INPUT],[OUTPUT]) 136m4_define([IT_TCPMUX], 137[AT_SETUP([tcpmux: $1]) 138AT_KEYWORDS([inetd builtin internal tcpmux $1]) 139AT_CHECK([ 140PIES_XFAIL_CHECK 141PIES_CONTROL_INIT 142: ${PIES_TEST_INET_SOCKET:=unix://$PWD/in.sock} 143m4_if([$3],[],[],[AT_DATA([input],[$3])]) 144cat > pies.conf <<_EOT 145component master { 146 socket "$PIES_TEST_INET_SOCKET"; 147 service tcpmux; 148 flags internal; 149} 150component one { 151 service one; 152 flags (tcpmuxplus); 153 tcpmux-master master; 154 command "$auxdir/in.test $PWD/one.log"; 155 stderr file "$PWD/one.err"; 156} 157component two { 158 service two; 159 flags (tcpmuxplus); 160 tcpmux-master master; 161 command "$auxdir/in.test $PWD/two.log"; 162 stderr file "$PWD/two.err"; 163} 164component test { 165 command "nt -t [$2]m4_if([$3],[],,[ -i $PWD/input]) -o $PWD/test.out '$PIES_TEST_INET_SOCKET'"; 166 stderr file "$PWD/test.err"; 167 return-code * { 168 action disable; 169 exec "piesctl --no-netrc --url=$PIES_CTLSOCK shutdown"; 170 } 171} 172_EOT 173 174set -e 175to 10 \ 176 pies --foreground --stderr \ 177 --config-file control.conf --config-file pies.conf --debug 1 2>errlog 178 179for err in one.err two.err test.err 180do 181 if test -s $err; then 182 echo "$err:" 183 cat $err 184 fi 185done >&2 186 187if test -f test.out; then 188 cat test.out | tr -d '\r' 189fi 190], 191[0], 192[$4]) 193AT_CLEANUP 194]) 195 196IT_TCPMUX([help],[help],[], 197[one 198two 199]) 200 201IT_TCPMUX([service],[one], 202[Test one 203quit 204], 205[OK Test one 206]) 207 208m4_popdef([IT_TCPMUX]) 209 210 211