1 AT_BANNER([daemon unit tests - C])
6 AT_CAPTURE_FILE([expected])
7 # Start the daemon and wait for the pidfile to get created
8 # and that its contents are the correct pid.
9 AT_CHECK([ovsdb-server --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db& echo $! > expected], [0])
10 OVS_WAIT_UNTIL([test -s pid], [kill `cat expected`])
12 [pid=`cat pid` && expected=`cat expected` && test "$pid" = "$expected"],
13 [0], [], [], [kill `cat expected`])
14 AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat expected`])
15 # Kill the daemon and make sure that the pidfile gets deleted.
17 OVS_WAIT_WHILE([kill -0 `cat expected`])
18 AT_CHECK([test ! -e pid])
21 AT_SETUP([daemon --monitor])
23 AT_CAPTURE_FILE([pid])
24 AT_CAPTURE_FILE([parent])
25 AT_CAPTURE_FILE([parentpid])
26 AT_CAPTURE_FILE([newpid])
27 # Start the daemon and wait for the pidfile to get created.
28 AT_CHECK([ovsdb-server --monitor --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db& echo $! > parent], [0])
29 OVS_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.
32 AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat parent`])
33 AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
34 [0], [], [], [kill `cat parent`])
36 [parentpid=`cat parentpid` &&
37 parent=`cat parent` &&
38 test $parentpid = $parent],
39 [0], [], [], [kill `cat parent`])
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).
43 [ovs-appctl --timeout=10 -t "`pwd`/unixctl" version],
45 # Kill the daemon process, making it look like a segfault,
46 # and wait for a new child process to get spawned.
47 AT_CHECK([cp pid oldpid], [0], [], [], [kill `cat parent`])
48 AT_CHECK([kill -SEGV `cat pid`], [0], [], [ignore], [kill `cat parent`])
49 OVS_WAIT_WHILE([kill -0 `cat oldpid`], [kill `cat parent`])
50 OVS_WAIT_UNTIL([test -s pid && test `cat pid` != `cat oldpid`],
52 AT_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.
55 AT_CHECK([ps -o ppid= -p `cat pid` > parentpid],
56 [0], [], [], [kill `cat parent`])
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.
64 AT_CHECK([kill `cat pid`], [0], [], [ignore], [kill `cat parent`])
65 OVS_WAIT_WHILE([kill -0 `cat parent` || kill -0 `cat newpid` || test -e pid],
69 AT_SETUP([daemon --detach])
70 AT_CAPTURE_FILE([pid])
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.
75 AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0])
76 AT_CHECK([test -s pid])
77 AT_CHECK([kill -0 `cat pid`])
78 # Kill the daemon and make sure that the pidfile gets deleted.
81 OVS_WAIT_WHILE([kill -0 `cat saved-pid`])
82 AT_CHECK([test ! -e pid])
85 AT_SETUP([daemon --detach --monitor])
87 [AT_CHECK([$1], [$2], [$3], [$4], [kill `cat daemon monitor`])])
89 AT_CAPTURE_FILE([daemon])
90 AT_CAPTURE_FILE([olddaemon])
91 AT_CAPTURE_FILE([newdaemon])
92 AT_CAPTURE_FILE([monitor])
93 AT_CAPTURE_FILE([newmonitor])
94 AT_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.
98 AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/daemon --monitor --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0])
99 AT_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.
103 CHECK([kill -0 `cat daemon`])
104 CHECK([ps -o ppid= -p `cat daemon` > monitor])
105 CHECK([kill -0 `cat monitor`])
106 CHECK([ps -o ppid= -p `cat monitor` > init])
107 CHECK([test `cat init` = 1])
108 # Kill the daemon process, making it look like a segfault,
109 # and wait for a new daemon process to get spawned.
110 CHECK([cp daemon olddaemon])
111 CHECK([kill -SEGV `cat daemon`], [0])
112 OVS_WAIT_WHILE([kill -0 `cat olddaemon`], [kill `cat olddaemon daemon`])
113 OVS_WAIT_UNTIL([test -s daemon && test `cat daemon` != `cat olddaemon`],
114 [kill `cat olddaemon daemon`])
115 CHECK([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.
118 CHECK([kill -0 `cat daemon`])
119 CHECK([diff olddaemon newdaemon], [1], [ignore])
120 CHECK([ps -o ppid= -p `cat daemon` > newmonitor])
121 CHECK([diff monitor newmonitor])
122 CHECK([kill -0 `cat newmonitor`])
123 CHECK([ps -o ppid= -p `cat newmonitor` > init])
124 CHECK([test `cat init` = 1])
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.
127 CHECK([kill `cat daemon`], [0], [], [ignore])
129 [kill -0 `cat monitor` || kill -0 `cat newdaemon` || test -e daemon],
130 [kill `cat monitor newdaemon`])
134 AT_SETUP([daemon --detach startup errors])
135 AT_CAPTURE_FILE([pid])
137 AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/pid --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr])
138 AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
140 AT_CHECK([test ! -s pid])
143 AT_SETUP([daemon --detach --monitor startup errors])
144 AT_CAPTURE_FILE([pid])
146 AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/pid --monitor --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr])
147 AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
149 AT_CHECK([test ! -s pid])