aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
@@ -45,24 +45,25 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
## ------------ ##
## Test suite. ##
## ------------ ##
TESTSUITE_AT = \
testsuite.at\
control.at\
cyclic.at\
env.at\
envop.at\
inet.at\
+ maxinst.at\
respawn.at\
redirect.at\
ret-exec.at\
ret-notify.at\
shell.at\
startup.at\
shutdown.at\
version.at
TESTSUITE = $(srcdir)/testsuite
M4=m4
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
@@ -1,22 +1,29 @@
#! /bin/sh
FILE=${1:?}
IFS='
'
+: ${PIESCTL:=piesctl}
+PIESCTL="$PIESCTL --no-netrc${PIES_CTLSOCK:+ --url=}$PIES_CTLSOCK"
while read COMMAND ARG
do
echo $COMMAND $ARG >> $FILE
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}
;;
quit) exit $ARG;;
*) echo "OK $COMMAND $ARG"
;;
esac
done
diff --git a/tests/control.at b/tests/control.at
index 8814b30..3d0c218 100644
--- a/tests/control.at
+++ b/tests/control.at
@@ -14,31 +14,32 @@
# 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([Control interface])
AT_CHECK([
PIES_XFAIL_CHECK
PIES_CONTROL_INIT
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])
kill -9 $pid0
exit 1
else
exit 0
fi
else
PIES_XFAIL_MSG([can't send control commands])
kill -9 $pid0
exit 1
fi
else
diff --git a/tests/inet.at b/tests/inet.at
index 41cae6a..893e45f 100644
--- a/tests/inet.at
+++ b/tests/inet.at
@@ -1,28 +1,40 @@
+# 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])
AT_CHECK([
PIES_XFAIL_CHECK
PIES_CONTROL_INIT
AT_DATA([input],
[line 1
line 2
stop
])
: ${PIES_TEST_INET_SOCKET:=unix://$PWD/in.sock}
cat > pies.conf <<_EOT
component in {
command "$auxdir/in.test $PWD/inlog";
- env {
- set "STOPCMD=piesctl --url unix:///$PWD/pies.ctl --no-netrc shutdown";
- }
mode inetd;
socket "$PIES_TEST_INET_SOCKET";
stderr file "$PWD/log.err";
}
component controller {
command "nt $PIES_TEST_INET_SOCKET -i input";
}
_EOT
set -e
to 10 \
pies --foreground --stderr \
--config-file control.conf --config-file pies.conf --debug 1 2>errlog
diff --git a/tests/iobuf.h b/tests/iobuf.h
index 4e43338..737a8b7 100644
--- a/tests/iobuf.h
+++ b/tests/iobuf.h
@@ -126,16 +126,16 @@ iobuf_copy (struct iobuf *dst, struct iobuf *src)
if (n > 0)
{
ssize_t avail = iobuf_avail_size (dst);
if (avail < n)
n = avail;
if (n)
{
memcpy (iobuf_avail_ptr (dst), iobuf_data_ptr (src), n);
iobuf_avail_advance (dst, n);
iobuf_data_advance (src, n);
}
}
- 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
@@ -98,88 +98,101 @@ from the fd and return
stdout_writer (peer -> net_reader)
1. If OUT buffer is empty
1.1 If the peer's IN buffer is not empty, transfer data from it
1.2 Else raise the peers POLLIN bit and return.
2. Write as much as possible from OUT to fd
stdin_reader (same as net_reader)
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
netcat_stream_read (netcat_server_t *srv)
{
ssize_t n;
-
+
if (iobuf_avail_size (&srv->buf[IN]))
{
n = iobuf_fill (&srv->buf[IN], srv->pollfd->fd);
if (n == -1)
{
+ if (errno == EINTR)
+ return 0;
grecs_error (NULL, errno, "%s: read", srv->id);
srv->pollfd->events &= ~POLLIN;
return -1;
}
- 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;
}
else
{
srv->pollfd->events &= ~POLLIN;
n = 0; /* catch timeout? */
}
return n;
}
-static inline int
-peer_is_state (netcat_server_t *srv, int state)
-{
- return srv->peer && (srv->peer->state & state);
-}
-
ssize_t
netcat_stream_write (netcat_server_t *srv)
{
ssize_t n;
if (iobuf_data_size (&srv->buf[OUT]) == 0)
{
if (!peer_is_state (srv, POLLIN))
{
// 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;
}
if (iobuf_copy (&srv->buf[OUT], &srv->peer->buf[IN]) == 0)
{
srv->peer->pollfd->events |= POLLIN;
+ srv->pollfd->events &= ~POLLOUT;
return 0;
}
}
n = iobuf_flush (&srv->buf[OUT], srv->pollfd->fd);
if (n == -1)
{
+ if (errno == EINTR)
+ return 0;
grecs_error (NULL, errno, "%s: write", srv->id);
return -1;
}
if (n == 0)
{
// FIXME: eof
return -1;
}
return 0;
}
int
@@ -244,37 +257,34 @@ netcat (char const *urlstr)
{
ssize_t n = poll (pfd, nfd, -1);
if (n == -1)
{
if (errno != EINTR)
grecs_error (NULL, errno, "poll");
continue;
}
for (srv = server_head; srv; )
{
netcat_server_t *next = srv->next;
int events;
-
+
events = (srv->pollfd->events|POLLHUP)
- & (srv->pollfd->revents & (srv->state|POLLHUP));
+ & (srv->pollfd->revents
+ & (srv->state | ((srv->state & POLLOUT) ? POLLHUP : 0)));
if (events)
{
if (events & POLLHUP)
{
//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);
}
else if (events & POLLIN)
netcat_stream_read (srv);
else if (events & POLLOUT)
netcat_stream_write (srv);
}
if (srv->state == 0 || srv->pollfd->fd == -1)
netcat_server_remove (srv);
srv = next;
}
}
return 0;
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 822ac7b..0682b51 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -19,56 +19,58 @@ m4_version_prereq([2.69])
m4_define([PIES_SGN],[pies (AT_PACKAGE_NAME) AT_PACKAGE_VERSION])
m4_define([PIES_XFAIL_MSG],[cat >$[]XFAILFILE <<'_EOT'
==============================================================
$*
==============================================================
_EOT
])
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";
}
_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
sleep 1
pies_stop_spinner=$(($pies_stop_spinner + 1))
if test $pies_stop_spinner -gt 3; then
- kill `cat $pidfile`
+ kill `cat $PIES_PIDFILE`
echo >&2 "timed out waiting for shutdown"
fi
done])
AT_INIT
AT_TESTED([pies])
AT_BANNER([Initial])
m4_include([version.at])
m4_include([control.at])
AT_BANNER([Dependencies])
m4_include([cyclic.at])
AT_BANNER([Components])
m4_include([respawn.at])
m4_include([redirect.at])
m4_include([ret-exec.at])
m4_include([ret-notify.at])
m4_include([startup.at])
m4_include([shutdown.at])
m4_include([shell.at])
m4_include([inet.at])
+m4_include([maxinst.at])
m4_include([envop.at])
m4_include([env.at]) \ No newline at end of file

Return to:

Send suggestions and report system problems to the System administrator.