Setting tag sliver-openvswitch-2.2.90-1
[sliver-openvswitch.git] / tests / daemon.at
1 AT_BANNER([daemon unit tests - C])
2
3 AT_SETUP([daemon])
4 OVSDB_INIT([db])
5 AT_CAPTURE_FILE([pid])
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 2>/dev/null & echo $! > expected], [0])
10 OVS_WAIT_UNTIL([test -s pid], [kill `cat expected`])
11 AT_CHECK(
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.
16 kill `cat expected`
17 OVS_WAIT_WHILE([kill -0 `cat expected`])
18 AT_CHECK([test ! -e pid])
19 AT_CLEANUP
20
21 AT_SETUP([daemon --monitor])
22 OVSDB_INIT([db])
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 2>/dev/null & 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`])
35 AT_CHECK(
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).
42 OVS_WAIT_UNTIL(
43   [ovs-appctl --timeout=10 -t "`pwd`/unixctl" version],
44   [kill `cat pid`])
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`],
51   [kill `cat parent`])
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`])
57 AT_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.
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],
66   [kill `cat parent`])
67 AT_CLEANUP
68
69 AT_SETUP([daemon --detach])
70 AT_CAPTURE_FILE([pid])
71 OVSDB_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.
75 AT_CHECK([ovsdb-server --detach --no-chdir --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.
79 cp pid saved-pid
80 kill `cat pid`
81 OVS_WAIT_WHILE([kill -0 `cat saved-pid`])
82 AT_CHECK([test ! -e pid])
83 AT_CLEANUP
84
85 AT_SETUP([daemon --detach --monitor])
86 m4_define([CHECK], 
87   [AT_CHECK([$1], [$2], [$3], [$4], [kill `cat daemon monitor`])])
88 OVSDB_INIT([db])
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 --no-chdir --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` != $$])
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` != $$])
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])
128 OVS_WAIT_WHILE(
129   [kill -0 `cat monitor` || kill -0 `cat newdaemon` || test -e daemon],
130   [kill `cat monitor newdaemon`])
131 m4_undefine([CHECK])
132 AT_CLEANUP
133
134 AT_SETUP([daemon --detach startup errors])
135 AT_CAPTURE_FILE([pid])
136 OVSDB_INIT([db])
137 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr])
138 AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
139   [0], [ignore], [])
140 AT_CHECK([test ! -s pid])
141 AT_CLEANUP
142
143 AT_SETUP([daemon --detach --monitor startup errors])
144 AT_CAPTURE_FILE([pid])
145 OVSDB_INIT([db])
146 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/pid --monitor --unixctl="`pwd`"/nonexistent/unixctl db], [1], [], [stderr])
147 AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
148   [0], [ignore], [])
149 AT_CHECK([test ! -s pid])
150 AT_CLEANUP