summaryrefslogtreecommitdiffabout
path: root/tests
authorSergey Poznyakoff <gray@gnu.org>2019-06-11 09:54:02 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2019-06-11 10:18:29 (GMT)
commitbf6506cdc46446eada5090a428c2407ebd17468a (patch) (unidiff)
tree2113b5c049283413fb4fe3981a837989d2969918 /tests
parent186b9a1c99988844c5ea3fcce1fcc6cadb491206 (diff)
downloadpies-bf6506cdc46446eada5090a428c2407ebd17468a.tar.gz
pies-bf6506cdc46446eada5090a428c2407ebd17468a.tar.bz2
Improve the nt tool. Test inet running instance limit.
* tests/Makefile.am: Add new test. * tests/aux/in.test (PIESCTL): Provide the necessary options. Discontinue the use of STOPCMD environment variable. New commands: enable, sleep, touch. * tests/testsuite.at (PIES_CONTROL_INIT): Rename pidfile to PIES_PIDFILE and ctlsock to PIES_CTLSOCK. Export both. Include maxinst.at * tests/control.at: Use new variables. * tests/inet.at: Remove the env block. * tests/iobuf.h (iobuf_copy): Return number of bytes copied. * tests/maxinst.at: New file. * tests/nt.c (netcat_stream_disconnect): New function. (netcat_stream_read): Disconnect the peer stream if no more input is available and the peer is not available for output (i.e. its output buffer is empty). (netcat_stream_write): Stop polling if output buffer is empty. (netcat): Fix event mask
Diffstat (limited to 'tests') (more/less context) (ignore whitespace changes)
-rw-r--r--tests/Makefile.am1
-rwxr-xr-xtests/aux/in.test19
-rw-r--r--tests/control.at11
-rw-r--r--tests/inet.at18
-rw-r--r--tests/iobuf.h2
-rw-r--r--tests/maxinst.at78
-rw-r--r--tests/nt.c62
-rw-r--r--tests/testsuite.at16
8 files changed, 159 insertions, 48 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0290f61..fa1d6be 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -54,6 +54,7 @@ TESTSUITE_AT = \
54 env.at\ 54 env.at\
55 envop.at\ 55 envop.at\
56 inet.at\ 56 inet.at\
57 maxinst.at\
57 respawn.at\ 58 respawn.at\
58 redirect.at\ 59 redirect.at\
59 ret-exec.at\ 60 ret-exec.at\
diff --git a/tests/aux/in.test b/tests/aux/in.test
index 4a98763..1fae034 100755
--- a/tests/aux/in.test
+++ b/tests/aux/in.test
@@ -3,16 +3,23 @@
3FILE=${1:?} 3FILE=${1:?}
4 IFS=' 4 IFS='
5' 5'
6: ${PIESCTL:=piesctl}
7PIESCTL="$PIESCTL --no-netrc${PIES_CTLSOCK:+ --url=}$PIES_CTLSOCK"
6while read COMMAND ARG 8while read COMMAND ARG
7do 9do
8 echo $COMMAND $ARG >> $FILE 10 echo $COMMAND $ARG >> $FILE
9 case $COMMAND in 11 case $COMMAND in
10 stop) if [ -n "$STOPCMD" ]; then 12 stop) echo "OK shutting down"
11 echo "STOP" 13 $PIESCTL shutdown
12 $STOPCMD 14 ;;
13 else 15 enable)
14 echo "OK $COMMAND $ARG" 16 $PIESCTL start component ${ARG:?component name not supplied}
15 fi 17 ;;
18 sleep)
19 sleep ${ARG:-1}
20 ;;
21 touch)
22 touch ${ARG:?touch argument required}
16 ;; 23 ;;
17 quit) exit $ARG;; 24 quit) exit $ARG;;
18 *) echo "OK $COMMAND $ARG" 25 *) echo "OK $COMMAND $ARG"
diff --git a/tests/control.at b/tests/control.at
index 8814b30..3d0c218 100644
--- a/tests/control.at
+++ b/tests/control.at
@@ -23,13 +23,14 @@ PIES_CONTROL_INIT
23pies --config-file control.conf 23pies --config-file control.conf
24 24
25sleep 1 25sleep 1
26if test -f $pidfile; then 26PIESCTL="piesctl --no-netrc --url '$PIES_CTLSOCK'"
27 pid0=`head -1 $pidfile` 27if test -f $PIES_PIDFILE; then
28 pid1=`piesctl --url "$ctlsock" id PID|sed 's/^PID: //'` 28 pid0=`head -1 $PIES_PIDFILE`
29 pid1=`$PIESCTL id PID|sed 's/^PID: //'`
29 if test "$pid1" = "$pid0"; then 30 if test "$pid1" = "$pid0"; then
30 if piesctl --url "$ctlsock" shutdown; then 31 if $PIESCTL shutdown; then
31 sleep 1 32 sleep 1
32 if test -f $pidfile; then 33 if test -f $PIES_PIDFILE; then
33 PIES_XFAIL_MSG([pies does not respond to control commands]) 34 PIES_XFAIL_MSG([pies does not respond to control commands])
34 kill -9 $pid0 35 kill -9 $pid0
35 exit 1 36 exit 1
diff --git a/tests/inet.at b/tests/inet.at
index 41cae6a..893e45f 100644
--- a/tests/inet.at
+++ b/tests/inet.at
@@ -1,3 +1,18 @@
1# This file is part of GNU pies testsuite. -*- Autotest -*-
2# Copyright (C) 2016-2019 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/>.
1AT_SETUP([inet component]) 16AT_SETUP([inet component])
2AT_CHECK([ 17AT_CHECK([
3PIES_XFAIL_CHECK 18PIES_XFAIL_CHECK
@@ -11,9 +26,6 @@ stop
11cat > pies.conf <<_EOT 26cat > pies.conf <<_EOT
12component in { 27component in {
13 command "$auxdir/in.test $PWD/inlog"; 28 command "$auxdir/in.test $PWD/inlog";
14 env {
15 set "STOPCMD=piesctl --url unix:///$PWD/pies.ctl --no-netrc shutdown";
16 }
17 mode inetd; 29 mode inetd;
18 socket "$PIES_TEST_INET_SOCKET"; 30 socket "$PIES_TEST_INET_SOCKET";
19 stderr file "$PWD/log.err"; 31 stderr file "$PWD/log.err";
diff --git a/tests/iobuf.h b/tests/iobuf.h
index 4e43338..737a8b7 100644
--- a/tests/iobuf.h
+++ b/tests/iobuf.h
@@ -135,7 +135,7 @@ iobuf_copy (struct iobuf *dst, struct iobuf *src)
135 iobuf_data_advance (src, n); 135 iobuf_data_advance (src, n);
136 } 136 }
137 } 137 }
138 return 0; 138 return n;
139} 139}
140 140
141 141
diff --git a/tests/maxinst.at b/tests/maxinst.at
new file mode 100644
index 0000000..f67d15e
--- a/dev/null
+++ b/tests/maxinst.at
@@ -0,0 +1,78 @@
1# This file is part of GNU pies testsuite. -*- Autotest -*-
2# Copyright (C) 2019 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/>.
16
17AT_SETUP([inet component: max instances])
18AT_CHECK([
19PIES_XFAIL_CHECK
20PIES_CONTROL_INIT
21
22AT_DATA([in1],
23[test
24enable con2
25sleep 10
26quit
27])
28
29AT_DATA([in2],
30[test
31enable con3
32sleep 10
33quit
34])
35
36: ${PIES_TEST_INET_SOCKET:=unix://$PWD/in.sock}
37
38cat > pies.conf <<_EOT
39component in {
40 command "$auxdir/in.test /tmp/in.log";
41 mode inetd;
42 socket "$PIES_TEST_INET_SOCKET";
43 stderr file "$PWD/in.err";
44 max-instances 2;
45 max-instances-message "too many instances running\n";
46}
47component con1 {
48 command "nt $PIES_TEST_INET_SOCKET -i in1 -o con1.out";
49 stderr file "/tmp/con1.err";
50}
51component con2 {
52 command "nt $PIES_TEST_INET_SOCKET -i in2 -o con2.out";
53 stderr file "/tmp/con2.err";
54 flags (disable);
55}
56component con3 {
57 flags (disable);
58 command "nt $PIES_TEST_INET_SOCKET -o con3.out";
59 stderr file "/tmp/con3.err";
60 return-code * {
61 action disable;
62 exec "$abs_top_builddir/src/piesctl --url unix://$PWD/pies.ctl --no-netrc shutdown";
63 }
64}
65_EOT
66
67set -e
68to 10 \
69 pies --foreground --stderr \
70 --config-file control.conf --config-file pies.conf --debug 1 2>errlog
71
72cat con3.out
73],
74[0],
75[too many instances running
76])
77
78AT_CLEANUP
diff --git a/tests/nt.c b/tests/nt.c
index 7501586..d30e447 100644
--- a/tests/nt.c
+++ b/tests/nt.c
@@ -107,29 +107,49 @@ stdin_reader (same as net_reader)
107net_writer (peer -> stdin_reader) same as stdout_writer 107net_writer (peer -> stdin_reader) same as stdout_writer
108*/ 108*/
109 109
110static inline int
111peer_is_state (netcat_server_t *srv, int state)
112{
113 return srv->peer && (srv->peer->state & state);
114}
115
116static void
117netcat_stream_disconnect (netcat_server_t *srv, int mask)
118{
119 srv->disconnect (srv);
120 srv->state &= ~mask;
121 srv->pollfd->events &= ~mask;
122 if (srv->pollfd->events == 0)
123 srv->pollfd->fd = -1;
124}
125
110ssize_t 126ssize_t
111netcat_stream_read (netcat_server_t *srv) 127netcat_stream_read (netcat_server_t *srv)
112{ 128{
113 ssize_t n; 129 ssize_t n;
114 130
115 if (iobuf_avail_size (&srv->buf[IN])) 131 if (iobuf_avail_size (&srv->buf[IN]))
116 { 132 {
117 n = iobuf_fill (&srv->buf[IN], srv->pollfd->fd); 133 n = iobuf_fill (&srv->buf[IN], srv->pollfd->fd);
118 if (n == -1) 134 if (n == -1)
119 { 135 {
136 if (errno == EINTR)
137 return 0;
120 grecs_error (NULL, errno, "%s: read", srv->id); 138 grecs_error (NULL, errno, "%s: read", srv->id);
121 srv->pollfd->events &= ~POLLIN; 139 srv->pollfd->events &= ~POLLIN;
122 return -1; 140 return -1;
123 } 141 }
124 if (n == 0) 142 if (n == 0 || !peer_is_state (srv, POLLOUT))
125 { 143 {
126 /* No more input is expected */ 144 /* No more input is expected || needed */
127 srv->disconnect (srv); 145 netcat_stream_disconnect (srv, POLLIN);
128 srv->state &= ~POLLIN; 146
129 srv->pollfd->events &= ~POLLIN; 147 if (srv->peer)
130 if (srv->pollfd->events == 0) 148 netcat_stream_disconnect (srv->peer, POLLOUT);
131 srv->pollfd->fd = -1; 149 return 0;
132 } 150 }
151 else
152 srv->peer->pollfd->events |= POLLOUT;
133 } 153 }
134 else 154 else
135 { 155 {
@@ -139,12 +159,6 @@ netcat_stream_read (netcat_server_t *srv)
139 return n; 159 return n;
140} 160}
141 161
142static inline int
143peer_is_state (netcat_server_t *srv, int state)
144{
145 return srv->peer && (srv->peer->state & state);
146}
147
148ssize_t 162ssize_t
149netcat_stream_write (netcat_server_t *srv) 163netcat_stream_write (netcat_server_t *srv)
150{ 164{
@@ -155,22 +169,21 @@ netcat_stream_write (netcat_server_t *srv)
155 if (!peer_is_state (srv, POLLIN)) 169 if (!peer_is_state (srv, POLLIN))
156 { 170 {
157 // shutdown write end 171 // shutdown write end
158 srv->disconnect (srv); 172 netcat_stream_disconnect (srv, POLLOUT);
159 srv->state &= ~POLLOUT;
160 srv->pollfd->events &= ~POLLOUT;
161 if (srv->pollfd->events == 0)
162 srv->pollfd->fd = -1;
163 return -1; 173 return -1;
164 } 174 }
165 if (iobuf_copy (&srv->buf[OUT], &srv->peer->buf[IN]) == 0) 175 if (iobuf_copy (&srv->buf[OUT], &srv->peer->buf[IN]) == 0)
166 { 176 {
167 srv->peer->pollfd->events |= POLLIN; 177 srv->peer->pollfd->events |= POLLIN;
178 srv->pollfd->events &= ~POLLOUT;
168 return 0; 179 return 0;
169 } 180 }
170 } 181 }
171 n = iobuf_flush (&srv->buf[OUT], srv->pollfd->fd); 182 n = iobuf_flush (&srv->buf[OUT], srv->pollfd->fd);
172 if (n == -1) 183 if (n == -1)
173 { 184 {
185 if (errno == EINTR)
186 return 0;
174 grecs_error (NULL, errno, "%s: write", srv->id); 187 grecs_error (NULL, errno, "%s: write", srv->id);
175 return -1; 188 return -1;
176 } 189 }
@@ -253,19 +266,16 @@ netcat (char const *urlstr)
253 { 266 {
254 netcat_server_t *next = srv->next; 267 netcat_server_t *next = srv->next;
255 int events; 268 int events;
256 269
257 events = (srv->pollfd->events|POLLHUP) 270 events = (srv->pollfd->events|POLLHUP)
258 & (srv->pollfd->revents & (srv->state|POLLHUP)); 271 & (srv->pollfd->revents
272 & (srv->state | ((srv->state & POLLOUT) ? POLLHUP : 0)));
259 if (events) 273 if (events)
260 { 274 {
261 if (events & POLLHUP) 275 if (events & POLLHUP)
262 { 276 {
263 //grecs_error (NULL, 0, "HUP on %s", srv->id); 277 //grecs_error (NULL, 0, "HUP on %s", srv->id);
264 srv->disconnect (srv); 278 netcat_stream_disconnect (srv, srv->state);
265 srv->pollfd->events &= ~srv->state;
266 if (srv->pollfd->events == 0)
267 srv->pollfd->fd = -1;
268 srv->state = 0;
269 } 279 }
270 else if (events & POLLIN) 280 else if (events & POLLIN)
271 netcat_stream_read (srv); 281 netcat_stream_read (srv);
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 822ac7b..0682b51 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -28,25 +28,26 @@ _EOT
28m4_define([PIES_XFAIL_CHECK],[AT_XFAIL_IF([test -f $[]XFAILFILE])]) 28m4_define([PIES_XFAIL_CHECK],[AT_XFAIL_IF([test -f $[]XFAILFILE])])
29 29
30m4_define([PIES_CONTROL_INIT],[ 30m4_define([PIES_CONTROL_INIT],[
31pidfile="$PWD/pies.pid" 31PIES_PIDFILE="$PWD/pies.pid"
32ctlsock="unix://$PWD/pies.ctl"; 32PIES_CTLSOCK="unix://$PWD/pies.ctl";
33export PIES_PIDFILE PIES_CTLSOCK
33cat > control.conf <<_EOT 34cat > control.conf <<_EOT
34pidfile "$pidfile"; 35pidfile "$PIES_PIDFILE";
35control { 36control {
36 socket "$ctlsock"; 37 socket "$PIES_CTLSOCK";
37} 38}
38_EOT 39_EOT
39]) 40])
40 41
41m4_define([PIES_STOP],[ 42m4_define([PIES_STOP],[
42piesctl --url "$ctlsock" shutdown 43piesctl --url "$PIES_CTLSOCK" shutdown
43pies_stop_spinner=0 44pies_stop_spinner=0
44while test -f $pidfile 45while test -f $PIES_PIDFILE
45do 46do
46 sleep 1 47 sleep 1
47 pies_stop_spinner=$(($pies_stop_spinner + 1)) 48 pies_stop_spinner=$(($pies_stop_spinner + 1))
48 if test $pies_stop_spinner -gt 3; then 49 if test $pies_stop_spinner -gt 3; then
49 kill `cat $pidfile` 50 kill `cat $PIES_PIDFILE`
50 echo >&2 "timed out waiting for shutdown" 51 echo >&2 "timed out waiting for shutdown"
51 fi 52 fi
52done]) 53done])
@@ -69,6 +70,7 @@ m4_include([startup.at])
69m4_include([shutdown.at]) 70m4_include([shutdown.at])
70m4_include([shell.at]) 71m4_include([shell.at])
71m4_include([inet.at]) 72m4_include([inet.at])
73m4_include([maxinst.at])
72 74
73m4_include([envop.at]) 75m4_include([envop.at])
74m4_include([env.at]) \ No newline at end of file 76m4_include([env.at]) \ No newline at end of file

Return to:

Send suggestions and report system problems to the System administrator.