aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
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.c58
-rw-r--r--tests/testsuite.at16
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
@@ -56,2 +56,3 @@ TESTSUITE_AT = \
inet.at\
+ maxinst.at\
respawn.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
@@ -5,2 +5,4 @@ IFS='
'
+: ${PIESCTL:=piesctl}
+PIESCTL="$PIESCTL --no-netrc${PIES_CTLSOCK:+ --url=}$PIES_CTLSOCK"
while read COMMAND ARG
@@ -9,8 +11,13 @@ do
case $COMMAND in
- stop) if [ -n "$STOPCMD" ]; then
- echo "STOP"
- $STOPCMD
- else
- echo "OK $COMMAND $ARG"
- fi
+ stop) echo "OK shutting down"
+ $PIESCTL shutdown
+ ;;
+ enable)
+ $PIESCTL start component ${ARG:?component name not supplied}
+ ;;
+ sleep)
+ sleep ${ARG:-1}
+ ;;
+ touch)
+ touch ${ARG:?touch argument required}
;;
diff --git a/tests/control.at b/tests/control.at
index 8814b30..3d0c218 100644
--- a/tests/control.at
+++ b/tests/control.at
@@ -25,9 +25,10 @@ pies --config-file control.conf
sleep 1
-if test -f $pidfile; then
- pid0=`head -1 $pidfile`
- pid1=`piesctl --url "$ctlsock" id PID|sed 's/^PID: //'`
+PIESCTL="piesctl --no-netrc --url '$PIES_CTLSOCK'"
+if test -f $PIES_PIDFILE; then
+ pid0=`head -1 $PIES_PIDFILE`
+ pid1=`$PIESCTL id PID|sed 's/^PID: //'`
if test "$pid1" = "$pid0"; then
- if piesctl --url "$ctlsock" shutdown; then
+ if $PIESCTL shutdown; then
sleep 1
- if test -f $pidfile; then
+ if test -f $PIES_PIDFILE; then
PIES_XFAIL_MSG([pies does not respond to control commands])
diff --git a/tests/inet.at b/tests/inet.at
index 41cae6a..893e45f 100644
--- a/tests/inet.at
+++ b/tests/inet.at
@@ -1 +1,16 @@
+# This file is part of GNU pies testsuite. -*- Autotest -*-
+# Copyright (C) 2016-2019 Sergey Poznyakoff
+#
+# GNU pies is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU pies is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU pies. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([inet component])
@@ -13,5 +28,2 @@ component in {
command "$auxdir/in.test $PWD/inlog";
- env {
- set "STOPCMD=piesctl --url unix:///$PWD/pies.ctl --no-netrc shutdown";
- }
mode inetd;
diff --git a/tests/iobuf.h b/tests/iobuf.h
index 4e43338..737a8b7 100644
--- a/tests/iobuf.h
+++ b/tests/iobuf.h
@@ -137,3 +137,3 @@ iobuf_copy (struct iobuf *dst, struct iobuf *src)
}
- return 0;
+ return n;
}
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 @@
+# This file is part of GNU pies testsuite. -*- Autotest -*-
+# Copyright (C) 2019 Sergey Poznyakoff
+#
+# GNU pies is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU pies is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU pies. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([inet component: max instances])
+AT_CHECK([
+PIES_XFAIL_CHECK
+PIES_CONTROL_INIT
+
+AT_DATA([in1],
+[test
+enable con2
+sleep 10
+quit
+])
+
+AT_DATA([in2],
+[test
+enable con3
+sleep 10
+quit
+])
+
+: ${PIES_TEST_INET_SOCKET:=unix://$PWD/in.sock}
+
+cat > pies.conf <<_EOT
+component in {
+ command "$auxdir/in.test /tmp/in.log";
+ mode inetd;
+ socket "$PIES_TEST_INET_SOCKET";
+ stderr file "$PWD/in.err";
+ max-instances 2;
+ max-instances-message "too many instances running\n";
+}
+component con1 {
+ command "nt $PIES_TEST_INET_SOCKET -i in1 -o con1.out";
+ stderr file "/tmp/con1.err";
+}
+component con2 {
+ command "nt $PIES_TEST_INET_SOCKET -i in2 -o con2.out";
+ stderr file "/tmp/con2.err";
+ flags (disable);
+}
+component con3 {
+ flags (disable);
+ command "nt $PIES_TEST_INET_SOCKET -o con3.out";
+ stderr file "/tmp/con3.err";
+ return-code * {
+ action disable;
+ exec "$abs_top_builddir/src/piesctl --url unix://$PWD/pies.ctl --no-netrc shutdown";
+ }
+}
+_EOT
+
+set -e
+to 10 \
+ pies --foreground --stderr \
+ --config-file control.conf --config-file pies.conf --debug 1 2>errlog
+
+cat con3.out
+],
+[0],
+[too many instances running
+])
+
+AT_CLEANUP
diff --git a/tests/nt.c b/tests/nt.c
index 7501586..d30e447 100644
--- a/tests/nt.c
+++ b/tests/nt.c
@@ -109,2 +109,18 @@ net_writer (peer -> stdin_reader) same as stdout_writer
+static inline int
+peer_is_state (netcat_server_t *srv, int state)
+{
+ return srv->peer && (srv->peer->state & state);
+}
+
+static void
+netcat_stream_disconnect (netcat_server_t *srv, int mask)
+{
+ srv->disconnect (srv);
+ srv->state &= ~mask;
+ srv->pollfd->events &= ~mask;
+ if (srv->pollfd->events == 0)
+ srv->pollfd->fd = -1;
+}
+
ssize_t
@@ -119,2 +135,4 @@ netcat_stream_read (netcat_server_t *srv)
{
+ if (errno == EINTR)
+ return 0;
grecs_error (NULL, errno, "%s: read", srv->id);
@@ -123,11 +141,13 @@ netcat_stream_read (netcat_server_t *srv)
}
- if (n == 0)
+ if (n == 0 || !peer_is_state (srv, POLLOUT))
{
- /* No more input is expected */
- srv->disconnect (srv);
- srv->state &= ~POLLIN;
- srv->pollfd->events &= ~POLLIN;
- if (srv->pollfd->events == 0)
- srv->pollfd->fd = -1;
+ /* No more input is expected || needed */
+ netcat_stream_disconnect (srv, POLLIN);
+
+ if (srv->peer)
+ netcat_stream_disconnect (srv->peer, POLLOUT);
+ return 0;
}
+ else
+ srv->peer->pollfd->events |= POLLOUT;
}
@@ -141,8 +161,2 @@ netcat_stream_read (netcat_server_t *srv)
-static inline int
-peer_is_state (netcat_server_t *srv, int state)
-{
- return srv->peer && (srv->peer->state & state);
-}
-
ssize_t
@@ -157,7 +171,3 @@ netcat_stream_write (netcat_server_t *srv)
// shutdown write end
- srv->disconnect (srv);
- srv->state &= ~POLLOUT;
- srv->pollfd->events &= ~POLLOUT;
- if (srv->pollfd->events == 0)
- srv->pollfd->fd = -1;
+ netcat_stream_disconnect (srv, POLLOUT);
return -1;
@@ -167,2 +177,3 @@ netcat_stream_write (netcat_server_t *srv)
srv->peer->pollfd->events |= POLLIN;
+ srv->pollfd->events &= ~POLLOUT;
return 0;
@@ -173,2 +184,4 @@ netcat_stream_write (netcat_server_t *srv)
{
+ if (errno == EINTR)
+ return 0;
grecs_error (NULL, errno, "%s: write", srv->id);
@@ -257,3 +270,4 @@ netcat (char const *urlstr)
events = (srv->pollfd->events|POLLHUP)
- & (srv->pollfd->revents & (srv->state|POLLHUP));
+ & (srv->pollfd->revents
+ & (srv->state | ((srv->state & POLLOUT) ? POLLHUP : 0)));
if (events)
@@ -263,7 +277,3 @@ netcat (char const *urlstr)
//grecs_error (NULL, 0, "HUP on %s", srv->id);
- srv->disconnect (srv);
- srv->pollfd->events &= ~srv->state;
- if (srv->pollfd->events == 0)
- srv->pollfd->fd = -1;
- srv->state = 0;
+ netcat_stream_disconnect (srv, srv->state);
}
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 822ac7b..0682b51 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -30,8 +30,9 @@ m4_define([PIES_XFAIL_CHECK],[AT_XFAIL_IF([test -f $[]XFAILFILE])])
m4_define([PIES_CONTROL_INIT],[
-pidfile="$PWD/pies.pid"
-ctlsock="unix://$PWD/pies.ctl";
+PIES_PIDFILE="$PWD/pies.pid"
+PIES_CTLSOCK="unix://$PWD/pies.ctl";
+export PIES_PIDFILE PIES_CTLSOCK
cat > control.conf <<_EOT
-pidfile "$pidfile";
+pidfile "$PIES_PIDFILE";
control {
- socket "$ctlsock";
+ socket "$PIES_CTLSOCK";
}
@@ -41,5 +42,5 @@ _EOT
m4_define([PIES_STOP],[
-piesctl --url "$ctlsock" shutdown
+piesctl --url "$PIES_CTLSOCK" shutdown
pies_stop_spinner=0
-while test -f $pidfile
+while test -f $PIES_PIDFILE
do
@@ -48,3 +49,3 @@ do
if test $pies_stop_spinner -gt 3; then
- kill `cat $pidfile`
+ kill `cat $PIES_PIDFILE`
echo >&2 "timed out waiting for shutdown"
@@ -71,2 +72,3 @@ m4_include([shell.at])
m4_include([inet.at])
+m4_include([maxinst.at])

Return to:

Send suggestions and report system problems to the System administrator.