meta-flow: Correctly set destination MAC in mf_set_flow_value().
[sliver-openvswitch.git] / tests / daemon.at
1 AT_BANNER([daemon unit tests - C])
2
3 AT_SETUP([daemon])
4 AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ
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& 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 "$CHECK_LCOV" = true]) # lcov wrapper make pids differ
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& 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 # Kill the daemon process, making it look like a segfault,
43 # and wait for a new child process to get spawned.
44 AT_CHECK([cp pid oldpid], [0], [], [], [kill `cat parent`])
45 AT_CHECK([kill -SEGV `cat pid`], [0], [], [ignore], [kill `cat parent`])
46 OVS_WAIT_WHILE([kill -0 `cat oldpid`], [kill `cat parent`])
47 OVS_WAIT_UNTIL([test -s pid && test `cat pid` != `cat oldpid`],
48   [kill `cat parent`])
49 AT_CHECK([cp pid newpid], [0], [], [], [kill `cat parent`])
50 # Check that the pidfile names a running process,
51 # and that the parent process of that process is our child process.
52 AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
53   [0], [], [], [kill `cat parent`])
54 AT_CHECK(
55   [parentpid=`cat parentpid` && 
56    parent=`cat parent` && 
57    test $parentpid = $parent],
58   [0], [], [], [kill `cat parent`])
59 # Kill the daemon process with SIGTERM, and wait for the daemon
60 # and the monitor processes to go away and the pidfile to get deleted.
61 AT_CHECK([kill `cat pid`], [0], [], [ignore], [kill `cat parent`])
62 OVS_WAIT_WHILE([kill -0 `cat parent` || kill -0 `cat newpid` || test -e pid],
63   [kill `cat parent`])
64 AT_CLEANUP
65
66 AT_SETUP([daemon --detach])
67 AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ
68 AT_CAPTURE_FILE([pid])
69 OVSDB_INIT([db])
70 # Start the daemon and make sure that the pidfile exists immediately.
71 # We don't wait for the pidfile to get created because the daemon is
72 # supposed to do so before the parent exits.
73 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --remote=punix:socket --unixctl=$PWD/unixctl db], [0])
74 AT_CHECK([test -s pid])
75 AT_CHECK([kill -0 `cat pid`])
76 # Kill the daemon and make sure that the pidfile gets deleted.
77 cp pid saved-pid
78 kill `cat pid`
79 OVS_WAIT_WHILE([kill -0 `cat saved-pid`])
80 AT_CHECK([test ! -e pid])
81 AT_CLEANUP
82
83 AT_SETUP([daemon --detach --monitor])
84 AT_SKIP_IF([test "$CHECK_LCOV" = true]) # lcov wrapper make pids differ
85 m4_define([CHECK], 
86   [AT_CHECK([$1], [$2], [$3], [$4], [kill `cat daemon monitor`])])
87 OVSDB_INIT([db])
88 AT_CAPTURE_FILE([daemon])
89 AT_CAPTURE_FILE([olddaemon])
90 AT_CAPTURE_FILE([newdaemon])
91 AT_CAPTURE_FILE([monitor])
92 AT_CAPTURE_FILE([newmonitor])
93 AT_CAPTURE_FILE([init])
94 # Start the daemon and make sure that the pidfile exists immediately.
95 # We don't wait for the pidfile to get created because the daemon is
96 # supposed to do so before the parent exits.
97 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/daemon --monitor --remote=punix:socket --unixctl=$PWD/unixctl db], [0])
98 AT_CHECK([test -s daemon])
99 # Check that the pidfile names a running process,
100 # and that the parent process of that process is a running process,
101 # and that the parent process of that process is init.
102 CHECK([kill -0 `cat daemon`])
103 CHECK([ps -o ppid= -p `cat daemon` > monitor])
104 CHECK([kill -0 `cat monitor`])
105 CHECK([ps -o ppid= -p `cat monitor` > init])
106 CHECK([test `cat init` = 1])
107 # Kill the daemon process, making it look like a segfault,
108 # and wait for a new daemon process to get spawned.
109 CHECK([cp daemon olddaemon])
110 CHECK([kill -SEGV `cat daemon`], [0])
111 OVS_WAIT_WHILE([kill -0 `cat olddaemon`], [kill `cat olddaemon daemon`])
112 OVS_WAIT_UNTIL([test -s daemon && test `cat daemon` != `cat olddaemon`],
113   [kill `cat olddaemon daemon`])
114 CHECK([cp daemon newdaemon])
115 # Check that the pidfile names a running process,
116 # and that the parent process of that process is our child process.
117 CHECK([kill -0 `cat daemon`])
118 CHECK([diff olddaemon newdaemon], [1], [ignore])
119 CHECK([ps -o ppid= -p `cat daemon` > newmonitor])
120 CHECK([diff monitor newmonitor])
121 CHECK([kill -0 `cat newmonitor`])
122 CHECK([ps -o ppid= -p `cat newmonitor` > init])
123 CHECK([test `cat init` = 1])
124 # Kill the daemon process with SIGTERM, and wait for the daemon
125 # and the monitor processes to go away and the pidfile to get deleted.
126 CHECK([kill `cat daemon`], [0], [], [ignore])
127 OVS_WAIT_WHILE(
128   [kill -0 `cat monitor` || kill -0 `cat newdaemon` || test -e daemon],
129   [kill `cat monitor newdaemon`])
130 m4_undefine([CHECK])
131 AT_CLEANUP
132
133 AT_SETUP([daemon --detach startup errors])
134 AT_CAPTURE_FILE([pid])
135 OVSDB_INIT([db])
136 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/nonexistent/unixctl db], [1], [], [stderr])
137 AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
138   [0], [ignore], [])
139 AT_CHECK([test ! -s pid])
140 AT_CLEANUP
141
142 AT_SETUP([daemon --detach --monitor startup errors])
143 AT_CAPTURE_FILE([pid])
144 OVSDB_INIT([db])
145 AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --monitor --unixctl=$PWD/nonexistent/unixctl db], [1], [], [stderr])
146 AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
147   [0], [ignore], [])
148 AT_CHECK([test ! -s pid])
149 AT_CLEANUP
150
151 # xxx This test hangs frequently, which often prevents builds from
152 # xxx completing.   Skip this test until we have time to debug it.
153 AT_SETUP([daemon --detach closes standard fds])
154 AT_SKIP_IF([:])
155 AT_CAPTURE_FILE([pid])
156 AT_CAPTURE_FILE([status])
157 AT_CAPTURE_FILE([stderr])
158 OVSDB_INIT([db])
159 AT_CHECK([(yes 2>stderr; echo $? > status) | ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/unixctl db], [0], [], [])
160 AT_CHECK([kill `cat pid`])
161 AT_CHECK([test -s status])
162 if grep '[[bB]]roken pipe' stderr >/dev/null 2>&1; then
163   # Something in the environment caused SIGPIPE to be ignored, but
164   # 'yes' at least told us that it got EPIPE.  Good enough; we know
165   # that stdout was closed.
166   :
167 else
168   # Otherwise make sure that 'yes' died from SIGPIPE.
169   AT_CHECK([kill -l `cat status`], [0], [PIPE
170 ])
171 fi
172 AT_CLEANUP
173
174 # xxx This test hangs frequently, which often prevents builds from
175 # xxx completing.   Skip this test until we have time to debug it.
176 AT_SETUP([daemon --detach --monitor closes standard fds])
177 AT_SKIP_IF([:])
178 AT_CAPTURE_FILE([pid])
179 AT_CAPTURE_FILE([status])
180 AT_CAPTURE_FILE([stderr])
181 OVSDB_INIT([db])
182 AT_CHECK([(yes 2>stderr; echo $? > status) | ovsdb-server --detach --monitor --pidfile=$PWD/pid --unixctl=$PWD/unixctl db], [0], [], [])
183 AT_CHECK([kill `cat pid`])
184 AT_CHECK([test -s status])
185 if grep '[[bB]]roken pipe' stderr >/dev/null 2>&1; then
186   # Something in the environment caused SIGPIPE to be ignored, but
187   # 'yes' at least told us that it got EPIPE.  Good enough; we know
188   # that stdout was closed.
189   :
190 else
191   # Otherwise make sure that 'yes' died from SIGPIPE.
192   AT_CHECK([kill -l `cat status`], [0], [PIPE
193 ])
194 fi
195 AT_CLEANUP