blob: 192fd9404152c8b2c15c9908bcc666312c71950a [file] [log] [blame]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001"""This test checks for correct wait4() behavior.
2"""
3
4import os
Thomas Wouters0e3f5912006-08-11 14:57:12 +00005import time
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00006from test.fork_wait import ForkWait
Benjamin Petersonee8712c2008-05-20 21:35:26 +00007from test.support import TestSkipped, run_unittest, reap_children
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00008
9try:
10 os.fork
11except AttributeError:
Collin Winter3add4d72007-08-29 23:37:32 +000012 raise TestSkipped("os.fork not defined -- skipping test_wait4")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000013
14try:
15 os.wait4
16except AttributeError:
Collin Winter3add4d72007-08-29 23:37:32 +000017 raise TestSkipped("os.wait4 not defined -- skipping test_wait4")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000018
19class Wait4Test(ForkWait):
20 def wait_impl(self, cpid):
Thomas Wouters0e3f5912006-08-11 14:57:12 +000021 for i in range(10):
22 # wait4() shouldn't hang, but some of the buildbots seem to hang
23 # in the forking tests. This is an attempt to fix the problem.
24 spid, status, rusage = os.wait4(cpid, os.WNOHANG)
25 if spid == cpid:
26 break
27 time.sleep(1.0)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000028 self.assertEqual(spid, cpid)
29 self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
30 self.assertTrue(rusage)
31
32def test_main():
33 run_unittest(Wait4Test)
Thomas Wouters0e3f5912006-08-11 14:57:12 +000034 reap_children()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000035
36if __name__ == "__main__":
37 test_main()