Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1 | """This test checks for correct wait4() behavior. |
| 2 | """ |
| 3 | |
| 4 | import os |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 5 | import time |
Antoine Pitrou | be9c841 | 2013-07-04 21:03:10 +0200 | [diff] [blame^] | 6 | import sys |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7 | from test.fork_wait import ForkWait |
R. David Murray | 6af6d26 | 2009-03-31 23:50:31 +0000 | [diff] [blame] | 8 | from test.support import run_unittest, reap_children, get_attribute |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 9 | |
R. David Murray | 6af6d26 | 2009-03-31 23:50:31 +0000 | [diff] [blame] | 10 | # If either of these do not exist, skip this test. |
| 11 | get_attribute(os, 'fork') |
| 12 | get_attribute(os, 'wait4') |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 13 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 14 | |
| 15 | class Wait4Test(ForkWait): |
| 16 | def wait_impl(self, cpid): |
Antoine Pitrou | be9c841 | 2013-07-04 21:03:10 +0200 | [diff] [blame^] | 17 | 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 Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 22 | 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 Pitrou | be9c841 | 2013-07-04 21:03:10 +0200 | [diff] [blame^] | 25 | spid, status, rusage = os.wait4(cpid, option) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 26 | if spid == cpid: |
| 27 | break |
| 28 | time.sleep(1.0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 29 | self.assertEqual(spid, cpid) |
| 30 | self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) |
| 31 | self.assertTrue(rusage) |
| 32 | |
| 33 | def test_main(): |
| 34 | run_unittest(Wait4Test) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 35 | reap_children() |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 36 | |
| 37 | if __name__ == "__main__": |
| 38 | test_main() |