1 AT_BANNER([daemon unit tests - C])
4 AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ
7 AT_CAPTURE_FILE([expected])
8 # Start the daemon and wait for the pidfile to get created
9 # and that its contents are the correct pid.
10 AT_CHECK([ovsdb-server --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db& echo $! > expected], [0])
11 OVS_WAIT_UNTIL([test -s pid], [kill `cat expected`])
13 [pid=`cat pid` && expected=`cat expected` && test "$pid" = "$expected"],
14 [0], [], [], [kill `cat expected`])
15 AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat expected`])
16 # Kill the daemon and make sure that the pidfile gets deleted.
18 OVS_WAIT_WHILE([kill -0 `cat expected`])
19 AT_CHECK([test ! -e pid])
22 AT_SETUP([daemon --monitor])
23 AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ
25 AT_CAPTURE_FILE([pid])
26 AT_CAPTURE_FILE([parent])
27 AT_CAPTURE_FILE([parentpid])
28 AT_CAPTURE_FILE([newpid])
29 # Start the daemon and wait for the pidfile to get created.
30 AT_CHECK([ovsdb-server --monitor --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db& echo $! > parent], [0])
31 OVS_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.
34 AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat parent`])
35 AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
36 [0], [], [], [kill `cat parent`])
38 [parentpid=`cat parentpid` &&
39 parent=`cat parent` &&
40 test $parentpid = $parent],
41 [0], [], [], [kill `cat parent`])
42 # Avoid a race between pidfile creation and notifying the parent,
43 # which can easily trigger if ovsdb-server is slow (e.g. due to valgrind).
45 [ovs-appctl --timeout=10 -t "`pwd`/unixctl" version],
47 # Kill the daemon process, making it look like a segfault,
48 # and wait for a new child process to get spawned.
49 AT_CHECK([cp pid oldpid], [0], [], [], [kill `cat parent`])
50 AT_CHECK([kill -SEGV `cat pid`], [0], [], [ignore], [kill `cat parent`])
51 OVS_WAIT_WHILE([kill -0 `cat oldpid`], [kill `cat parent`])
52 OVS_WAIT_UNTIL([test -s pid && test `cat pid` != `cat oldpid`],
54 AT_CHECK([cp pid newpid], [0], [], [], [kill `cat parent`])
55 # Check that the pidfile names a running process,
56 # and that the parent process of that process is our child process.
57 AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
58 [0], [], [], [kill `cat parent`])
60 [parentpid=`cat parentpid` &&
61 parent=`cat parent` &&
62 test $parentpid = $parent],
63 [0], [], [], [kill `cat parent`])
64 # Kill the daemon process with SIGTERM, and wait for the daemon
65 # and the monitor processes to go away and the pidfile to get deleted.
66 AT_CHECK([kill `cat pid`], [0], [], [ignore], [kill `cat parent`])
67 OVS_WAIT_WHILE([kill -0 `cat parent` || kill -0 `cat newpid` || test -e pid],
71 AT_SETUP([daemon --detach])
72 AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ
73 AT_CAPTURE_FILE([pid])
75 # Start the daemon and make sure that the pidfile exists immediately.
76 # We don't wait for the pidfile to get created because the daemon is
77 # supposed to do so before the parent exits.
78 AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0])
79 AT_CHECK([test -s pid])
80 AT_CHECK([kill -0 `cat pid`])
81 # Kill the daemon and make sure that the pidfile gets deleted.
84 OVS_WAIT_WHILE([kill -0 `cat saved-pid`])
85 AT_CHECK([test ! -e pid])
88 AT_SETUP([daemon --detach --monitor])
89 AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ
91 [AT_CHECK([$1], [$2], [$3], [$4], [kill `cat daemon monitor`])])
93 AT_CAPTURE_FILE([daemon])
94 AT_CAPTURE_FILE([olddaemon])
95 AT_CAPTURE_FILE([newdaemon])
96 AT_CAPTURE_FILE([monitor])
97 AT_CAPTURE_FILE([newmonitor])
98 AT_CAPTURE_FILE([init])
99 # Start the daemon and make sure that the pidfile exists immediately.
100 # We don't wait for the pidfile to get created because the daemon is
101 # supposed to do so before the parent exits.
102 AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/daemon --monitor --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0])
103 AT_CHECK([test -s daemon])
104 # Check that the pidfile names a running process,
105 # and that the parent process of that process is a running process,
106 # and that the parent process of that process is init.
107 CHECK([kill -0 `cat daemon`])
108 CHECK([ps -o ppid= -p `cat daemon` > monitor])
109 CHECK([kill -0 `cat monitor`])
110 CHECK([ps -o ppid= -p `cat monitor` > init])
111 CHECK([test `cat init` = 1])
112 # Kill the daemon process, making it look like a segfault,
113 # and wait for a new daemon process to get spawned.
114 CHECK([cp daemon olddaemon])
115 CHECK([kill -SEGV `cat daemon`], [0])
116 OVS_WAIT_WHILE([kill -0 `cat olddaemon`], [kill `cat olddaemon daemon`])
117 OVS_WAIT_UNTIL([test -s daemon && test `cat daemon` != `cat olddaemon`],
118 [kill `cat olddaemon daemon`])
119 CHECK([cp daemon newdaemon])
120 # Check that the pidfile names a running process,
121 # and that the parent process of that process is our child process.
122 CHECK([kill -0 `cat daemon`])
123 CHECK([diff olddaemon newdaemon], [1], [ignore])
124 CHECK([ps -o ppid= -p `cat daemon` > newmonitor])
125 CHECK([diff monitor newmonitor])
126 CHECK([kill -0 `cat newmonitor`])
127 CHECK([ps -o ppid= -p `cat newmonitor` > init])
128 CHECK([test `cat init` = 1])
129 # Kill the daemon process with SIGTERM, and wait for the daemon
130 # and the monitor processes to go away and the pidfile to get deleted.
131 CHECK([kill `cat daemon`], [0], [], [ignore])
133 [kill -0 `cat monitor` || kill -0 `cat newdaemon` || test -e daemon],
134 [kill `cat monitor newdaemon`])
138 AT_SETUP([daemon --detach startup errors])
139 AT_CAPTURE_FILE([pid])
141 AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/pid --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr])
142 AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
144 AT_CHECK([test ! -s pid])
147 AT_SETUP([daemon --detach --monitor startup errors])
148 AT_CAPTURE_FILE([pid])
150 AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/pid --monitor --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr])
151 AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
153 AT_CHECK([test ! -s pid])
156 # xxx This test hangs frequently, which often prevents builds from
157 # xxx completing. Skip this test until we have time to debug it.
158 AT_SETUP([daemon --detach closes standard fds])
160 AT_CAPTURE_FILE([pid])
161 AT_CAPTURE_FILE([status])
162 AT_CAPTURE_FILE([stderr])
164 AT_CHECK([(yes 2>stderr; echo $? > status) | ovsdb-server --detach --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl db], [0], [], [])
165 AT_CHECK([kill `cat pid`])
166 AT_CHECK([test -s status])
167 if grep '[[bB]]roken pipe' stderr >/dev/null 2>&1; then
168 # Something in the environment caused SIGPIPE to be ignored, but
169 # 'yes' at least told us that it got EPIPE. Good enough; we know
170 # that stdout was closed.
173 # Otherwise make sure that 'yes' died from SIGPIPE.
174 AT_CHECK([kill -l `cat status`], [0], [PIPE
179 # xxx This test hangs frequently, which often prevents builds from
180 # xxx completing. Skip this test until we have time to debug it.
181 AT_SETUP([daemon --detach --monitor closes standard fds])
183 AT_CAPTURE_FILE([pid])
184 AT_CAPTURE_FILE([status])
185 AT_CAPTURE_FILE([stderr])
187 AT_CHECK([(yes 2>stderr; echo $? > status) | ovsdb-server --detach --monitor --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl db], [0], [], [])
188 AT_CHECK([kill `cat pid`])
189 AT_CHECK([test -s status])
190 if grep '[[bB]]roken pipe' stderr >/dev/null 2>&1; then
191 # Something in the environment caused SIGPIPE to be ignored, but
192 # 'yes' at least told us that it got EPIPE. Good enough; we know
193 # that stdout was closed.
196 # Otherwise make sure that 'yes' died from SIGPIPE.
197 AT_CHECK([kill -l `cat status`], [0], [PIPE