]> git.proxmox.com Git - mirror_ovs.git/blame - tests/daemon.at
Rename NOT_REACHED to OVS_NOT_REACHED
[mirror_ovs.git] / tests / daemon.at
CommitLineData
99155935 1AT_BANNER([daemon unit tests - C])
ff8decf1
BP
2
3AT_SETUP([daemon])
4OVSDB_INIT([db])
5AT_CAPTURE_FILE([pid])
6AT_CAPTURE_FILE([expected])
7# Start the daemon and wait for the pidfile to get created
8# and that its contents are the correct pid.
37d03458 9AT_CHECK([ovsdb-server --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db& echo $! > expected], [0])
ff8decf1
BP
10OVS_WAIT_UNTIL([test -s pid], [kill `cat expected`])
11AT_CHECK(
12 [pid=`cat pid` && expected=`cat expected` && test "$pid" = "$expected"],
13 [0], [], [], [kill `cat expected`])
14AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat expected`])
15# Kill the daemon and make sure that the pidfile gets deleted.
16kill `cat expected`
17OVS_WAIT_WHILE([kill -0 `cat expected`])
18AT_CHECK([test ! -e pid])
19AT_CLEANUP
20
21AT_SETUP([daemon --monitor])
22OVSDB_INIT([db])
23AT_CAPTURE_FILE([pid])
24AT_CAPTURE_FILE([parent])
25AT_CAPTURE_FILE([parentpid])
26AT_CAPTURE_FILE([newpid])
27# Start the daemon and wait for the pidfile to get created.
37d03458 28AT_CHECK([ovsdb-server --monitor --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db& echo $! > parent], [0])
ff8decf1
BP
29OVS_WAIT_UNTIL([test -s pid], [kill `cat parent`])
30# Check that the pidfile names a running process,
31# and that the parent process of that process is our child process.
32AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat parent`])
33AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
34 [0], [], [], [kill `cat parent`])
35AT_CHECK(
36 [parentpid=`cat parentpid` &&
37 parent=`cat parent` &&
38 test $parentpid = $parent],
39 [0], [], [], [kill `cat parent`])
34a57104
BP
40# Avoid a race between pidfile creation and notifying the parent,
41# which can easily trigger if ovsdb-server is slow (e.g. due to valgrind).
42OVS_WAIT_UNTIL(
43 [ovs-appctl --timeout=10 -t "`pwd`/unixctl" version],
44 [kill `cat pid`])
ff8decf1
BP
45# Kill the daemon process, making it look like a segfault,
46# and wait for a new child process to get spawned.
47AT_CHECK([cp pid oldpid], [0], [], [], [kill `cat parent`])
48AT_CHECK([kill -SEGV `cat pid`], [0], [], [ignore], [kill `cat parent`])
49OVS_WAIT_WHILE([kill -0 `cat oldpid`], [kill `cat parent`])
50OVS_WAIT_UNTIL([test -s pid && test `cat pid` != `cat oldpid`],
51 [kill `cat parent`])
52AT_CHECK([cp pid newpid], [0], [], [], [kill `cat parent`])
53# Check that the pidfile names a running process,
54# and that the parent process of that process is our child process.
55AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
56 [0], [], [], [kill `cat parent`])
57AT_CHECK(
58 [parentpid=`cat parentpid` &&
59 parent=`cat parent` &&
60 test $parentpid = $parent],
61 [0], [], [], [kill `cat parent`])
62# Kill the daemon process with SIGTERM, and wait for the daemon
63# and the monitor processes to go away and the pidfile to get deleted.
64AT_CHECK([kill `cat pid`], [0], [], [ignore], [kill `cat parent`])
65OVS_WAIT_WHILE([kill -0 `cat parent` || kill -0 `cat newpid` || test -e pid],
66 [kill `cat parent`])
67AT_CLEANUP
68
69AT_SETUP([daemon --detach])
70AT_CAPTURE_FILE([pid])
71OVSDB_INIT([db])
72# Start the daemon and make sure that the pidfile exists immediately.
73# We don't wait for the pidfile to get created because the daemon is
74# supposed to do so before the parent exits.
77a922c7 75AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0])
ff8decf1
BP
76AT_CHECK([test -s pid])
77AT_CHECK([kill -0 `cat pid`])
78# Kill the daemon and make sure that the pidfile gets deleted.
79cp pid saved-pid
80kill `cat pid`
81OVS_WAIT_WHILE([kill -0 `cat saved-pid`])
82AT_CHECK([test ! -e pid])
83AT_CLEANUP
84
85AT_SETUP([daemon --detach --monitor])
86m4_define([CHECK],
87 [AT_CHECK([$1], [$2], [$3], [$4], [kill `cat daemon monitor`])])
88OVSDB_INIT([db])
89AT_CAPTURE_FILE([daemon])
90AT_CAPTURE_FILE([olddaemon])
91AT_CAPTURE_FILE([newdaemon])
92AT_CAPTURE_FILE([monitor])
93AT_CAPTURE_FILE([newmonitor])
94AT_CAPTURE_FILE([init])
95# Start the daemon and make sure that the pidfile exists immediately.
96# We don't wait for the pidfile to get created because the daemon is
97# supposed to do so before the parent exits.
77a922c7 98AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/daemon --monitor --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0])
ff8decf1
BP
99AT_CHECK([test -s daemon])
100# Check that the pidfile names a running process,
101# and that the parent process of that process is a running process,
102# and that the parent process of that process is init.
103CHECK([kill -0 `cat daemon`])
104CHECK([ps -o ppid= -p `cat daemon` > monitor])
105CHECK([kill -0 `cat monitor`])
106CHECK([ps -o ppid= -p `cat monitor` > init])
c8dc7b46 107CHECK([test `cat init` != $$])
ff8decf1
BP
108# Kill the daemon process, making it look like a segfault,
109# and wait for a new daemon process to get spawned.
110CHECK([cp daemon olddaemon])
bc9dcfb3 111CHECK([kill -SEGV `cat daemon`], [0])
ff8decf1
BP
112OVS_WAIT_WHILE([kill -0 `cat olddaemon`], [kill `cat olddaemon daemon`])
113OVS_WAIT_UNTIL([test -s daemon && test `cat daemon` != `cat olddaemon`],
114 [kill `cat olddaemon daemon`])
115CHECK([cp daemon newdaemon])
116# Check that the pidfile names a running process,
117# and that the parent process of that process is our child process.
118CHECK([kill -0 `cat daemon`])
119CHECK([diff olddaemon newdaemon], [1], [ignore])
120CHECK([ps -o ppid= -p `cat daemon` > newmonitor])
121CHECK([diff monitor newmonitor])
122CHECK([kill -0 `cat newmonitor`])
123CHECK([ps -o ppid= -p `cat newmonitor` > init])
c8dc7b46 124CHECK([test `cat init` != $$])
ff8decf1
BP
125# Kill the daemon process with SIGTERM, and wait for the daemon
126# and the monitor processes to go away and the pidfile to get deleted.
127CHECK([kill `cat daemon`], [0], [], [ignore])
128OVS_WAIT_WHILE(
129 [kill -0 `cat monitor` || kill -0 `cat newdaemon` || test -e daemon],
130 [kill `cat monitor newdaemon`])
131m4_undefine([CHECK])
132AT_CLEANUP
133
134AT_SETUP([daemon --detach startup errors])
135AT_CAPTURE_FILE([pid])
136OVSDB_INIT([db])
77a922c7 137AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr])
ff8decf1
BP
138AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
139 [0], [ignore], [])
140AT_CHECK([test ! -s pid])
141AT_CLEANUP
142
143AT_SETUP([daemon --detach --monitor startup errors])
144AT_CAPTURE_FILE([pid])
145OVSDB_INIT([db])
77a922c7 146AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --monitor --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr])
ff8decf1
BP
147AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
148 [0], [ignore], [])
149AT_CHECK([test ! -s pid])
150AT_CLEANUP