]> git.proxmox.com Git - ovs.git/blob - tests/daemon.at
Fix ovs-dpctl-top by removing 3 wrong hunks in py3-compat.patch.
[ovs.git] / tests / daemon.at
1 AT_BANNER([daemon unit tests - C])
2
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() {
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
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
48 AT_SETUP([daemon])
49 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
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
59 # Start the daemon and wait for the pidfile to get created
60 # and that its contents are the correct pid.
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
65 OVS_WAIT_UNTIL([test -s ovsdb-server.pid])
66 pid=$(cat ovsdb-server.pid)
67
68 AT_CHECK([test $pid = $expected_pid])
69 AT_CHECK([kill -0 $pid])
70
71 # Kill the daemon and make sure that the pidfile gets deleted.
72 AT_CHECK([kill $pid])
73 OVS_WAIT_WHILE([kill -0 $pid])
74
75 AT_CHECK([test ! -e ovsdb-server.pid])
76 AT_CLEANUP
77
78 AT_SETUP([daemon --monitor])
79 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
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
84 # Start the daemon and wait for the pidfile to get created.
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
91 # Check that the pidfile names a running process,
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
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).
100 OVS_WAIT_UNTIL([ovs-appctl -t ovsdb-server version])
101
102 # Kill the daemon process, making it look like a segfault,
103 # and wait for a new child process to get spawned.
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
108 # Check that the pidfile names a running process,
109 # and that the parent process of that process is our child process.
110 child2=$(cat ovsdb-server.pid)
111 check_ancestors $child2 $parent
112 check_process_name $child2 ovsdb-server
113
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.
116 AT_CHECK([kill $child2])
117 OVS_WAIT_WHILE([kill -0 $parent || kill -0 $child2 || test -e ovsdb-server.pid])
118 AT_CLEANUP
119
120
121 AT_SETUP([daemon --detach])
122
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.
126 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --no-db], [0])
127 AT_CHECK([test -s ovsdb-server.pid])
128 child=$(cat ovsdb-server.pid)
129 AT_CHECK([kill -0 $child])
130
131 # Kill the daemon and make sure that the pidfile gets deleted.
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
136 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
137 else
138 kill $child
139 fi
140 OVS_WAIT_WHILE([kill -0 $child])
141 AT_CHECK([test ! -e ovsdb-server.pid])
142
143 AT_CLEANUP
144
145
146 AT_SETUP([daemon --detach --monitor])
147 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
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
152 on_exit 'kill $(cat *.pid)'
153
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.
157 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --monitor --no-db])
158 AT_CHECK([test -s ovsdb-server.pid])
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
166 # Kill the daemon process, making it look like a segfault,
167 # and wait for a new daemon process to get spawned.
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
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.
179 AT_CHECK([kill $child2])
180 OVS_WAIT_WHILE(
181 [kill -0 $monitor || kill -0 $child2 || test -e ovsdb-server.pid])
182 AT_CLEANUP
183
184
185 AT_SETUP([daemon --detach startup errors])
186 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --unixctl=nonexistent/unixctl --no-db], [1], [], [stderr])
187 AT_CHECK([grep 'could not initialize control socket' stderr],
188 [0], [ignore])
189 AT_CHECK([test ! -e ovsdb-server.pid])
190 AT_CLEANUP
191
192
193 AT_SETUP([daemon --detach --monitor startup errors])
194 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
195 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --monitor --unixctl=nonexistent/unixctl --no-db], [1], [], [stderr])
196 AT_CHECK([grep 'could not initialize control socket' stderr],
197 [0], [ignore])
198 AT_CHECK([test ! -e ovsdb-server.pid])
199 AT_CLEANUP
200
201
202 AT_SETUP([daemon --service])
203 AT_KEYWORDS([windows-service])
204 AT_SKIP_IF([test "$IS_WIN32" != "yes"])
205 OVS_SKIP_NON_ADMIN_WIN
206 AT_SKIP_IF([sc qc ovsdb-server])
207
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
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"],
213 [0], [[[SC]] CreateService SUCCESS
214 ])
215
216 AT_CHECK([sc start ovsdb-server], [0], [ignore], [ignore], [sc delete ovsdb-server])
217 OVS_WAIT_UNTIL([test -s ovsdb-server.pid])
218 OVS_WAIT_UNTIL([sc query ovsdb-server | grep STATE | grep RUNNING > /dev/null 2>&1])
219 AT_CHECK([kill -0 `cat ovsdb-server.pid`], [0], [ignore])
220 AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs], [0],
221 [Open_vSwitch
222 ])
223 AT_CHECK([sc stop ovsdb-server], [0], [ignore])
224 OVS_WAIT_UNTIL([test ! -s ovsdb-server.pid])
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