netdev-dpdk: fix mbuf leaks
[cascardo/ovs.git] / tests / daemon.at
1 AT_BANNER([daemon unit tests - C])
2
3 AT_SETUP([daemon])
4 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
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.
10 AT_CHECK([ovsdb-server --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db 2>/dev/null & echo $! > expected], [0])
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])
23 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
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.
30 AT_CHECK([ovsdb-server --monitor --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db 2>/dev/null & echo $! > parent], [0])
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 # 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`])
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.
77 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0])
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
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
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])
95 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
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.
108 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/daemon --monitor --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0])
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])
117 CHECK([test `cat init` != $$])
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])
121 CHECK([kill -SEGV `cat daemon`], [0])
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])
134 CHECK([test `cat init` != $$])
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])
147 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr])
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])
154 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
155 AT_CAPTURE_FILE([pid])
156 OVSDB_INIT([db])
157 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --monitor --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr])
158 AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
159   [0], [ignore], [])
160 AT_CHECK([test ! -s pid])
161 AT_CLEANUP
162
163 AT_SETUP([daemon --service])
164 AT_KEYWORDS([windows-service])
165 AT_SKIP_IF([test "$IS_WIN32" != "yes"])
166 OVSDB_INIT([db])
167 AT_CAPTURE_FILE([pid])
168 # To create a Windows service, we need the absolute path for the executable.
169 abs_path="$(cd $(dirname `which ovsdb-server`); pwd -W; cd $OLDPWD)"
170
171 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"],
172 [0], [[[SC]] CreateService SUCCESS
173 ])
174
175 AT_CHECK([sc start ovsdb-server], [0], [ignore], [ignore], [sc delete ovsdb-server])
176 OVS_WAIT_UNTIL([test -s pid])
177 OVS_WAIT_UNTIL([sc query ovsdb-server | grep STATE | grep RUNNING > /dev/null 2>&1])
178 AT_CHECK([kill -0 `cat pid`], [0], [ignore])
179 AT_CHECK([ovs-appctl -t `pwd`/unixctl ovsdb-server/list-dbs], [0],
180 [Open_vSwitch
181 ])
182 AT_CHECK([sc stop ovsdb-server], [0], [ignore])
183 OVS_WAIT_UNTIL([test ! -s pid])
184 AT_CHECK([sc query ovsdb-server | grep STATE | grep STOPPED], [0], [ignore])
185 AT_CHECK([sc delete ovsdb-server], [0], [[[SC]] DeleteService SUCCESS
186 ])
187 AT_CLEANUP