]>
Commit | Line | Data |
---|---|---|
99155935 | 1 | AT_BANNER([daemon unit tests - C]) |
ff8decf1 BP |
2 | |
3 | AT_SETUP([daemon]) | |
fc28ea52 | 4 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) |
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. | |
434380a6 | 10 | AT_CHECK([ovsdb-server --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db 2>/dev/null & 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]) | |
fc28ea52 | 23 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) |
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. | |
434380a6 | 30 | AT_CHECK([ovsdb-server --monitor --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db 2>/dev/null & 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`]) | |
34a57104 BP |
42 | # Avoid a race between pidfile creation and notifying the parent, |
43 | # which can easily trigger if ovsdb-server is slow (e.g. due to valgrind). | |
44 | OVS_WAIT_UNTIL( | |
45 | [ovs-appctl --timeout=10 -t "`pwd`/unixctl" version], | |
46 | [kill `cat pid`]) | |
ff8decf1 BP |
47 | # Kill the daemon process, making it look like a segfault, |
48 | # and wait for a new child process to get spawned. | |
49 | AT_CHECK([cp pid oldpid], [0], [], [], [kill `cat parent`]) | |
50 | AT_CHECK([kill -SEGV `cat pid`], [0], [], [ignore], [kill `cat parent`]) | |
51 | OVS_WAIT_WHILE([kill -0 `cat oldpid`], [kill `cat parent`]) | |
52 | OVS_WAIT_UNTIL([test -s pid && test `cat pid` != `cat oldpid`], | |
53 | [kill `cat parent`]) | |
54 | AT_CHECK([cp pid newpid], [0], [], [], [kill `cat parent`]) | |
55 | # Check that the pidfile names a running process, | |
56 | # and that the parent process of that process is our child process. | |
57 | AT_CHECK([ps -o ppid= -p `cat pid` > parentpid], | |
58 | [0], [], [], [kill `cat parent`]) | |
59 | AT_CHECK( | |
60 | [parentpid=`cat parentpid` && | |
61 | parent=`cat parent` && | |
62 | test $parentpid = $parent], | |
63 | [0], [], [], [kill `cat parent`]) | |
64 | # Kill the daemon process with SIGTERM, and wait for the daemon | |
65 | # and the monitor processes to go away and the pidfile to get deleted. | |
66 | AT_CHECK([kill `cat pid`], [0], [], [ignore], [kill `cat parent`]) | |
67 | OVS_WAIT_WHILE([kill -0 `cat parent` || kill -0 `cat newpid` || test -e pid], | |
68 | [kill `cat parent`]) | |
69 | AT_CLEANUP | |
70 | ||
71 | AT_SETUP([daemon --detach]) | |
72 | AT_CAPTURE_FILE([pid]) | |
73 | OVSDB_INIT([db]) | |
74 | # Start the daemon and make sure that the pidfile exists immediately. | |
75 | # We don't wait for the pidfile to get created because the daemon is | |
76 | # supposed to do so before the parent exits. | |
77a922c7 | 77 | AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0]) |
ff8decf1 BP |
78 | AT_CHECK([test -s pid]) |
79 | AT_CHECK([kill -0 `cat pid`]) | |
80 | # Kill the daemon and make sure that the pidfile gets deleted. | |
81 | cp pid saved-pid | |
fc28ea52 GS |
82 | if test "$IS_WIN32" = "yes"; then |
83 | # When a 'kill pid' is done on windows (through 'taskkill //F'), | |
84 | # pidfiles are not deleted (because it is force kill), so use | |
85 | # 'ovs-appctl exit' instead | |
86 | ovs-appctl -t `pwd`/unixctl exit | |
87 | else | |
88 | kill `cat pid` | |
89 | fi | |
ff8decf1 BP |
90 | OVS_WAIT_WHILE([kill -0 `cat saved-pid`]) |
91 | AT_CHECK([test ! -e pid]) | |
92 | AT_CLEANUP | |
93 | ||
94 | AT_SETUP([daemon --detach --monitor]) | |
fc28ea52 | 95 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) |
ff8decf1 BP |
96 | m4_define([CHECK], |
97 | [AT_CHECK([$1], [$2], [$3], [$4], [kill `cat daemon monitor`])]) | |
98 | OVSDB_INIT([db]) | |
99 | AT_CAPTURE_FILE([daemon]) | |
100 | AT_CAPTURE_FILE([olddaemon]) | |
101 | AT_CAPTURE_FILE([newdaemon]) | |
102 | AT_CAPTURE_FILE([monitor]) | |
103 | AT_CAPTURE_FILE([newmonitor]) | |
104 | AT_CAPTURE_FILE([init]) | |
105 | # Start the daemon and make sure that the pidfile exists immediately. | |
106 | # We don't wait for the pidfile to get created because the daemon is | |
107 | # supposed to do so before the parent exits. | |
77a922c7 | 108 | AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/daemon --monitor --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0]) |
ff8decf1 BP |
109 | AT_CHECK([test -s daemon]) |
110 | # Check that the pidfile names a running process, | |
111 | # and that the parent process of that process is a running process, | |
112 | # and that the parent process of that process is init. | |
113 | CHECK([kill -0 `cat daemon`]) | |
114 | CHECK([ps -o ppid= -p `cat daemon` > monitor]) | |
115 | CHECK([kill -0 `cat monitor`]) | |
116 | CHECK([ps -o ppid= -p `cat monitor` > init]) | |
c8dc7b46 | 117 | CHECK([test `cat init` != $$]) |
ff8decf1 BP |
118 | # Kill the daemon process, making it look like a segfault, |
119 | # and wait for a new daemon process to get spawned. | |
120 | CHECK([cp daemon olddaemon]) | |
bc9dcfb3 | 121 | CHECK([kill -SEGV `cat daemon`], [0]) |
ff8decf1 BP |
122 | OVS_WAIT_WHILE([kill -0 `cat olddaemon`], [kill `cat olddaemon daemon`]) |
123 | OVS_WAIT_UNTIL([test -s daemon && test `cat daemon` != `cat olddaemon`], | |
124 | [kill `cat olddaemon daemon`]) | |
125 | CHECK([cp daemon newdaemon]) | |
126 | # Check that the pidfile names a running process, | |
127 | # and that the parent process of that process is our child process. | |
128 | CHECK([kill -0 `cat daemon`]) | |
129 | CHECK([diff olddaemon newdaemon], [1], [ignore]) | |
130 | CHECK([ps -o ppid= -p `cat daemon` > newmonitor]) | |
131 | CHECK([diff monitor newmonitor]) | |
132 | CHECK([kill -0 `cat newmonitor`]) | |
133 | CHECK([ps -o ppid= -p `cat newmonitor` > init]) | |
c8dc7b46 | 134 | CHECK([test `cat init` != $$]) |
ff8decf1 BP |
135 | # Kill the daemon process with SIGTERM, and wait for the daemon |
136 | # and the monitor processes to go away and the pidfile to get deleted. | |
137 | CHECK([kill `cat daemon`], [0], [], [ignore]) | |
138 | OVS_WAIT_WHILE( | |
139 | [kill -0 `cat monitor` || kill -0 `cat newdaemon` || test -e daemon], | |
140 | [kill `cat monitor newdaemon`]) | |
141 | m4_undefine([CHECK]) | |
142 | AT_CLEANUP | |
143 | ||
144 | AT_SETUP([daemon --detach startup errors]) | |
145 | AT_CAPTURE_FILE([pid]) | |
146 | OVSDB_INIT([db]) | |
77a922c7 | 147 | AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr]) |
ff8decf1 BP |
148 | AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr], |
149 | [0], [ignore], []) | |
150 | AT_CHECK([test ! -s pid]) | |
151 | AT_CLEANUP | |
152 | ||
153 | AT_SETUP([daemon --detach --monitor startup errors]) | |
fc28ea52 | 154 | AT_SKIP_IF([test "$IS_WIN32" = "yes"]) |
ff8decf1 BP |
155 | AT_CAPTURE_FILE([pid]) |
156 | OVSDB_INIT([db]) | |
77a922c7 | 157 | AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --monitor --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr]) |
ff8decf1 BP |
158 | AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr], |
159 | [0], [ignore], []) | |
160 | AT_CHECK([test ! -s pid]) | |
161 | AT_CLEANUP | |
02a514ef GS |
162 | |
163 | AT_SETUP([daemon --service]) | |
164 | AT_SKIP_IF([test "$IS_WIN32" != "yes"]) | |
165 | OVSDB_INIT([db]) | |
166 | AT_CAPTURE_FILE([pid]) | |
167 | # To create a Windows service, we need the absolute path for the executable. | |
168 | abs_path="$(cd $(dirname `which ovsdb-server`); pwd -W; cd $OLDPWD)" | |
169 | ||
170 | AT_CHECK([sc create ovsdb-server binpath="$abs_path/ovsdb-server `pwd`/db --log-file=`pwd`/ovsdb-server.log --pidfile=`pwd`/pid --remote=punix:`pwd`/socket --unixctl=`pwd`/unixctl --service"], | |
171 | [0], [[[SC]] CreateService SUCCESS | |
172 | ]) | |
173 | ||
174 | AT_CHECK([sc start ovsdb-server], [0], [ignore]) | |
175 | OVS_WAIT_UNTIL([test -s pid]) | |
176 | AT_CHECK([sc query ovsdb-server | grep STATE | grep RUNNING], [0], [ignore]) | |
177 | AT_CHECK([kill -0 `cat pid`], [0], [ignore]) | |
178 | AT_CHECK([ovs-appctl -t `pwd`/unixctl ovsdb-server/list-dbs], [0], | |
179 | [Open_vSwitch | |
180 | ]) | |
181 | AT_CHECK([sc stop ovsdb-server], [0], [ignore]) | |
182 | OVS_WAIT_UNTIL([test ! -s pid]) | |
183 | AT_CHECK([sc query ovsdb-server | grep STATE | grep STOPPED], [0], [ignore]) | |
184 | AT_CHECK([sc delete ovsdb-server], [0], [[[SC]] DeleteService SUCCESS | |
185 | ]) | |
186 | AT_CLEANUP |