aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-06-09 18:54:58 +0300
committerSergey Poznyakoff <gray@gnu.org>2019-06-09 18:54:58 +0300
commitc4dbd40477bb658cdc5c5e01b8f80057e587cd88 (patch)
tree73534b2cd2fff99e16c26ed4be8cf115cf4b3960 /tests
parentc33922f128403f5d05d24f19abeaad2368ce5467 (diff)
downloadpies-c4dbd40477bb658cdc5c5e01b8f80057e587cd88.tar.gz
pies-c4dbd40477bb658cdc5c5e01b8f80057e587cd88.tar.bz2
Test inetd components.
* lib/Makefile.am: Add urlconn.c * lib/libpies.h (url_connect): New proto. * lib/urlconn.c: New file. * src/piesctl.c (shttp_connect): Use url_connect. * tests/.gitignore: Update. * tests/Makefile.am: New auxtool: aux/in.test New test: inet.at * tests/aux/in.test: New file. * tests/inet.at: New file. * tests/iobuf.h: New file. * tests/nt.c: New file. * tests/testsuite.at: Add new test. * tests/to.c: explicitly terminate the child process on timeout.
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.am9
-rwxr-xr-xtests/aux/in.test22
-rw-r--r--tests/inet.at38
-rw-r--r--tests/iobuf.h141
-rw-r--r--tests/nt.c339
-rw-r--r--tests/testsuite.at1
-rw-r--r--tests/to.c50
8 files changed, 590 insertions, 11 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 459fa44..68159e3 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -7,3 +7,4 @@ testsuite
7testsuite.dir 7testsuite.dir
8testsuite.log 8testsuite.log
9to 9to
10nt
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 14f5b4f..0290f61 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -20,7 +20,8 @@ AUXTOOLS = \
20 aux/mailer\ 20 aux/mailer\
21 aux/touchfile\ 21 aux/touchfile\
22 aux/sleepexit\ 22 aux/sleepexit\
23 aux/startcheck 23 aux/startcheck\
24 aux/in.test
24 25
25EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 $(AUXTOOLS) 26EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 $(AUXTOOLS)
26DISTCLEANFILES = atconfig $(check_SCRIPTS) 27DISTCLEANFILES = atconfig $(check_SCRIPTS)
@@ -52,6 +53,7 @@ TESTSUITE_AT = \
52 cyclic.at\ 53 cyclic.at\
53 env.at\ 54 env.at\
54 envop.at\ 55 envop.at\
56 inet.at\
55 respawn.at\ 57 respawn.at\
56 redirect.at\ 58 redirect.at\
57 ret-exec.at\ 59 ret-exec.at\
@@ -64,9 +66,12 @@ TESTSUITE_AT = \
64TESTSUITE = $(srcdir)/testsuite 66TESTSUITE = $(srcdir)/testsuite
65M4=m4 67M4=m4
66 68
67noinst_PROGRAMS = envtest to lines 69noinst_PROGRAMS = envtest to lines nt
70nt_SOURCES = nt.c iobuf.h
68AM_CPPFLAGS = \ 71AM_CPPFLAGS = \
69 -I$(top_srcdir)/lib\ 72 -I$(top_srcdir)/lib\
73 -I$(top_srcdir)/gnu\
74 -I$(top_builddir)/gnu\
70 @GRECS_INCLUDES@ 75 @GRECS_INCLUDES@
71 76
72LDADD = \ 77LDADD = \
diff --git a/tests/aux/in.test b/tests/aux/in.test
new file mode 100755
index 0000000..4a98763
--- /dev/null
+++ b/tests/aux/in.test
@@ -0,0 +1,22 @@
1#! /bin/sh
2
3FILE=${1:?}
4IFS='
5'
6while read COMMAND ARG
7do
8 echo $COMMAND $ARG >> $FILE
9 case $COMMAND in
10 stop) if [ -n "$STOPCMD" ]; then
11 echo "STOP"
12 $STOPCMD
13 else
14 echo "OK $COMMAND $ARG"
15 fi
16 ;;
17 quit) exit $ARG;;
18 *) echo "OK $COMMAND $ARG"
19 ;;
20 esac
21done
22
diff --git a/tests/inet.at b/tests/inet.at
new file mode 100644
index 0000000..41cae6a
--- /dev/null
+++ b/tests/inet.at
@@ -0,0 +1,38 @@
1AT_SETUP([inet component])
2AT_CHECK([
3PIES_XFAIL_CHECK
4PIES_CONTROL_INIT
5AT_DATA([input],
6[line 1
7line 2
8stop
9])
10: ${PIES_TEST_INET_SOCKET:=unix://$PWD/in.sock}
11cat > pies.conf <<_EOT
12component in {
13 command "$auxdir/in.test $PWD/inlog";
14 env {
15 set "STOPCMD=piesctl --url unix:///$PWD/pies.ctl --no-netrc shutdown";
16 }
17 mode inetd;
18 socket "$PIES_TEST_INET_SOCKET";
19 stderr file "$PWD/log.err";
20}
21component controller {
22 command "nt $PIES_TEST_INET_SOCKET -i input";
23}
24_EOT
25set -e
26to 10 \
27 pies --foreground --stderr \
28 --config-file control.conf --config-file pies.conf --debug 1 2>errlog
29
30cat inlog
31cat log.err >&2
32],
33[0],
34[line 1
35line 2
36stop
37])
38AT_CLEANUP
diff --git a/tests/iobuf.h b/tests/iobuf.h
new file mode 100644
index 0000000..4e43338
--- /dev/null
+++ b/tests/iobuf.h
@@ -0,0 +1,141 @@
1/* This file is part of GNU Pies.
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#define IO_BUF_SIZE 512
18
19struct iobuf
20{
21 char buf[IO_BUF_SIZE]; /* Initial line buffer */
22 size_t start; /* Start of data */
23 size_t avail; /* Start of available space */
24};
25
26static inline void
27iobuf_reset (struct iobuf *bp)
28{
29 bp->start = bp->avail = 0;
30}
31
32/* Return the count of data bytes in the buffer */
33static inline size_t
34iobuf_data_size (struct iobuf *bp)
35{
36 return bp->avail - bp->start;
37}
38
39static inline char *
40iobuf_data_ptr (struct iobuf *bp)
41{
42 return bp->buf + bp->start;
43}
44
45static inline void
46iobuf_data_advance (struct iobuf *bp, size_t n)
47{
48 bp->start += n;
49 if (bp->start == bp->avail)
50 iobuf_reset (bp);
51}
52
53static inline int
54iobuf_putback (struct iobuf *bp)
55{
56 return bp->buf[--bp->start-1];
57}
58
59static inline int
60iobuf_getc (struct iobuf *bp)
61{
62 int c = -1;
63 if (iobuf_data_size (bp) > 0)
64 {
65 c = *iobuf_data_ptr (bp);
66 iobuf_data_advance(bp, 1);
67 }
68 return c;
69}
70
71/* Return the count of available bytes in the buffer */
72static inline size_t
73iobuf_avail_size (struct iobuf *bp)
74{
75 return sizeof (bp->buf) - bp->avail;
76}
77
78static inline char *
79iobuf_avail_ptr (struct iobuf *bp)
80{
81 return bp->buf + bp->avail;
82}
83
84static inline void
85iobuf_avail_advance (struct iobuf *bp, size_t n)
86{
87 bp->avail += n;
88 if (iobuf_avail_size (bp) == 0 && iobuf_data_size (bp) == 0)
89 iobuf_reset (bp);
90}
91
92static inline int
93iobuf_putc (struct iobuf *bp, int c)
94{
95 if (iobuf_avail_size (bp) > 0)
96 {
97 *iobuf_avail_ptr (bp) = c;
98 iobuf_avail_advance (bp, 1);
99 return c;
100 }
101 return -1;
102}
103
104static inline ssize_t
105iobuf_fill (struct iobuf *bp, int fd)
106{
107 ssize_t n = read (fd, iobuf_avail_ptr (bp), iobuf_avail_size (bp));
108 if (n >= 0)
109 iobuf_avail_advance (bp, n);
110 return n;
111}
112
113static inline ssize_t
114iobuf_flush (struct iobuf *bp, int fd)
115{
116 ssize_t n = write (fd, iobuf_data_ptr (bp), iobuf_data_size (bp));
117 if (n >= 0)
118 iobuf_data_advance (bp, n);
119 return n;
120}
121
122static inline ssize_t
123iobuf_copy (struct iobuf *dst, struct iobuf *src)
124{
125 ssize_t n = iobuf_data_size (src);
126 if (n > 0)
127 {
128 ssize_t avail = iobuf_avail_size (dst);
129 if (avail < n)