summaryrefslogtreecommitdiffabout
path: root/tests
authorSergey Poznyakoff <gray@gnu.org>2019-06-12 08:08:22 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2019-06-12 08:15:51 (GMT)
commitf5c72b5e74ea7aaf1375f763f977e3249c6b7fc4 (patch) (unidiff)
tree22efbd43e8215666e7d7391193e4030d4354342e /tests
parent07e7ee3d732b60e0b7f5b242bbfb0cdec8e99e7f (diff)
downloadpies-f5c72b5e74ea7aaf1375f763f977e3249c6b7fc4.tar.gz
pies-f5c72b5e74ea7aaf1375f763f977e3249c6b7fc4.tar.bz2
Check accept components and inet built-in services.
* src/comp.c (component_verify,component_finish): Fix check for the presense of the "command" statement. * src/pies.c (component_keywords): Reorder some entries for the consistency of config-help output. * tests/.gitignore: Add new files. * tests/Makefile.am: Add new tests and noinst programs. * tests/accept.at: New test. * tests/builtin.at: New test. * tests/chargen.c: New file. * tests/readtime.c: New file. * tests/recvfd.c: Rewrite for testing both accept and pass-fd components. * tests/passfd.at: Pass -s option to recvfd * tests/testsuite.at: Add new tests. * tests/lines.c: Minor changes. * tests/nt.c: Minor changes. * tests/to.c: Minor changes.
Diffstat (limited to 'tests') (more/less context) (ignore whitespace changes)
-rw-r--r--tests/.gitignore2
-rw-r--r--tests/Makefile.am7
-rw-r--r--tests/accept.at54
-rw-r--r--tests/builtin.at131
-rw-r--r--tests/chargen.c109
-rw-r--r--tests/lines.c17
-rw-r--r--tests/nt.c4
-rw-r--r--tests/passfd.at2
-rw-r--r--tests/readtime.c161
-rw-r--r--tests/recvfd.c55
-rw-r--r--tests/testsuite.at2
-rw-r--r--tests/to.c3
12 files changed, 526 insertions, 21 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 7d2613a..43d3848 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -9,3 +9,5 @@ testsuite.log
9to 9to
10nt 10nt
11recvfd 11recvfd
12readtime
13chargen
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1fe78dc..4631a2c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -49,6 +49,8 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
49 49
50TESTSUITE_AT = \ 50TESTSUITE_AT = \
51 testsuite.at\ 51 testsuite.at\
52 accept.at\
53 builtin.at\
52 control.at\ 54 control.at\
53 cyclic.at\ 55 cyclic.at\
54 env.at\ 56 env.at\
@@ -68,7 +70,7 @@ TESTSUITE_AT = \
68TESTSUITE = $(srcdir)/testsuite 70TESTSUITE = $(srcdir)/testsuite
69M4=m4 71M4=m4
70 72
71noinst_PROGRAMS = envtest to lines nt recvfd 73noinst_PROGRAMS = envtest to lines nt recvfd readtime chargen
72nt_SOURCES = nt.c iobuf.h 74nt_SOURCES = nt.c iobuf.h
73AM_CPPFLAGS = \ 75AM_CPPFLAGS = \
74 -I$(top_srcdir)/lib\ 76 -I$(top_srcdir)/lib\
@@ -78,7 +80,8 @@ AM_CPPFLAGS = \
78 80
79LDADD = \ 81LDADD = \
80 ../lib/libpies.a\ 82 ../lib/libpies.a\
81 @GRECS_LDADD@ 83 @GRECS_LDADD@\
84 ../gnu/libgnu.a
82 85
83AUTOTEST = $(AUTOM4TE) --language=autotest 86AUTOTEST = $(AUTOM4TE) --language=autotest
84$(TESTSUITE): package.m4 $(TESTSUITE_AT) 87$(TESTSUITE): package.m4 $(TESTSUITE_AT)
diff --git a/tests/accept.at b/tests/accept.at
new file mode 100644
index 0000000..f76a05a
--- a/dev/null
+++ b/tests/accept.at
@@ -0,0 +1,54 @@
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/>.
16AT_SETUP([accept component])
17AT_CHECK([
18PIES_XFAIL_CHECK
19PIES_CONTROL_INIT
20
21AT_DATA([input],
22[now is
23the time
24stop
25])
26
27: ${PIES_TEST_INET_SOCKET:=unix://$PWD/in.sock}
28
29cat > pies.conf <<_EOT
30component pfd {
31 command "recvfd $auxdir/in.test $PWD/inlog";
32 mode accept;
33 socket "$PIES_TEST_INET_SOCKET";
34 stderr file "$PWD/log.err";
35}
36component controller {
37 command "nt $PIES_TEST_INET_SOCKET -i input";
38}
39_EOT
40
41set -e
42to 10 \
43 pies --foreground --stderr \
44 --config-file control.conf --config-file pies.conf --debug 1 2>errlog
45
46cat inlog
47cat log.err >&2
48],
49[0],
50[now is
51the time
52stop
53])
54AT_CLEANUP \ No newline at end of file
diff --git a/tests/builtin.at b/tests/builtin.at
new file mode 100644
index 0000000..40f65fa
--- a/dev/null
+++ b/tests/builtin.at
@@ -0,0 +1,131 @@
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/>.
16AT_BANNER([inetd built-in services])
17
18# IT_BUILTIN([SERVICE],[INPUT],[OUTPUT])
19m4_define([IT_BUILTIN],
20[AT_SETUP([$1])
21AT_KEYWORDS([inetd builtin internal $1])
22AT_CHECK([
23PIES_XFAIL_CHECK
24PIES_CONTROL_INIT
25AT_DATA([input],
26[$2])
27m4_if([$1],[qotd],[AT_DATA([qotd],[$3])])
28: ${PIES_TEST_INET_SOCKET:=unix://$PWD/in.sock}
29cat > pies.conf <<_EOT
30m4_if([$1],[qotd],[qotd-file "$PWD/qotd";
31])
32component in {
33 mode inetd;
34 socket "$PIES_TEST_INET_SOCKET";
35 flags internal;
36 service $1;
37 stderr file "$PWD/log.err";
38}
39component controller {
40 command "nt $PIES_TEST_INET_SOCKET -i input -o output";
41 return-code * {
42 action disable;
43 exec "piesctl --url '$PIES_CTLSOCK' --no-netrc shutdown";
44 }
45}
46_EOT
47set -e
48to 10 \
49 pies --foreground --stderr \
50 --config-file control.conf --config-file pies.conf --debug 1 2>errlog
51
52cat output m4_if([$1],[qotd],[| tr -d '\r'])
53cat log.err >&2
54],
55[0],
56[$3])
57AT_CLEANUP
58])
59
60# IT_SPECIAL(SERVICE,COMMAND)
61m4_define([IT_SPECIAL],
62[AT_SETUP([$1])
63AT_KEYWORDS([inetd builtin internal $1])
64AT_CHECK([
65PIES_XFAIL_CHECK
66PIES_CONTROL_INIT
67: ${PIES_TEST_INET_SOCKET:=unix://$PWD/in.sock}
68cat > pies.conf <<_EOT
69component in {
70 mode inetd;
71 socket "$PIES_TEST_INET_SOCKET";
72 flags internal;
73 service $1;
74 stderr file "$PWD/in.err";
75}
76component controller {
77 command "$2 '$PIES_TEST_INET_SOCKET'";
78 stderr file "$PWD/controller.err";
79 return-code * {
80 action disable;
81 exec "echo \$PIES_STATUS > $PWD/status ; piesctl --url '$PIES_CTLSOCK' --no-netrc shutdown";
82 }
83}
84_EOT
85set -e
86to 10 \
87 pies --foreground --stderr \
88 --config-file control.conf --config-file pies.conf --debug 1 2>errlog
89
90if test -s in.err; then
91 echo >&2 "in.err:"
92 cat controller.err >&2
93fi
94if test -s controller.err; then
95 echo >&2 "controller.err:"
96 cat controller.err >&2
97fi
98exit `cat status`
99],
100[0])
101AT_CLEANUP
102])
103
104# ##
105IT_BUILTIN([echo],
106[one
107two
108three
109],
110[one
111two
112three
113])
114
115IT_BUILTIN([discard],
116[one
117two
118three
119])
120
121IT_SPECIAL([time],[readtime])
122IT_SPECIAL([daytime],[readtime -H])
123IT_SPECIAL([chargen],[chargen])
124IT_BUILTIN([qotd],[],
125[A useful debugging and measurement tool is a quote of the day service.
126A quote of the day service simply sends a short message without regard
127to the input.
128])
129
130m4_popdef([IT_BUILTIN])
131m4_popdef([IT_SPECIAL])
diff --git a/tests/chargen.c b/tests/chargen.c
new file mode 100644
index 0000000..a3b3290
--- a/dev/null
+++ b/tests/chargen.c
@@ -0,0 +1,109 @@
1/* This file is part of GNU Pies testsuite.
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#include <config.h>
18#include <stdio.h>
19#include <stdlib.h>
20#include <c-ctype.h>
21#include <libpies.h>
22
23enum { LINESIZ = 72 };
24
25static int
26next_char (int stop)
27{
28 static int ch = 0;
29 static int i = 0;
30 static int c;
31 int ret;
32
33 switch (i++)
34 {
35 case 0:
36 do
37 ch = (ch + 1) % 128;
38 while (!c_isprint (ch));
39 if (ch == stop)
40 return 0;
41 c = ch;
42 break;
43
44 case LINESIZ:
45 return '\r';
46
47 case LINESIZ+1:
48 i = 0;
49 return '\n';
50 }
51
52 ret = c;
53 do
54 c = (c + 1) % 128;
55 while (!c_isprint (c));
56
57 return ret;
58}
59
60int
61main (int argc, char **argv)
62{
63 struct pies_url *url;
64 int fd;
65 FILE *fp;
66 unsigned n;
67 int c, first;
68 char *progname = argv[0];
69
70 if (argc != 2)
71 {
72 fprintf (stderr, "usage: %s URL\n", progname);
73 fprintf (stderr, "Tests the character generator protocol\n");
74 return 64;
75 }
76
77 if (pies_url_create (&url, argv[1]))
78 {
79 perror (argv[0]);
80 return 64;
81 }
82
83 fd = url_connect (url, NULL);
84 fp = fdopen (fd, "r");
85
86 first = next_char (0);
87 c = first;
88 do
89 {
90 int in = fgetc (fp);
91 if (in == EOF)
92 {
93 fprintf (stderr, "%s: unexpected EOF in %u\n", progname, n);
94 return 1;
95 }
96 if (in != c)
97 {
98 fprintf (stderr, "%s: got %d instead of %d in %u\n",
99 progname, in, c, n);
100 return 1;
101 }
102 n++;
103 }
104 while ((c = next_char (first)) != 0);
105 return 0;
106}
107
108
109
diff --git a/tests/lines.c b/tests/lines.c
index 106491f..f7f8443 100644
--- a/tests/lines.c
+++ b/tests/lines.c
@@ -1,3 +1,19 @@
1/* This file is part of GNU Pies testsuite.
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
1#include <stdio.h> 17#include <stdio.h>
2 18
3int 19int
@@ -11,6 +27,7 @@ main (int argc, char **argv)
11 if (argc != 2) 27 if (argc != 2)
12 { 28 {
13 fprintf (stderr, "usage: %s FILE\n", progname); 29 fprintf (stderr, "usage: %s FILE\n", progname);
30 fprintf (stderr, "Prints number of lines in FILE.\n");
14 return 1; 31 return 1;
15 } 32 }
16 33
diff --git a/tests/nt.c b/tests/nt.c
index 98a4077..876ffb1 100644
--- a/tests/nt.c
+++ b/tests/nt.c
@@ -311,7 +311,9 @@ redirect (int sfd, char const *name)
311static void 311static void
312usage (FILE *fp) 312usage (FILE *fp)
313{ 313{
314 fprintf (fp, "usage: nt [-i FILE] [-o FILE] URL\n"); 314 fprintf (fp, "usage: nt [-i IFILE] [-o OFILE] URL\n");
315 fprintf (fp, "Reads data from stdin (or IFILE) and sends them to URL.\n");
316 fprintf (fp, "Reads replies from URL and sends them to stdout (or OFILE).\n");
315} 317}
316 318
317int 319int
diff --git a/tests/passfd.at b/tests/passfd.at
index 4a685a3..8a7eecb 100644
--- a/tests/passfd.at
+++ b/tests/passfd.at
@@ -29,7 +29,7 @@ PIES_FD_SOCKET=$PWD/pfd.sock
29 29
30cat > pies.conf <<_EOT 30cat > pies.conf <<_EOT
31component pfd { 31component pfd {
32 command "recvfd '$PIES_FD_SOCKET' $auxdir/in.test $PWD/inlog"; 32 command "recvfd -s '$PIES_FD_SOCKET' $auxdir/in.test $PWD/inlog";
33 mode pass-fd; 33 mode pass-fd;
34 pass-fd-timeout 3; 34 pass-fd-timeout 3;
35 pass-fd-socket "$PIES_FD_SOCKET"; 35 pass-fd-socket "$PIES_FD_SOCKET";
diff --git a/tests/readtime.c b/tests/readtime.c
new file mode 100644
index 0000000..f7cc36a
--- a/dev/null
+++ b/tests/readtime.c
@@ -0,0 +1,161 @@
1/* This file is part of GNU Pies testsuite.
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#include <config.h>
18#include <stdio.h>
19#include <stdlib.h>
20#include <unistd.h>
21#include <time.h>
22#include <locale.h>
23#include <libpies.h>
24
25char *progname;
26int precision = 2;
27
28void
29usage (FILE *fp, int status)
30{
31 fprintf (fp, "usage: %s [-v] [-p PREC] URL\n", progname);
32 fprintf (fp, "Reads time stamp from URL as per RFC868.\n");
33 fprintf (fp, "Exits with status 0 if it is within PREC seconds from the current time.\n");
34 fprintf (fp, "Default PREC is %d seconds.\n", precision);
35 exit (status);
36}
37
38enum { SEVENTY_YEARS = (unsigned long)25567 * 24 * 60 * 60 };
39
40int
41main (int argc, char **argv)
42{
43 int c, fd;
44 struct pies_url *url;
45 time_t now;
46 int human_time = 0;
47 union
48 {
49 char s[80];
50 uint32_t u;
51 } buf;
52 uint32_t t, d;
53 ssize_t n;
54 int verbose = 0;
55
56 progname = argv[0];
57 setlocale (LC_ALL, "C");
58
59 while ((c = getopt (argc, argv, "Hhvp:")) != EOF)
60 {
61 switch (c)
62 {
63 case 'H':
64 human_time = 1;
65 break;
66
67 case 'h':
68 usage (stdout, 0);
69 break;
70
71 case 'p':
72 precision = atoi (optarg);
73 if (precision <= 0)
74 {
75 fprintf (stderr, "%s: bad precision\n", progname);
76 exit (1);
77 }
78 break;
79
80 case 'v':
81 verbose++;
82 break;
83
84 default:
85 exit (64);
86 }
87 }
88
89 argc -= optind;
90 argv += optind;
91
92 if (argc != 1)
93 usage (stderr, 64);
94
95 if (pies_url_create (&url, argv[0]))
96 {
97 perror (argv[0]);
98 return 64;
99 }
100
101 fd = url_connect (url, NULL);
102 time (&now);
103 n = read (fd, &buf, sizeof (buf));
104 if (n == -1)
105 {
106 perror ("read");
107 exit (1);
108 }
109
110 if (human_time)
111 {
112 struct tm daytime;
113 char *p;
114
115 if (buf.s[n-1] == '\n')
116 {
117 buf.s[--n] = 0;
118 if (buf.s[n-1] == '\r')
119 buf.s[--n] = 0;
120 }
121 if (verbose > 1)
122 printf ("got %*.*s\n", (int)n, (int)n, buf.s);
123 p = strptime (buf.s, "%a %b %d %H:%M:%S %Y", &daytime);
124 if (!p)
125 {
126 fprintf (stderr, "%s: unable to parse time '%s'\n", progname, buf.s);
127 exit (1);
128 }
129 if (*p)
130 {
131 fprintf (stderr, "%s: trailing garbage: '%s'\n", progname, p);
132 }
133 t = mktime (&daytime);
134 }
135 else
136 {
137 if (n < sizeof (buf.u))
138 {
139 fprintf (stderr, "%s: read %d bytes\n", progname, (int)n);
140 exit (1);
141 }
142 t = ntohl (buf.u);
143 if (verbose > 1)
144 printf ("got %lu\n", (unsigned long) t);
145 t -= SEVENTY_YEARS;
146 }
147
148 if (t > now)
149 d = t - now;
150 else
151 d = now - t;
152
153 if (d > precision)
154 {
155 fprintf (stderr, "%s: time diff %lu\n", progname, (unsigned long) d);
156 exit (1);
157 }
158 else if (verbose)
159 printf ("OK\n");
160 return 0;
161}
diff --git a/tests/recvfd.c b/tests/recvfd.c
index 82455c7..4da42ca 100644
--- a/tests/recvfd.c
+++ b/tests/recvfd.c
@@ -30,13 +30,13 @@
30char const *progname; 30char const *progname;
31 31
32void 32void
33usage (void) 33usage (FILE *fp, int status)
34{ 34{
35 fprintf (stderr, "usage: %s SOCKET COMMAND ARGS...\n", progname); 35 fprintf (fp, "usage: %s [-s SOCKET] COMMAND ARGS...\n", progname);
36 fprintf (stderr, "Test tool for pass-fd pies components.\n"); 36 fprintf (fp, "Test tool for accept and pass-fd pies components.\n");
37 fprintf (stderr, "Listens on the file descriptor obtained from SOCKET.\n"); 37 fprintf (fp, "Listens on the file descriptor, either 0 or obtained from SOCKET.\n");
38 fprintf (stderr, "For each connection, execs COMMAND ARGS as a separate process.\n"); 38 fprintf (fp, "For each connection, execs COMMAND ARGS as a separate process.\n");
39 exit (64); 39 exit (status);
40} 40}
41 41
42static int 42static int
@@ -162,21 +162,44 @@ sigquit (int sig)
162int 162int
163main (int argc, char **argv) 163main (int argc, char **argv)
164{ 164{
165 int sfd, fd; 165 int c;
166 int fd;
167 char *socket_name = NULL;
166 168
167 progname = argv[0]; 169 progname = argv[0];
168 170
169 if (argc < 3) 171 while ((c = getopt (argc, argv, "hs:")) != EOF)
170 usage (); 172 {
171 173 switch (c)
172 sfd = listen_socket (argv[1]); 174 {
173 175 case 'h':
174 argc -= 2; 176 usage (stdout, 0);
175 argv += 2; 177 break;
176 178
177 fd = get_fd (sfd); 179 case 's':
178 close (sfd); 180 socket_name = optarg;
181 break;
179 182
183 default:
184 exit (64);
185 }
186 }
187
188 argc -= optind;
189 argv += optind;
190
191 if (argc == 0)
192 usage (stderr, 64);
193
194 if (socket_name)
195 {
196 int sfd = listen_socket (socket_name);
197 fd = get_fd (sfd);
198 close (sfd);
199 }
200 else
201 fd = 0;
202
180 signal (SIGCHLD, sigchld); 203 signal (SIGCHLD, sigchld);
181 signal (SIGTERM, sigquit); 204 signal (SIGTERM, sigquit);
182 signal (SIGHUP, sigquit); 205 signal (SIGHUP, sigquit);
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 843d235..5c3f785 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -71,7 +71,9 @@ m4_include([shutdown.at])
71m4_include([shell.at]) 71m4_include([shell.at])
72m4_include([inet.at]) 72m4_include([inet.at])
73m4_include([maxinst.at]) 73m4_include([maxinst.at])
74m4_include([builtin.at])
74m4_include([passfd.at]) 75m4_include([passfd.at])
76m4_include([accept.at])
75 77
76m4_include([envop.at]) 78m4_include([envop.at])
77m4_include([env.at]) \ No newline at end of file 79m4_include([env.at]) \ No newline at end of file
diff --git a/tests/to.c b/tests/to.c
index 0bfabac..78e5f97 100644
--- a/tests/to.c
+++ b/tests/to.c
@@ -51,7 +51,8 @@ main (int argc, char **argv)
51 51
52 if (argc < 3) 52 if (argc < 3)
53 { 53 {
54 fprintf (stderr, "usage: %s TIMEOUT COMMAND ...\n", progname); 54 fprintf (stderr, "usage: %s TIMEOUT COMMAND ARGS...\n", progname);
55 fprintf (stderr, "Runs command with a timeout.\n");
55 exit (1); 56 exit (1);
56 } 57 }
57 errno = 0; 58 errno = 0;

Return to:

Send suggestions and report system problems to the System administrator.