blob: 352c11aadec36d042a64e68eae14ff7b342bf847 [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
Antoine Pitroube9c8412013-07-04 21:03:10 +02006import sys
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00007from test.fork_wait import ForkWait
R. David Murray6af6d262009-03-31 23:50:31 +00008from test.support import run_unittest, reap_children, get_attribute
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00009
R. David Murray6af6d262009-03-31 23:50:31 +000010# If either of these do not exist, skip this test.
11get_attribute(os, 'fork')
12get_attribute(os, 'wait4')
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000013
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000014
15class Wait4Test(ForkWait):
16 def wait_impl(self, cpid):
Antoine Pitroube9c8412013-07-04 21:03:10 +020017 option = os.WNOHANG
18 if sys.platform.startswith('aix'):
19 # Issue #11185: wait4 is broken on AIX and will always return 0
20 # with WNOHANG.
21 option = 0
Thomas Wouters0e3f5912006-08-11 14:57:12 +000022 for i in range(10):
23 # wait4() shouldn't hang, but some of the buildbots seem to hang
24 # in the forking tests. This is an attempt to fix the problem.
Antoine Pitroube9c8412013-07-04 21:03:10 +020025 spid, status, rusage = os.wait4(cpid, option)
Thomas Wouters0e3f5912006-08-11 14:57:12 +000026 if spid == cpid:
27 break
28 time.sleep(1.0)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000029 self.assertEqual(spid, cpid)
30 self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
31 self.assertTrue(rusage)
32
33def test_main():
34 run_unittest(Wait4Test)
Thomas Wouters0e3f5912006-08-11 14:57:12 +000035 reap_children()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000036
37if __name__ == "__main__":
38 test_main()