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 # Kill the daemon process, making it look like a segfault,
43 # and wait for a new child process to get spawned.
44 AT_CHECK([cp pid oldpid], [0], [], [], [kill `cat parent`])
45 AT_CHECK([kill -SEGV `cat pid`], [0], [], [ignore], [kill `cat parent`])
46 OVS_WAIT_WHILE([kill -0 `cat oldpid`], [kill `cat parent`])
47 OVS_WAIT_UNTIL([test -s pid && test `cat pid` != `cat oldpid`],
49 AT_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.
52 AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
53 [0], [], [], [kill `cat parent`])
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.
61 AT_CHECK([kill `cat pid`], [0], [], [ignore], [kill `cat parent`])
62 OVS_WAIT_WHILE([kill -0 `cat parent` || kill -0 `cat newpid` || test -e pid],
66 AT_SETUP([daemon --detach])
67 AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ
68 AT_CAPTURE_FILE([pid])
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.
73 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --remote=punix:socket --unixctl=$PWD/unixctl db], [0])
74 AT_CHECK([test -s pid])
75 AT_CHECK([kill -0 `cat pid`])
76 # Kill the daemon and make sure that the pidfile gets deleted.
79 OVS_WAIT_WHILE([kill -0 `cat saved-pid`])
80 AT_CHECK([test ! -e pid])
83 AT_SETUP([daemon --detach --monitor])
84 AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ
86 [AT_CHECK([$1], [$2], [$3], [$4], [kill `cat daemon monitor`])])
88 AT_CAPTURE_FILE([daemon])
89 AT_CAPTURE_FILE([olddaemon])
90 AT_CAPTURE_FILE([newdaemon])
91 AT_CAPTURE_FILE([monitor])
92 AT_CAPTURE_FILE([newmonitor])
93 AT_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.
97 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/daemon --monitor --remote=punix:socket --unixctl=$PWD/unixctl db], [0])
98 AT_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.
102 CHECK([kill -0 `cat daemon`])
103 CHECK([ps -o ppid= -p `cat daemon` > monitor])
104 CHECK([kill -0 `cat monitor`])
105 CHECK([ps -o ppid= -p `cat monitor` > init])
106 CHECK([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.
109 CHECK([cp daemon olddaemon])
110 CHECK([kill -SEGV `cat daemon`], [0])
111 OVS_WAIT_WHILE([kill -0 `cat olddaemon`], [kill `cat olddaemon daemon`])
112 OVS_WAIT_UNTIL([test -s daemon && test `cat daemon` != `cat olddaemon`],
113 [kill `cat olddaemon daemon`])
114 CHECK([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.
117 CHECK([kill -0 `cat daemon`])
118 CHECK([diff olddaemon newdaemon], [1], [ignore])
119 CHECK([ps -o ppid= -p `cat daemon` > newmonitor])
120 CHECK([diff monitor newmonitor])
121 CHECK([kill -0 `cat newmonitor`])
122 CHECK([ps -o ppid= -p `cat newmonitor` > init])
123 CHECK([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.
126 CHECK([kill `cat daemon`], [0], [], [ignore])
128 [kill -0 `cat monitor` || kill -0 `cat newdaemon` || test -e daemon],
129 [kill `cat monitor newdaemon`])
133 AT_SETUP([daemon --detach startup errors])
134 AT_CAPTURE_FILE([pid])
136 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/nonexistent/unixctl db], [1], [], [stderr])
137 AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
139 AT_CHECK([test ! -s pid])
142 AT_SETUP([daemon --detach --monitor startup errors])
143 AT_CAPTURE_FILE([pid])
145 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --monitor --unixctl=$PWD/nonexistent/unixctl db], [1], [], [stderr])
146 AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
148 AT_CHECK([test ! -s pid])
151 # xxx This test hangs frequently, which often prevents builds from
152 # xxx completing. Skip this test until we have time to debug it.
153 AT_SETUP([daemon --detach closes standard fds])
155 AT_CAPTURE_FILE([pid])
156 AT_CAPTURE_FILE([status])
157 AT_CAPTURE_FILE([stderr])
159 AT_CHECK([(yes 2>stderr; echo $? > status) | ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/unixctl db], [0], [], [])
160 AT_CHECK([kill `cat pid`])
161 AT_CHECK([test -s status])
162 if 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.
168 # Otherwise make sure that 'yes' died from SIGPIPE.
169 AT_CHECK([kill -l `cat status`], [0], [PIPE
174 # xxx This test hangs frequently, which often prevents builds from
175 # xxx completing. Skip this test until we have time to debug it.
176 AT_SETUP([daemon --detach --monitor closes standard fds])
178 AT_CAPTURE_FILE([pid])
179 AT_CAPTURE_FILE([status])
180 AT_CAPTURE_FILE([stderr])
182 AT_CHECK([(yes 2>stderr; echo $? > status) | ovsdb-server --detach --monitor --pidfile=$PWD/pid --unixctl=$PWD/unixctl db], [0], [], [])
183 AT_CHECK([kill `cat pid`])
184 AT_CHECK([test -s status])
185 if 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.
191 # Otherwise make sure that 'yes' died from SIGPIPE.
192 AT_CHECK([kill -l `cat status`], [0], [PIPE