aboutsummaryrefslogtreecommitdiff
path: root/tests/builtin.at
blob: c13b42b687aabcb5432ff0e13a9a7f9f877850d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2016-2023 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_BANNER([inetd built-in services])

# IT_BUILTIN([SERVICE],[INPUT],[OUTPUT])
m4_define([IT_BUILTIN],
[AT_SETUP([$1])
AT_KEYWORDS([inetd builtin internal $1])
AT_CHECK([
PIES_XFAIL_CHECK
PIES_CONTROL_INIT
AT_DATA([input],
[$2])
m4_if([$1],[qotd],[AT_DATA([qotd],[$3])])
: ${PIES_TEST_INET_SOCKET:=unix://$PWD/in.sock}
cat > pies.conf <<_EOT
m4_if([$1],[qotd],[qotd-file "$PWD/qotd";
])
component in {
  mode inetd;
  socket "$PIES_TEST_INET_SOCKET";
  flags internal;
  service $1;
  stderr file "$PWD/log.err";
}
component controller {
  command "nt -i input -o output $PIES_TEST_INET_SOCKET";
  return-code * {
    action disable;
    exec "piesctl --config-file=/dev/null --url '$PIES_CTLSOCK' --config-file=/dev/null --no-netrc shutdown";
  }	
}
_EOT
set -e
to 10 \
  pies --no-preprocessor --foreground --stderr \
       --config-file control.conf --config-file pies.conf --debug 1 2>errlog

cat output m4_if([$1],[qotd],[| tr -d '\r'])
cat log.err >&2
],
[0],
[$3])
AT_CLEANUP
])

# IT_SPECIAL(SERVICE,COMMAND)
m4_define([IT_SPECIAL],
[AT_SETUP([$1])
AT_KEYWORDS([inetd builtin internal $1])
AT_CHECK([
PIES_XFAIL_CHECK
PIES_CONTROL_INIT
: ${PIES_TEST_INET_SOCKET:=unix://$PWD/in.sock}
cat > pies.conf <<_EOT
component in {
  mode inetd;
  socket "$PIES_TEST_INET_SOCKET";
  flags internal;
  service $1;
  stderr file "$PWD/in.err";
}
component controller {
  command "$2 '$PIES_TEST_INET_SOCKET'";
  stderr file "$PWD/controller.err";
  return-code * {
    action disable;
    exec "echo \$PIES_STATUS > $PWD/status ; piesctl --url '$PIES_CTLSOCK' --config-file=/dev/null --no-netrc shutdown";
  }
}
_EOT
TZ=0
export TZ
set -e
to 10 \
  pies --no-preprocessor --foreground --stderr \
       --config-file control.conf --config-file pies.conf --debug 1 2>errlog

if test -s in.err; then
  echo >&2 "in.err:"
  cat controller.err >&2
fi
if test -s controller.err; then
  echo >&2 "controller.err:"
  cat controller.err >&2
fi  
exit `cat status`
],
[0])
AT_CLEANUP
])

# ##
IT_BUILTIN([echo],
[one
two
three
],
[one
two
three
])

IT_BUILTIN([discard],
[one
two
three
])

IT_SPECIAL([time],[readtime])
IT_SPECIAL([daytime],[readtime -H])
IT_SPECIAL([chargen],[chargen])
IT_BUILTIN([qotd],[],
[A useful debugging and measurement tool is a quote of the day service.
A quote of the day service simply sends a short message without regard
to the input.
])

m4_popdef([IT_BUILTIN])
m4_popdef([IT_SPECIAL])

# IT_TCPMUX([KW],[ID],[INPUT],[OUTPUT])
m4_define([IT_TCPMUX],
[AT_SETUP([tcpmux: $1])
AT_KEYWORDS([inetd builtin internal tcpmux $1])
AT_CHECK([
PIES_XFAIL_CHECK
PIES_CONTROL_INIT
: ${PIES_TEST_INET_SOCKET:=unix://$PWD/in.sock}
m4_if([$3],[],[],[AT_DATA([input],[$3])])
cat > pies.conf <<_EOT
component master {
  socket "$PIES_TEST_INET_SOCKET";
  service tcpmux;
  flags internal;
}
component one {
  service one;
  flags (tcpmuxplus);
  tcpmux-master master;
  command "$auxdir/in.test $PWD/one.log";
  stderr file "$PWD/one.err";
}  
component two {
  service two;
  flags (tcpmuxplus);
  tcpmux-master master;
  command "$auxdir/in.test $PWD/two.log";
  stderr file "$PWD/two.err";
}  
component test {
  command "nt -t [$2]m4_if([$3],[],,[ -i $PWD/input]) -o $PWD/test.out '$PIES_TEST_INET_SOCKET'";
  stderr file "$PWD/test.err";
  return-code * {
      action disable;
      exec "piesctl --config-file=/dev/null --no-netrc --url=$PIES_CTLSOCK shutdown";
  }
}
_EOT

set -e
to 10 \
  pies --no-preprocessor --foreground --stderr \
       --config-file control.conf --config-file pies.conf --debug 1 2>errlog

for err in one.err two.err test.err
do
  if test -s $err; then
     echo "$err:"
     cat $err
  fi
done >&2

if test -f test.out; then
  cat test.out | tr -d '\r'
fi  
],
[0],
[$4])
AT_CLEANUP
])

IT_TCPMUX([help],[help],[],
[one
two
])

IT_TCPMUX([service],[one],
[Test one
quit
],
[OK Test one
])

m4_popdef([IT_TCPMUX])


Return to:

Send suggestions and report system problems to the System administrator.