]> git.proxmox.com Git - mirror_ovs.git/blame - tests/daemon.at
dpctl: Add the option 'pmd' for dump-flows.
[mirror_ovs.git] / tests / daemon.at
CommitLineData
99155935 1AT_BANNER([daemon unit tests - C])
ff8decf1 2
d8c6955a
BP
3OVS_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.)
8if 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 }
15else
16 check_process_name() {
17 :
18 }
19fi
20
21# check_ancestors PID PARENT [GRANDPARENT...]
22check_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}
46OVS_END_SHELL_HELPERS
47
ff8decf1 48AT_SETUP([daemon])
fc28ea52 49AT_SKIP_IF([test "$IS_WIN32" = "yes"])
ab7fc30e
PB
50
51dnl OVS_SKIP_NON_ADMIN_WIN()
52dnl
53dnl Checks if we have enough rights to create a service
54m4_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
61on_exit 'kill $(cat *.pid)'
62AT_CHECK([ovsdb-server --pidfile --no-db 2>/dev/null & echo $!], [0], [stdout])
63expected_pid=$(cat stdout)
64
56120500 65OVS_WAIT_UNTIL([test -s ovsdb-server.pid])
d8c6955a
BP
66pid=$(cat ovsdb-server.pid)
67
68AT_CHECK([test $pid = $expected_pid])
69AT_CHECK([kill -0 $pid])
70
ff8decf1 71# Kill the daemon and make sure that the pidfile gets deleted.
d8c6955a
BP
72AT_CHECK([kill $pid])
73OVS_WAIT_WHILE([kill -0 $pid])
74
56120500 75AT_CHECK([test ! -e ovsdb-server.pid])
ff8decf1
BP
76AT_CLEANUP
77
78AT_SETUP([daemon --monitor])
fc28ea52 79AT_SKIP_IF([test "$IS_WIN32" = "yes"])
5f223e92
BP
80
81# This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it.
82ASAN_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
85on_exit 'kill $(cat *.pid)'
86AT_CHECK([ovsdb-server --monitor --pidfile --no-db 2>/dev/null & echo $!],
87 [0], [stdout])
88parent=$(cat stdout)
89OVS_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.
94child=$(cat ovsdb-server.pid)
95check_ancestors $child $parent
96check_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 100OVS_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
104AT_CHECK([kill -SEGV $child], [0], [], [ignore])
105OVS_WAIT_WHILE([kill -0 $child])
106OVS_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
110child2=$(cat ovsdb-server.pid)
111check_ancestors $child2 $parent
112check_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
116AT_CHECK([kill $child2])
117OVS_WAIT_WHILE([kill -0 $parent || kill -0 $child2 || test -e ovsdb-server.pid])
ff8decf1
BP
118AT_CLEANUP
119
d8c6955a 120
ff8decf1 121AT_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 126AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --no-db], [0])
56120500 127AT_CHECK([test -s ovsdb-server.pid])
d8c6955a
BP
128child=$(cat ovsdb-server.pid)
129AT_CHECK([kill -0 $child])
130
ff8decf1 131# Kill the daemon and make sure that the pidfile gets deleted.
fc28ea52
GS
132if 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 137else
d8c6955a 138 kill $child
fc28ea52 139fi
d8c6955a 140OVS_WAIT_WHILE([kill -0 $child])
56120500 141AT_CHECK([test ! -e ovsdb-server.pid])
d8c6955a 142
ff8decf1
BP
143AT_CLEANUP
144
d8c6955a 145
ff8decf1 146AT_SETUP([daemon --detach --monitor])
fc28ea52 147AT_SKIP_IF([test "$IS_WIN32" = "yes"])
5f223e92
BP
148
149# This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it.
150ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS
151
d8c6955a
BP
152on_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 157AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --monitor --no-db])
56120500 158AT_CHECK([test -s ovsdb-server.pid])
d8c6955a
BP
159child=$(cat ovsdb-server.pid)
160
161# Check process naming and ancestry.
162monitor=$(parent_pid $child)
163check_process_name $child ovsdb-server
164check_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
168AT_CHECK([kill -SEGV $child], [0])
169OVS_WAIT_WHILE([kill -0 $child])
170OVS_WAIT_UNTIL([test -s ovsdb-server.pid && test `cat ovsdb-server.pid` != $child])
171child2=$(cat ovsdb-server.pid)
172
173# Check process naming and ancestry.
174check_process_name $child2 ovsdb-server
175check_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 179AT_CHECK([kill $child2])
ff8decf1 180OVS_WAIT_WHILE(
d8c6955a 181 [kill -0 $monitor || kill -0 $child2 || test -e ovsdb-server.pid])
ff8decf1
BP
182AT_CLEANUP
183
d8c6955a 184
ff8decf1 185AT_SETUP([daemon --detach startup errors])
d8c6955a 186AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --unixctl=nonexistent/unixctl --no-db], [1], [], [stderr])
295fc4d6 187AT_CHECK([grep 'could not initialize control socket' stderr],
56120500 188 [0], [ignore])
d8c6955a 189AT_CHECK([test ! -e ovsdb-server.pid])
ff8decf1
BP
190AT_CLEANUP
191
d8c6955a 192
ff8decf1 193AT_SETUP([daemon --detach --monitor startup errors])
fc28ea52 194AT_SKIP_IF([test "$IS_WIN32" = "yes"])
d8c6955a 195AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --monitor --unixctl=nonexistent/unixctl --no-db], [1], [], [stderr])
295fc4d6 196AT_CHECK([grep 'could not initialize control socket' stderr],
56120500 197 [0], [ignore])
d8c6955a 198AT_CHECK([test ! -e ovsdb-server.pid])
ff8decf1 199AT_CLEANUP
02a514ef 200
d8c6955a 201
02a514ef 202AT_SETUP([daemon --service])
05082734 203AT_KEYWORDS([windows-service])
02a514ef 204AT_SKIP_IF([test "$IS_WIN32" != "yes"])
ab7fc30e 205OVS_SKIP_NON_ADMIN_WIN
13574ee6 206AT_SKIP_IF([sc qc ovsdb-server])
ab7fc30e 207
02a514ef
GS
208AT_CAPTURE_FILE([pid])
209# To create a Windows service, we need the absolute path for the executable.
210abs_path="$(cd $(dirname `which ovsdb-server`); pwd -W; cd $OLDPWD)"
211
d8c6955a 212AT_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 216AT_CHECK([sc start ovsdb-server], [0], [ignore], [ignore], [sc delete ovsdb-server])
56120500 217OVS_WAIT_UNTIL([test -s ovsdb-server.pid])
05082734 218OVS_WAIT_UNTIL([sc query ovsdb-server | grep STATE | grep RUNNING > /dev/null 2>&1])
56120500
BP
219AT_CHECK([kill -0 `cat ovsdb-server.pid`], [0], [ignore])
220AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-dbs], [0],
02a514ef
GS
221[Open_vSwitch
222])
223AT_CHECK([sc stop ovsdb-server], [0], [ignore])
56120500 224OVS_WAIT_UNTIL([test ! -s ovsdb-server.pid])
02a514ef
GS
225AT_CHECK([sc query ovsdb-server | grep STATE | grep STOPPED], [0], [ignore])
226AT_CHECK([sc delete ovsdb-server], [0], [[[SC]] DeleteService SUCCESS
227])
228AT_CLEANUP