aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-06-11 12:54:02 +0300
committerSergey Poznyakoff <gray@gnu.org>2019-06-11 13:18:29 +0300
commitbf6506cdc46446eada5090a428c2407ebd17468a (patch)
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')
-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:?}
4IFS=' 4IFS='
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
--- /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 (