1 AT_BANNER([daemon unit tests - Python3])
3 AT_SETUP([daemon - Python3])
4 # Skip this test for Windows, echo $! gives shell pid instead of parent process
5 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
6 AT_KEYWORDS([python daemon])
8 on_exit 'kill $(cat *.pid)'
9 pidfile=test-daemon.py.pid
11 # Start the daemon and wait for the pidfile to get created
12 # and that its contents are the correct pid.
13 AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile & echo $!], [0], [stdout])
16 OVS_WAIT_UNTIL([test -s $pidfile], [kill $pid])
17 AT_CHECK([test $pid = $(cat $pidfile)])
18 AT_CHECK([kill -0 $pid])
20 # Kill the daemon and make sure that the pidfile gets deleted.
22 OVS_WAIT_WHILE([kill -0 $pid])
23 AT_CHECK([test ! -e $pidfile])
26 AT_SETUP([daemon --monitor - Python3])
27 # Skip this test for Windows, echo $! gives shell pid instead of parent process
28 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
30 on_exit 'kill $(cat *.pid)'
31 pidfile=test-daemon.py.pid
33 # Start the daemon and wait for the pidfile to get created.
34 AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --monitor & echo $!], [0], [stdout])
36 OVS_WAIT_UNTIL([test -s $pidfile])
39 # Check that the pidfile names a running process,
40 # and that the parent process of that process is our child process.
41 check_ancestors $child $monitor
43 # Kill the daemon process, making it look like a segfault,
44 # and wait for a new child process to get spawned.
45 AT_CHECK([kill -SEGV $child])
46 OVS_WAIT_WHILE([kill -0 $child])
47 OVS_WAIT_UNTIL([test -s $pidfile && test $(cat $pidfile) != $child])
48 child2=$(cat $pidfile)
50 # Check that the pidfile names a running process,
51 # and that the parent process of that process is our child process.
52 check_ancestors $child2 $monitor
54 # Kill the daemon process with SIGTERM, and wait for the daemon
55 # and the monitor processes to go away and the pidfile to get deleted.
56 AT_CHECK([kill $child2])
57 OVS_WAIT_WHILE([kill -0 $monitor || kill -0 $child2 || test -e $pidfile])
60 AT_SETUP([daemon --monitor restart exit code - Python3])
61 # Skip this test for Windows, echo $! gives shell pid instead of parent process
62 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
64 on_exit 'kill $(cat *.pid)'
65 pidfile=test-daemon.py.pid
67 # Start the daemon and wait for the pidfile to get created.
68 AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --monitor & echo $!], [0], [stdout])
70 OVS_WAIT_UNTIL([test -s $pidfile])
73 # Check that the pidfile names a running process,
74 # and that the parent process of that process is our child process.
75 check_ancestors $child $monitor
77 # HUP the daemon process causing it to throw an exception,
78 # and wait for a new child process to get spawned.
79 AT_CHECK([kill -HUP $child])
80 OVS_WAIT_WHILE([kill -0 $child])
81 OVS_WAIT_UNTIL([test -s $pidfile && test $child != $(cat $pidfile)])
82 child2=$(cat $pidfile)
84 # Check that the pidfile names a running process,
85 # and that the parent process of that process is our child process.
86 check_ancestors $child2 $monitor
88 # Kill the daemon process with SIGTERM, and wait for the daemon
89 # and the monitor processes to go away and the pidfile to get deleted.
90 AT_CHECK([kill $child2])
91 OVS_WAIT_WHILE([kill -0 $monitor || kill -0 $child2 || test -e $pidfile])
94 AT_SETUP([daemon --detach - Python3])
96 # Skip this test for Windows, the pid file not removed if the daemon is killed
97 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
99 on_exit 'kill $(cat *.pid)'
100 pidfile=test-daemon.py.pid
102 # Start the daemon and make sure that the pidfile exists immediately.
103 # We don't wait for the pidfile to get created because the daemon is
104 # supposed to do so before the parent exits.
105 AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir], [0])
106 AT_CHECK([test -s $pidfile])
108 check_ancestors $pid 1
110 # Kill the daemon and make sure that the pidfile gets deleted.
111 AT_CHECK([kill $pid])
112 OVS_WAIT_WHILE([kill -0 $pid])
113 AT_CHECK([test ! -e $pidfile])
116 AT_SETUP([daemon --detach --monitor - Python3])
118 # Skip this test for Windows, uses Linux specific kill signal
119 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
121 on_exit 'kill $(cat *.pid)'
122 pidfile=test-daemon.py.pid
124 # Start the daemon and make sure that the pidfile exists immediately.
125 # We don't wait for the pidfile to get created because the daemon is
126 # supposed to do so before the parent exits.
127 AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir --monitor], [0])
128 AT_CHECK([test -s $pidfile])
129 child=$(cat $pidfile)
130 AT_CHECK([parent_pid $child], [0], [stdout])
131 monitor=$(cat stdout)
133 # Check that the pidfile names a running process,
134 # and that the parent process of that process is a running process,
135 # and that the parent process of that process is init.
136 check_ancestors $child $monitor 1
138 # Kill the daemon process, making it look like a segfault,
139 # and wait for a new daemon process to get spawned.
140 AT_CHECK([kill -SEGV $child])
141 OVS_WAIT_WHILE([kill -0 $child])
142 OVS_WAIT_UNTIL([test -s $pidfile && test $(cat $pidfile) != $child])
143 child2=$(cat $pidfile)
145 # Check that the pidfile names a running process,
146 # and that the parent process of that process is our child process.
147 check_ancestors $child2 $monitor 1
149 # Kill the daemon process with SIGTERM, and wait for the daemon
150 # and the monitor processes to go away and the pidfile to get deleted.
151 AT_CHECK([kill $child2])
152 OVS_WAIT_WHILE([kill -0 $child2 || kill -0 $monitor || test -e $pidfile])
155 AT_SETUP([daemon --detach startup errors - Python3])
156 AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir --bail], [1], [], [stderr])
157 AT_CHECK([grep 'test-daemon.py: exiting after daemonize_start() as requested' stderr],
159 AT_CHECK([test ! -s test-daemon.py.pid])
162 AT_SETUP([daemon --detach --monitor startup errors - Python3])
163 AT_CAPTURE_FILE([pid])
164 AT_CHECK([$PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir --monitor --bail], [1], [], [stderr])
165 AT_CHECK([grep 'test-daemon.py: exiting after daemonize_start() as requested' stderr],
167 AT_CHECK([test ! -s test-daemon.py.pid])
170 AT_SETUP([daemon --detach closes standard fds - Python3])
171 # Skip this test for Windows, uses Linux specific kill signal
172 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
174 AT_CHECK([(yes 2>stderr; echo $? > status) | $PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir])
175 AT_CHECK([kill $(cat test-daemon.py.pid)])
176 AT_CHECK([test -s status])
177 if grep '[[bB]]roken pipe' stderr >/dev/null 2>&1; then
178 # Something in the environment caused SIGPIPE to be ignored, but
179 # 'yes' at least told us that it got EPIPE. Good enough; we know
180 # that stdout was closed.
183 # Otherwise make sure that 'yes' died from SIGPIPE.
184 AT_CHECK([kill -l `cat status`], [0], [PIPE
189 AT_SETUP([daemon --detach --monitor closes standard fds - Python3])
190 # Skip this test for Windows, uses Linux specific kill signal
191 AT_SKIP_IF([test "$IS_WIN32" = "yes"])
192 AT_CHECK([(yes 2>stderr; echo $? > status) | $PYTHON3 $srcdir/test-daemon.py --pidfile --detach --no-chdir], [0], [], [])
193 AT_CHECK([kill $(cat test-daemon.py.pid)])
194 AT_CHECK([test -s status])
195 if grep '[[bB]]roken pipe' stderr >/dev/null 2>&1; then
196 # Something in the environment caused SIGPIPE to be ignored, but
197 # 'yes' at least told us that it got EPIPE. Good enough; we know
198 # that stdout was closed.
201 # Otherwise make sure that 'yes' died from SIGPIPE.
202 AT_CHECK([kill -l `cat status`], [0], [PIPE