aboutsummaryrefslogtreecommitdiff
path: root/tests/builtin.at
blob: 40f65fa2a1d5f75d1e1b91859be1f2036e83dd80 (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
# 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_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 $PIES_TEST_INET_SOCKET -i input -o output";
  return-code * {
    action disable;
    exec "piesctl --url '$PIES_CTLSOCK' --no-netrc shutdown";
  }	
}
_EOT
set -e
to 10 \
  pies --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' --no-netrc shutdown";
  }
}
_EOT
set -e
to 10 \
  pies --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])

Return to:

Send suggestions and report system problems to the System administrator.