]>
Commit | Line | Data |
---|---|---|
99155935 | 1 | AT_BANNER([daemon unit tests - C]) |
ff8decf1 BP |
2 | |
3 | AT_SETUP([daemon]) | |
7c126fbb | 4 | AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ |
ff8decf1 BP |
5 | OVSDB_INIT([db]) |
6 | AT_CAPTURE_FILE([pid]) | |
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. | |
37d03458 | 10 | AT_CHECK([ovsdb-server --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db& echo $! > expected], [0]) |
ff8decf1 BP |
11 | OVS_WAIT_UNTIL([test -s pid], [kill `cat expected`]) |
12 | AT_CHECK( | |
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. | |
17 | kill `cat expected` | |
18 | OVS_WAIT_WHILE([kill -0 `cat expected`]) | |
19 | AT_CHECK([test ! -e pid]) | |
20 | AT_CLEANUP | |
21 | ||
22 | AT_SETUP([daemon --monitor]) | |
7c126fbb | 23 | AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ |
ff8decf1 BP |
24 | OVSDB_INIT([db]) |
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. | |
37d03458 | 30 | AT_CHECK([ovsdb-server --monitor --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db& echo $! > parent], [0]) |
ff8decf1 BP |
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`]) | |
37 | AT_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. | |
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`], | |
48 | [kill `cat parent`]) | |
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`]) | |
54 | AT_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. | |
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], | |
63 | [kill `cat parent`]) | |
64 | AT_CLEANUP | |
65 | ||
66 | AT_SETUP([daemon --detach]) | |
7c126fbb | 67 | AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ |
ff8decf1 BP |
68 | AT_CAPTURE_FILE([pid]) |
69 | OVSDB_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 | 73 | AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0]) |
ff8decf1 BP |
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. | |
77 | cp pid saved-pid | |
78 | kill `cat pid` | |
79 | OVS_WAIT_WHILE([kill -0 `cat saved-pid`]) | |
80 | AT_CHECK([test ! -e pid]) | |
81 | AT_CLEANUP | |
82 | ||
83 | AT_SETUP([daemon --detach --monitor]) | |
7c126fbb | 84 | AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ |
ff8decf1 BP |
85 | m4_define([CHECK], |
86 | [AT_CHECK([$1], [$2], [$3], [$4], [kill `cat daemon monitor`])]) | |
87 | OVSDB_INIT([db]) | |
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. | |
37d03458 | 97 | AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/daemon --monitor --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0]) |
ff8decf1 BP |
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]) | |
bc9dcfb3 | 110 | CHECK([kill -SEGV `cat daemon`], [0]) |
ff8decf1 BP |
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]) | |
127 | OVS_WAIT_WHILE( | |
128 | [kill -0 `cat monitor` || kill -0 `cat newdaemon` || test -e daemon], | |
129 | [kill `cat monitor newdaemon`]) | |
130 | m4_undefine([CHECK]) | |
131 | AT_CLEANUP | |
132 | ||
133 | AT_SETUP([daemon --detach startup errors]) | |
134 | AT_CAPTURE_FILE([pid]) | |
135 | OVSDB_INIT([db]) | |
37d03458 | 136 | AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/pid --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr]) |
ff8decf1 BP |
137 | AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr], |
138 | [0], [ignore], []) | |
139 | AT_CHECK([test ! -s pid]) | |
140 | AT_CLEANUP | |
141 | ||
142 | AT_SETUP([daemon --detach --monitor startup errors]) | |
143 | AT_CAPTURE_FILE([pid]) | |
144 | OVSDB_INIT([db]) | |
37d03458 | 145 | AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/pid --monitor --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr]) |
ff8decf1 BP |
146 | AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr], |
147 | [0], [ignore], []) | |
148 | AT_CHECK([test ! -s pid]) | |
149 | AT_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 | 153 | AT_SETUP([daemon --detach closes standard fds]) |
bfee9bd6 | 154 | AT_SKIP_IF([:]) |
ff8decf1 | 155 | AT_CAPTURE_FILE([pid]) |
cfcef6b2 BP |
156 | AT_CAPTURE_FILE([status]) |
157 | AT_CAPTURE_FILE([stderr]) | |
ff8decf1 | 158 | OVSDB_INIT([db]) |
37d03458 | 159 | AT_CHECK([(yes 2>stderr; echo $? > status) | ovsdb-server --detach --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl db], [0], [], []) |
ff8decf1 BP |
160 | AT_CHECK([kill `cat pid`]) |
161 | AT_CHECK([test -s status]) | |
cfcef6b2 BP |
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. | |
166 | : | |
167 | else | |
168 | # Otherwise make sure that 'yes' died from SIGPIPE. | |
169 | AT_CHECK([kill -l `cat status`], [0], [PIPE | |
ff8decf1 | 170 | ]) |
cfcef6b2 | 171 | fi |
ff8decf1 BP |
172 | AT_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 | 176 | AT_SETUP([daemon --detach --monitor closes standard fds]) |
bfee9bd6 | 177 | AT_SKIP_IF([:]) |
ff8decf1 | 178 | AT_CAPTURE_FILE([pid]) |
cfcef6b2 BP |
179 | AT_CAPTURE_FILE([status]) |
180 | AT_CAPTURE_FILE([stderr]) | |
ff8decf1 | 181 | OVSDB_INIT([db]) |
37d03458 | 182 | AT_CHECK([(yes 2>stderr; echo $? > status) | ovsdb-server --detach --monitor --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl db], [0], [], []) |
ff8decf1 BP |
183 | AT_CHECK([kill `cat pid`]) |
184 | AT_CHECK([test -s status]) | |
cfcef6b2 BP |
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. | |
189 | : | |
190 | else | |
191 | # Otherwise make sure that 'yes' died from SIGPIPE. | |
192 | AT_CHECK([kill -l `cat status`], [0], [PIPE | |
ff8decf1 | 193 | ]) |
cfcef6b2 | 194 | fi |
ff8decf1 | 195 | AT_CLEANUP |