]>
Commit | Line | Data |
---|---|---|
99155935 | 1 | AT_BANNER([daemon unit tests - C]) |
ff8decf1 | 2 | |
d8c6955a BP |
3 | OVS_START_SHELL_HELPERS |
4 | # check_process_name PID NAME | |
5 | # | |
6 | # On Linux, make sure that the name of process PID is NAME. | |
7 | # (On other systems, don't bother.) | |
8 | if test -e /proc/$$/comm; then | |
9 | check_process_name() { | |
789aecd8 BP |
10 | # In case we're building with shared libraries enabled, strip |
11 | # off libtool's lt- prefix. | |
12 | AT_CHECK_UNQUOTED([sed 's/lt-//' /proc/$1/comm], [0], [$2 | |
d8c6955a BP |
13 | ]) |
14 | } | |
15 | else | |
16 | check_process_name() { | |
17 | : | |
18 | } | |
19 | fi | |
20 | ||
21 | # check_ancestors PID PARENT [GRANDPARENT...] | |
22 | check_ancestors() { | |
23 | echo "checking ancestry: $*" | |
24 | local child=$1; shift | |
25 | AT_CHECK([kill -0 $child]) | |
26 | while test $# != 0; do | |
27 | local parent=$1; shift | |
28 | AT_CHECK([parent_pid $child], [0], [stdout]) | |
29 | actual_parent=$(cat stdout) | |
30 | if test $parent = 1; then | |
31 | # Traditionally, if a parent's process exits, the process's new | |
32 | # parent is pid 1 (init) but this is not always the case these | |
33 | # days. Instead, if the parent process should be pid 1, be | |
34 | # satisfied if the parent process is different from our own pid. | |
35 | if test $actual_parent = $$; then | |
36 | echo "parent of pid $child is this shell ($$) but should not be" | |
37 | AT_FAIL_IF([:]) | |
38 | fi | |
39 | elif test $parent != $actual_parent; then | |
40 | echo "parent of pid $child is $actual_parent but should be $parent" | |
41 | AT_FAIL_IF([:]) | |
42 | fi | |
43 | child=$parent | |
44 | done | |
45 | } | |
46 | OVS_END_SHELL_HELPERS | |
47 | ||
ff8decf1 | 48 | AT_SETUP([daemon]) |
fc28ea52 | 49 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) |
ab7fc30e PB |
50 | |
51 | dnl OVS_SKIP_NON_ADMIN_WIN() | |
52 | dnl | |
53 | dnl Checks if we have enough rights to create a service | |
54 | m4_define([OVS_SKIP_NON_ADMIN_WIN], | |
55 | [ | |
56 | AT_SKIP_IF([net session; test $? -ne 0]) | |
57 | ]) | |
58 | ||
ff8decf1 BP |
59 | # Start the daemon and wait for the pidfile to get created |
60 | # and that its contents are the correct pid. | |
d8c6955a BP |
61 | on_exit 'kill $(cat *.pid)' |
62 | AT_CHECK([ovsdb-server --pidfile --no-db 2>/dev/null & echo $!], [0], [stdout]) | |
63 | expected_pid=$(cat stdout) | |
64 | ||
56120500 | 65 | OVS_WAIT_UNTIL([test -s ovsdb-server.pid]) |
d8c6955a BP |
66 | pid=$(cat ovsdb-server.pid) |
67 | ||
68 | AT_CHECK([test $pid = $expected_pid]) | |
69 | AT_CHECK([kill -0 $pid]) | |
70 | ||
ff8decf1 | 71 | # Kill the daemon and make sure that the pidfile gets deleted. |
d8c6955a BP |
72 | AT_CHECK([kill $pid]) |
73 | OVS_WAIT_WHILE([kill -0 $pid]) | |
74 | ||
56120500 | 75 | AT_CHECK([test ! -e ovsdb-server.pid]) |
ff8decf1 BP |
76 | AT_CLEANUP |
77 | ||
78 | AT_SETUP([daemon --monitor]) | |
fc28ea52 | 79 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) |
5f223e92 BP |
80 | |
81 | # This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it. | |
82 | ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS | |
83 | ||
ff8decf1 | 84 | # Start the daemon and wait for the pidfile to get created. |
d8c6955a BP |
85 | on_exit 'kill $(cat *.pid)' |
86 | AT_CHECK([ovsdb-server --monitor --pidfile --no-db 2>/dev/null & echo $!], | |
87 | [0], [stdout]) | |
88 | parent=$(cat stdout) | |
89 | OVS_WAIT_UNTIL([test -s ovsdb-server.pid]) | |
90 | ||
ff8decf1 | 91 | # Check that the pidfile names a running process, |
d8c6955a BP |
92 | # and that the parent process of that process is our child process, |
93 | # and that (with a Linux kernel) the child's process name is correct. | |
94 | child=$(cat ovsdb-server.pid) | |
95 | check_ancestors $child $parent | |
96 | check_process_name $child ovsdb-server | |
97 | ||
34a57104 BP |
98 | # Avoid a race between pidfile creation and notifying the parent, |
99 | # which can easily trigger if ovsdb-server is slow (e.g. due to valgrind). | |
15394e0f | 100 | OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version]) |
d8c6955a | 101 | |
ff8decf1 BP |
102 | # Kill the daemon process, making it look like a segfault, |
103 | # and wait for a new child process to get spawned. | |
d8c6955a BP |
104 | AT_CHECK([kill -SEGV $child], [0], [], [ignore]) |
105 | OVS_WAIT_WHILE([kill -0 $child]) | |
106 | OVS_WAIT_UNTIL([test -s ovsdb-server.pid && test $(cat ovsdb-server.pid) != $child]) | |
107 | ||
ff8decf1 BP |
108 | # Check that the pidfile names a running process, |
109 | # and that the parent process of that process is our child process. | |
d8c6955a BP |
110 | child2=$(cat ovsdb-server.pid) |
111 | check_ancestors $child2 $parent | |
112 | check_process_name $child2 ovsdb-server | |
113 | ||
ff8decf1 BP |
114 | # Kill the daemon process with SIGTERM, and wait for the daemon |
115 | # and the monitor processes to go away and the pidfile to get deleted. | |
d8c6955a BP |
116 | AT_CHECK([kill $child2]) |
117 | OVS_WAIT_WHILE([kill -0 $parent || kill -0 $child2 || test -e ovsdb-server.pid]) | |
ff8decf1 BP |
118 | AT_CLEANUP |
119 | ||
d8c6955a | 120 | |
ff8decf1 | 121 | AT_SETUP([daemon --detach]) |
d8c6955a | 122 | |
ff8decf1 BP |
123 | # Start the daemon and make sure that the pidfile exists immediately. |
124 | # We don't wait for the pidfile to get created because the daemon is | |
125 | # supposed to do so before the parent exits. | |
d8c6955a | 126 | AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --no-db], [0]) |
56120500 | 127 | AT_CHECK([test -s ovsdb-server.pid]) |
d8c6955a BP |
128 | child=$(cat ovsdb-server.pid) |
129 | AT_CHECK([kill -0 $child]) | |
130 | ||
ff8decf1 | 131 | # Kill the daemon and make sure that the pidfile gets deleted. |
fc28ea52 GS |
132 | if test "$IS_WIN32" = "yes"; then |
133 | # When a 'kill pid' is done on windows (through 'taskkill //F'), | |
134 | # pidfiles are not deleted (because it is force kill), so use | |
135 | # 'ovs-appctl exit' instead | |
56120500 | 136 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) |
fc28ea52 | 137 | else |
d8c6955a | 138 | kill $child |
fc28ea52 | 139 | fi |
d8c6955a | 140 | OVS_WAIT_WHILE([kill -0 $child]) |
56120500 | 141 | AT_CHECK([test ! -e ovsdb-server.pid]) |
d8c6955a | 142 | |
ff8decf1 BP |
143 | AT_CLEANUP |
144 | ||
d8c6955a | 145 | |
ff8decf1 | 146 | AT_SETUP([daemon --detach --monitor]) |
fc28ea52 | 147 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) |
5f223e92 BP |
148 | |
149 | # This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it. | |
150 | ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS | |
151 | ||
d8c6955a BP |
152 | on_exit 'kill $(cat *.pid)' |
153 | ||
ff8decf1 BP |
154 | # Start the daemon and make sure that the pidfile exists immediately. |
155 | # We don't wait for the pidfile to get created because the daemon is | |
156 | # supposed to do so before the parent exits. | |
d8c6955a | 157 | AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --monitor --no-db]) |
56120500 | 158 | AT_CHECK([test -s ovsdb-server.pid]) |
d8c6955a BP |
159 | child=$(cat ovsdb-server.pid) |
160 | ||
161 | # Check process naming and ancestry. | |
162 | monitor=$(parent_pid $child) | |
163 | check_process_name $child ovsdb-server | |
164 | check_ancestors $child $monitor 1 | |
165 | ||
ff8decf1 BP |
166 | # Kill the daemon process, making it look like a segfault, |
167 | # and wait for a new daemon process to get spawned. | |
d8c6955a BP |
168 | AT_CHECK([kill -SEGV $child], [0]) |
169 | OVS_WAIT_WHILE([kill -0 $child]) | |
170 | OVS_WAIT_UNTIL([test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != $child]) | |
171 | child2=$(cat ovsdb-server.pid) | |
172 | ||
173 | # Check process naming and ancestry. | |
174 | check_process_name $child2 ovsdb-server | |
175 | check_ancestors $child2 $monitor 1 | |
176 | ||
ff8decf1 BP |
177 | # Kill the daemon process with SIGTERM, and wait for the daemon |
178 | # and the monitor processes to go away and the pidfile to get deleted. | |
d8c6955a | 179 | AT_CHECK([kill $child2]) |
ff8decf1 | 180 | OVS_WAIT_WHILE( |
d8c6955a | 181 | [kill -0 $monitor || kill -0 $child2 || test -e ovsdb-server.pid]) |
ff8decf1 BP |
182 | AT_CLEANUP |
183 | ||
d8c6955a | 184 | |
ff8decf1 | 185 | AT_SETUP([daemon --detach startup errors]) |
d8c6955a | 186 | AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --unixctl=nonexistent/unixctl --no-db], [1], [], [stderr]) |
295fc4d6 | 187 | AT_CHECK([grep 'could not initialize control socket' stderr], |
56120500 | 188 | [0], [ignore]) |
d8c6955a | 189 | AT_CHECK([test ! -e ovsdb-server.pid]) |
ff8decf1 BP |
190 | AT_CLEANUP |
191 | ||
d8c6955a | 192 | |
ff8decf1 | 193 | AT_SETUP([daemon --detach --monitor startup errors]) |
fc28ea52 | 194 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) |
d8c6955a | 195 | AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --monitor --unixctl=nonexistent/unixctl --no-db], [1], [], [stderr]) |
295fc4d6 | 196 | AT_CHECK([grep 'could not initialize control socket' stderr], |
56120500 | 197 | [0], [ignore]) |
d8c6955a | 198 | AT_CHECK([test ! -e ovsdb-server.pid]) |
ff8decf1 | 199 | AT_CLEANUP |
02a514ef | 200 | |
d8c6955a | 201 | |
02a514ef | 202 | AT_SETUP([daemon --service]) |
05082734 | 203 | AT_KEYWORDS([windows-service]) |
02a514ef | 204 | AT_SKIP_IF([test "$IS_WIN32" != "yes"]) |
ab7fc30e | 205 | OVS_SKIP_NON_ADMIN_WIN |
13574ee6 | 206 | AT_SKIP_IF([sc qc ovsdb-server]) |
ab7fc30e | 207 | |
02a514ef GS |
208 | AT_CAPTURE_FILE([pid]) |
209 | # To create a Windows service, we need the absolute path for the executable. | |
210 | abs_path="$(cd $(dirname `which ovsdb-server`); pwd -W; cd $OLDPWD)" | |
211 | ||
d8c6955a | 212 | AT_CHECK([sc create ovsdb-server binpath="$abs_path/ovsdb-server --no-db --log-file=`pwd`/ovsdb-server.log --pidfile=`pwd`/ovsdb-server.pid --unixctl=`pwd`/ovsdb-server.ctl --remote=punix:`pwd`/socket --service"], |
02a514ef GS |
213 | [0], [[[SC]] CreateService SUCCESS |
214 | ]) | |
215 | ||
8164a704 | 216 | AT_CHECK([sc start ovsdb-server], [0], [ignore], [ignore], [sc delete ovsdb-server]) |
56120500 | 217 | OVS_WAIT_UNTIL([test -s ovsdb-server.pid]) |
05082734 | 218 | OVS_WAIT_UNTIL([sc query ovsdb-server | grep STATE | grep RUNNING > /dev/null 2>&1]) |
56120500 BP |
219 | AT_CHECK([kill -0 `cat ovsdb-server.pid`], [0], [ignore]) |
220 | AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs], [0], | |
02a514ef GS |
221 | [Open_vSwitch |
222 | ]) | |
223 | AT_CHECK([sc stop ovsdb-server], [0], [ignore]) | |
56120500 | 224 | OVS_WAIT_UNTIL([test ! -s ovsdb-server.pid]) |
02a514ef GS |
225 | AT_CHECK([sc query ovsdb-server | grep STATE | grep STOPPED], [0], [ignore]) |
226 | AT_CHECK([sc delete ovsdb-server], [0], [[[SC]] DeleteService SUCCESS | |
227 | ]) | |
228 | AT_CLEANUP |