aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-06-11 17:30:25 +0300
committerSergey Poznyakoff <gray@gnu.org>2019-06-11 17:30:25 +0300
commit07e7ee3d732b60e0b7f5b242bbfb0cdec8e99e7f (patch)
treed8106ba7d4e4e92f4bb4f49427eb6e2db10897a3 /tests
parentbf6506cdc46446eada5090a428c2407ebd17468a (diff)
downloadpies-07e7ee3d732b60e0b7f5b242bbfb0cdec8e99e7f.tar.gz
pies-07e7ee3d732b60e0b7f5b242bbfb0cdec8e99e7f.tar.bz2
Test pass-fd components
* tests/recvfd.c: New source. * tests/.gitignore: Update. * tests/passfd.at: New test. * tests/Makefile.am: Add new test. * tests/testsuite.at: Add new test. * tests/nt.c: Check all revents bits.
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/nt.c10
-rw-r--r--tests/passfd.at57
-rw-r--r--tests/recvfd.c223
-rw-r--r--tests/testsuite.at1
-rw-r--r--tests/to.c16
7 files changed, 305 insertions, 6 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 68159e3..7d2613a 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -8,3 +8,4 @@ testsuite.dir
8testsuite.log 8testsuite.log
9to 9to
10nt 10nt
11recvfd
diff --git a/tests/Makefile.am b/tests/Makefile.am
index fa1d6be..1fe78dc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -55,6 +55,7 @@ TESTSUITE_AT = \
55 envop.at\ 55 envop.at\
56 inet.at\ 56 inet.at\
57 maxinst.at\ 57 maxinst.at\
58 passfd.at\
58 respawn.at\ 59 respawn.at\
59 redirect.at\ 60 redirect.at\
60 ret-exec.at\ 61 ret-exec.at\
@@ -67,7 +68,7 @@ TESTSUITE_AT = \
67TESTSUITE = $(srcdir)/testsuite 68TESTSUITE = $(srcdir)/testsuite
68M4=m4 69M4=m4
69 70
70noinst_PROGRAMS = envtest to lines nt 71noinst_PROGRAMS = envtest to lines nt recvfd
71nt_SOURCES = nt.c iobuf.h 72nt_SOURCES = nt.c iobuf.h
72AM_CPPFLAGS = \ 73AM_CPPFLAGS = \
73 -I$(top_srcdir)/lib\ 74 -I$(top_srcdir)/lib\
diff --git a/tests/nt.c b/tests/nt.c
index d30e447..98a4077 100644
--- a/tests/nt.c
+++ b/tests/nt.c
@@ -1,4 +1,4 @@
1/* This file is part of GNU Pies. 1/* This file is part of GNU Pies testsuite.
2 Copyright (C) 2019 Sergey Poznyakoff 2 Copyright (C) 2019 Sergey Poznyakoff
3 3
4 GNU Pies is free software; you can redistribute it and/or modify 4 GNU Pies is free software; you can redistribute it and/or modify
@@ -272,15 +272,15 @@ netcat (char const *urlstr)
272 & (srv->state | ((srv->state & POLLOUT) ? POLLHUP : 0))); 272 & (srv->state | ((srv->state & POLLOUT) ? POLLHUP : 0)));
273 if (events) 273 if (events)
274 { 274 {
275 if (events & POLLIN)
276 netcat_stream_read (srv);
277 if (events & POLLOUT)
278 netcat_stream_write (srv);
275 if (events & POLLHUP) 279 if (events & POLLHUP)
276 { 280 {
277 //grecs_error (NULL, 0, "HUP on %s", srv->id); 281 //grecs_error (NULL, 0, "HUP on %s", srv->id);
278 netcat_stream_disconnect (srv, srv->state); 282 netcat_stream_disconnect (srv, srv->state);
279 } 283 }
280 else if (events & POLLIN)
281 netcat_stream_read (srv);
282 else if (events & POLLOUT)
283 netcat_stream_write (srv);
284 } 284 }
285 if (srv->state == 0 || srv->pollfd->fd == -1) 285 if (srv->state == 0 || srv->pollfd->fd == -1)
286 netcat_server_remove (srv); 286 netcat_server_remove (srv);
diff --git a/tests/passfd.at b/tests/passfd.at
new file mode 100644
index 0000000..4a685a3
--- /dev/null
+++ b/tests/passfd.at
@@ -0,0 +1,57 @@
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_SETUP([pass-fd 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}
28PIES_FD_SOCKET=$PWD/pfd.sock
29
30cat > pies.conf <<_EOT
31component pfd {
32 command "recvfd '$PIES_FD_SOCKET' $auxdir/in.test $PWD/inlog";
33 mode pass-fd;
34 pass-fd-timeout 3;
35 pass-fd-socket "$PIES_FD_SOCKET";
36 socket "$PIES_TEST_INET_SOCKET";
37 stderr file "$PWD/log.err";
38}
39component controller {
40 command "nt $PIES_TEST_INET_SOCKET -i input";
41}
42_EOT
43
44set -e
45to 10 \
46 pies --foreground --stderr \
47 --config-file control.conf --config-file pies.conf --debug 1 2>errlog
48
49cat inlog
50cat log.err >&2
51],
52[0],
53[now is
54the time
55stop
56])
57AT_CLEANUP \ No newline at end of file
diff --git a/tests/recvfd.c b/tests/recvfd.c
new file mode 100644
index 0000000..82455c7
--- /dev/null
+++ b/tests/recvfd.c
@@ -0,0 +1,223 @@
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 <errno.h>
22#include <sys/types.h>
23#include <sys/socket.h>
24#include <sys/un.h>
25#include <sys/stat.h>
26#include <sys/wait.h>
27#include <signal.h>
28#include "libpies.h"
29
30char const *progname;
31
32void
33usage (void)
34{
35 fprintf (stderr, "usage: %s SOCKET COMMAND ARGS...\n", progname);
36 fprintf (stderr, "Test tool for pass-fd pies components.\n");
37 fprintf (stderr, "Listens on the file descriptor obtained from SOCKET.\n");
38 fprintf (stderr, "For each connection, execs COMMAND ARGS as a separate process.\n");
39 exit (64);
40}
41
42static int
43listen_socket (char const *socket_name)
44{
45 struct sockaddr_un addr;
46 int sockfd;
47
48 if (strlen (socket_name) > sizeof addr.sun_path)
49 {
50 fprintf (stderr, "%s: UNIX socket name too long\n", progname);
51 return -1;
52 }
53 addr.sun_family = AF_UNIX;
54 strcpy (addr.sun_path, socket_name);
55
56 sockfd = socket (PF_UNIX, SOCK_STREAM, 0);
57 if (sockfd == -1)
58 {
59 perror ("socket");
60 exit (1);
61 }
62
63 umask (0117);
64 if (bind (sockfd, (struct sockaddr *) &addr, sizeof (addr)) < 0)
65 {
66 perror ("bind");
67 exit (1);
68 }
69
70 if (listen (sockfd, 8) < 0)
71 {
72 perror ("listen");
73 exit (1);
74 }
75 return sockfd;
76}
77
78static int
79read_fd (int fd)
80{
81 struct msghdr msg;
82 struct iovec iov[1];
83 char base[1];
84
85#if HAVE_STRUCT_MSGHDR_MSG_CONTROL
86 union
87 {
88 struct cmsghdr cm;
89 char control[CMSG_SPACE (sizeof (int))];
90 } control_un;
91 struct cmsghdr *cmptr;
92
93 msg.msg_control = control_un.control;
94 msg.msg_controllen = sizeof (control_un.control);
95#elif HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS
96 int newfd;
97
98 msg.msg_accrights = (caddr_t) &newfd;
99 msg.msg_accrightslen = sizeof (int);
100#else
101 fprintf (stderr, "no way to get fd\n");
102 exit (77);
103#endif
104
105 msg.msg_name = NULL;
106 msg.msg_namelen = 0;
107
108 iov[0].iov_base = base;
109 iov[0].iov_len = sizeof (base);
110
111 msg.msg_iov = iov;
112 msg.msg_iovlen = 1;
113
114 if (recvmsg (fd, &msg, 0) > 0)
115 {