diff options
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rwxr-xr-x | tests/aux/in.test | 19 | ||||
-rw-r--r-- | tests/control.at | 11 | ||||
-rw-r--r-- | tests/inet.at | 18 | ||||
-rw-r--r-- | tests/iobuf.h | 2 | ||||
-rw-r--r-- | tests/maxinst.at | 78 | ||||
-rw-r--r-- | tests/nt.c | 58 | ||||
-rw-r--r-- | tests/testsuite.at | 16 |
8 files changed, 157 insertions, 46 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 @@ | |||
3 | FILE=${1:?} | 3 | FILE=${1:?} |
4 | IFS=' | 4 | IFS=' |
5 | ' | 5 | ' |
6 | : ${PIESCTL:=piesctl} | ||
7 | PIESCTL="$PIESCTL --no-netrc${PIES_CTLSOCK:+ --url=}$PIES_CTLSOCK" | ||
6 | while read COMMAND ARG | 8 | while read COMMAND ARG |
7 | do | 9 | do |
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 | |||
23 | pies --config-file control.conf | 23 | pies --config-file control.conf |
24 | 24 | ||
25 | sleep 1 | 25 | sleep 1 |
26 | if test -f $pidfile; then | 26 | PIESCTL="piesctl --no-netrc --url '$PIES_CTLSOCK'" |
27 | pid0=`head -1 $pidfile` | 27 | if 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/>. | ||
1 | AT_SETUP([inet component]) | 16 | AT_SETUP([inet component]) |
2 | AT_CHECK([ | 17 | AT_CHECK([ |
3 | PIES_XFAIL_CHECK | 18 | PIES_XFAIL_CHECK |
@@ -11,9 +26,6 @@ stop | |||
11 | cat > pies.conf <<_EOT | 26 | cat > pies.conf <<_EOT |
12 | component in { | 27 | component 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 --- /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 | |||
17 | AT_SETUP([inet component: max instances]) | ||
18 | AT_CHECK([ | ||
19 | PIES_XFAIL_CHECK | ||
20 | PIES_CONTROL_INIT | ||
21 | |||
22 | AT_DATA([in1], | ||
23 | [test | ||
24 | enable con2 | ||
25 | sleep 10 | ||
26 | quit | ||
27 | ]) | ||
28 | |||
29 | AT_DATA([in2], | ||
30 | [test | ||
31 | enable con3 | ||
32 | sleep 10 | ||
33 | quit | ||
34 | ]) | ||
35 | |||
36 | : ${PIES_TEST_INET_SOCKET:=unix://$PWD/in.sock} | ||
37 | |||
38 | cat > pies.conf <<_EOT | ||
39 | component 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 | } | ||
47 | component con1 { | ||
48 | command "nt $PIES_TEST_INET_SOCKET -i in1 -o con1.out"; | ||
49 | stderr file "/tmp/con1.err"; | ||
50 | } | ||
51 | component con2 { | ||
52 | command "nt $PIES_TEST_INET_SOCKET -i in2 -o con2.out"; | ||
53 | stderr file "/tmp/con2.err"; | ||
54 | flags (disable); | ||
55 | } | ||
56 | component 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 | |||
67 | set -e | ||
68 | to 10 \ | ||
69 | pies --foreground --stderr \ | ||
70 | --config-file control.conf --config-file pies.conf --debug 1 2>errlog | ||
71 | |||
72 | cat con3.out | ||
73 | ], | ||
74 | [0], | ||
75 | [too many instances running | ||
76 | ]) | ||
77 | |||
78 | AT_CLEANUP | ||
@@ -107,6 +107,22 @@ stdin_reader (same as net_reader) | |||
107 | net_writer (peer -> stdin_reader) same as stdout_writer | 107 | net_writer (peer -> stdin_reader) same as stdout_writer |
108 | */ | 108 | */ |
109 | 109 | ||
110 | static inline int | ||
111 | peer_is_state (netcat_server_t *srv, int state) | ||
112 | { | ||
113 | return srv->peer && (srv->peer->state & state); | ||
114 | } | ||
115 | |||
116 | static void | ||
117 | netcat_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 | |||
110 | ssize_t | 126 | ssize_t |
111 | netcat_stream_read (netcat_server_t *srv) | 127 | netcat_stream_read (netcat_server_t *srv) |
112 | { | 128 | { |
@@ -117,19 +133,23 @@ netcat_stream_read (netcat_server_t *srv) | |||
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< |