]> git.proxmox.com Git - ovs.git/blame - tests/daemon.at
ofproto: Fix use-after-free error when ports disappear.
[ovs.git] / tests / daemon.at
CommitLineData
99155935 1AT_BANNER([daemon unit tests - C])
ff8decf1
BP
2
3AT_SETUP([daemon])
7c126fbb 4AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ
ff8decf1
BP
5OVSDB_INIT([db])
6AT_CAPTURE_FILE([pid])
7AT_CAPTURE_FILE([expected])
8# Start the daemon and wait for the pidfile to get created
9# and that its contents are the correct pid.
37d03458 10AT_CHECK([ovsdb-server --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db& echo $! > expected], [0])
ff8decf1
BP
11OVS_WAIT_UNTIL([test -s pid], [kill `cat expected`])
12AT_CHECK(
13 [pid=`cat pid` && expected=`cat expected` && test "$pid" = "$expected"],
14 [0], [], [], [kill `cat expected`])
15AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat expected`])
16# Kill the daemon and make sure that the pidfile gets deleted.
17kill `cat expected`
18OVS_WAIT_WHILE([kill -0 `cat expected`])
19AT_CHECK([test ! -e pid])
20AT_CLEANUP
21
22AT_SETUP([daemon --monitor])
7c126fbb 23AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ
ff8decf1
BP
24OVSDB_INIT([db])
25AT_CAPTURE_FILE([pid])
26AT_CAPTURE_FILE([parent])
27AT_CAPTURE_FILE([parentpid])
28AT_CAPTURE_FILE([newpid])
29# Start the daemon and wait for the pidfile to get created.
37d03458 30AT_CHECK([ovsdb-server --monitor --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db& echo $! > parent], [0])
ff8decf1
BP
31OVS_WAIT_UNTIL([test -s pid], [kill `cat parent`])
32# Check that the pidfile names a running process,
33# and that the parent process of that process is our child process.
34AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat parent`])
35AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
36 [0], [], [], [kill `cat parent`])
37AT_CHECK(
38 [parentpid=`cat parentpid` &&
39 parent=`cat parent` &&
40 test $parentpid = $parent],
41 [0], [], [], [kill `cat parent`])
42# Kill the daemon process, making it look like a segfault,
43# and wait for a new child process to get spawned.
44AT_CHECK([cp pid oldpid], [0], [], [], [kill `cat parent`])
45AT_CHECK([kill -SEGV `cat pid`], [0], [], [ignore], [kill `cat parent`])
46OVS_WAIT_WHILE([kill -0 `cat oldpid`], [kill `cat parent`])
47OVS_WAIT_UNTIL([test -s pid && test `cat pid` != `cat oldpid`],
48 [kill `cat parent`])
49AT_CHECK([cp pid newpid], [0], [], [], [kill `cat parent`])
50# Check that the pidfile names a running process,
51# and that the parent process of that process is our child process.
52AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
53 [0], [], [], [kill `cat parent`])
54AT_CHECK(
55 [parentpid=`cat parentpid` &&
56 parent=`cat parent` &&
57 test $parentpid = $parent],
58 [0], [], [], [kill `cat parent`])
59# Kill the daemon process with SIGTERM, and wait for the daemon
60# and the monitor processes to go away and the pidfile to get deleted.
61AT_CHECK([kill `cat pid`], [0], [], [ignore], [kill `cat parent`])
62OVS_WAIT_WHILE([kill -0 `cat parent` || kill -0 `cat newpid` || test -e pid],
63 [kill `cat parent`])
64AT_CLEANUP
65
66AT_SETUP([daemon --detach])
7c126fbb 67AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ
ff8decf1
BP
68AT_CAPTURE_FILE([pid])
69OVSDB_INIT([db])
70# Start the daemon and make sure that the pidfile exists immediately.
71# We don't wait for the pidfile to get created because the daemon is
72# supposed to do so before the parent exits.
37d03458 73AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0])
ff8decf1
BP
74AT_CHECK([test -s pid])
75AT_CHECK([kill -0 `cat pid`])
76# Kill the daemon and make sure that the pidfile gets deleted.
77cp pid saved-pid
78kill `cat pid`
79OVS_WAIT_WHILE([kill -0 `cat saved-pid`])
80AT_CHECK([test ! -e pid])
81AT_CLEANUP
82
83AT_SETUP([daemon --detach --monitor])
7c126fbb 84AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ
ff8decf1
BP
85m4_define([CHECK],
86 [AT_CHECK([$1], [$2], [$3], [$4], [kill `cat daemon monitor`])])
87OVSDB_INIT([db])
88AT_CAPTURE_FILE([daemon])
89AT_CAPTURE_FILE([olddaemon])
90AT_CAPTURE_FILE([newdaemon])
91AT_CAPTURE_FILE([monitor])
92AT_CAPTURE_FILE([newmonitor])
93AT_CAPTURE_FILE([init])
94# Start the daemon and make sure that the pidfile exists immediately.
95# We don't wait for the pidfile to get created because the daemon is
96# supposed to do so before the parent exits.
37d03458 97AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/daemon --monitor --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0])
ff8decf1
BP
98AT_CHECK([test -s daemon])
99# Check that the pidfile names a running process,
100# and that the parent process of that process is a running process,
101# and that the parent process of that process is init.
102CHECK([kill -0 `cat daemon`])
103CHECK([ps -o ppid= -p `cat daemon` > monitor])
104CHECK([kill -0 `cat monitor`])
105CHECK([ps -o ppid= -p `cat monitor` > init])
106CHECK([test `cat init` = 1])
107# Kill the daemon process, making it look like a segfault,
108# and wait for a new daemon process to get spawned.
109CHECK([cp daemon olddaemon])
bc9dcfb3 110CHECK([kill -SEGV `cat daemon`], [0])
ff8decf1
BP
111OVS_WAIT_WHILE([kill -0 `cat olddaemon`], [kill `cat olddaemon daemon`])
112OVS_WAIT_UNTIL([test -s daemon && test `cat daemon` != `cat olddaemon`],
113 [kill `cat olddaemon daemon`])
114CHECK([cp daemon newdaemon])
115# Check that the pidfile names a running process,
116# and that the parent process of that process is our child process.
117CHECK([kill -0 `cat daemon`])
118CHECK([diff olddaemon newdaemon], [1], [ignore])
119CHECK([ps -o ppid= -p `cat daemon` > newmonitor])
120CHECK([diff monitor newmonitor])
121CHECK([kill -0 `cat newmonitor`])
122CHECK([ps -o ppid= -p `cat newmonitor` > init])
123CHECK([test `cat init` = 1])
124# Kill the daemon process with SIGTERM, and wait for the daemon
125# and the monitor processes to go away and the pidfile to get deleted.
126CHECK([kill `cat daemon`], [0], [], [ignore])
127OVS_WAIT_WHILE(
128 [kill -0 `cat monitor` || kill -0 `cat newdaemon` || test -e daemon],
129 [kill `cat monitor newdaemon`])
130m4_undefine([CHECK])
131AT_CLEANUP
132
133AT_SETUP([daemon --detach startup errors])
134AT_CAPTURE_FILE([pid])
135OVSDB_INIT([db])
37d03458 136AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/pid --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr])
ff8decf1
BP
137AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
138 [0], [ignore], [])
139AT_CHECK([test ! -s pid])
140AT_CLEANUP
141
142AT_SETUP([daemon --detach --monitor startup errors])
143AT_CAPTURE_FILE([pid])
144OVSDB_INIT([db])
37d03458 145AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/pid --monitor --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr])
ff8decf1
BP
146AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
147 [0], [ignore], [])
148AT_CHECK([test ! -s pid])
149AT_CLEANUP
150
bfee9bd6
JP
151# xxx This test hangs frequently, which often prevents builds from
152# xxx completing. Skip this test until we have time to debug it.
ff8decf1 153AT_SETUP([daemon --detach closes standard fds])
bfee9bd6 154AT_SKIP_IF([:])
ff8decf1 155AT_CAPTURE_FILE([pid])
cfcef6b2
BP
156AT_CAPTURE_FILE([status])
157AT_CAPTURE_FILE([stderr])
ff8decf1 158OVSDB_INIT([db])
37d03458 159AT_CHECK([(yes 2>stderr; echo $? > status) | ovsdb-server --detach --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl db], [0], [], [])
ff8decf1
BP
160AT_CHECK([kill `cat pid`])
161AT_CHECK([test -s status])
cfcef6b2
BP
162if grep '[[bB]]roken pipe' stderr >/dev/null 2>&1; then
163 # Something in the environment caused SIGPIPE to be ignored, but
164 # 'yes' at least told us that it got EPIPE. Good enough; we know
165 # that stdout was closed.
166 :
167else
168 # Otherwise make sure that 'yes' died from SIGPIPE.
169 AT_CHECK([kill -l `cat status`], [0], [PIPE
ff8decf1 170])
cfcef6b2 171fi
ff8decf1
BP
172AT_CLEANUP
173
bfee9bd6
JP
174# xxx This test hangs frequently, which often prevents builds from
175# xxx completing. Skip this test until we have time to debug it.
ff8decf1 176AT_SETUP([daemon --detach --monitor closes standard fds])
bfee9bd6 177AT_SKIP_IF([:])
ff8decf1 178AT_CAPTURE_FILE([pid])
cfcef6b2
BP
179AT_CAPTURE_FILE([status])
180AT_CAPTURE_FILE([stderr])
ff8decf1 181OVSDB_INIT([db])
37d03458 182AT_CHECK([(yes 2>stderr; echo $? > status) | ovsdb-server --detach --monitor --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl db], [0], [], [])
ff8decf1
BP
183AT_CHECK([kill `cat pid`])
184AT_CHECK([test -s status])
cfcef6b2
BP
185if grep '[[bB]]roken pipe' stderr >/dev/null 2>&1; then
186 # Something in the environment caused SIGPIPE to be ignored, but
187 # 'yes' at least told us that it got EPIPE. Good enough; we know
188 # that stdout was closed.
189 :
190else
191 # Otherwise make sure that 'yes' died from SIGPIPE.
192 AT_CHECK([kill -l `cat status`], [0], [PIPE
ff8decf1 193])
cfcef6b2 194fi
ff8decf1 195AT_CLEANUP