blob: cdcd0604b7ceaba068aad599d114c05b72b46a26 [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
R. David Murray6af6d262009-03-31 23:50:31 +00007from test.support import run_unittest, reap_children, get_attribute
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00008
R. David Murray6af6d262009-03-31 23:50:31 +00009# If either of these do not exist, skip this test.
10get_attribute(os, 'fork')
11get_attribute(os, 'wait4')
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000012
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000013
14class Wait4Test(ForkWait):
15 def wait_impl(self, cpid):
Thomas Wouters0e3f5912006-08-11 14:57:12 +000016 for i in range(10):
17 # wait4() shouldn't hang, but some of the buildbots seem to hang
18 # in the forking tests. This is an attempt to fix the problem.
19 spid, status, rusage = os.wait4(cpid, os.WNOHANG)
20 if spid == cpid:
21 break
22 time.sleep(1.0)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000023 self.assertEqual(spid, cpid)
24 self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
25 self.assertTrue(rusage)
26
27def test_main():
28 run_unittest(Wait4Test)
Thomas Wouters0e3f5912006-08-11 14:57:12 +000029 reap_children()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000030
31if __name__ == "__main__":
32 test_main()