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 |
Zachary Ware | ac28b79 | 2015-12-04 23:32:23 -0600 | [diff] [blame^] | 7 | import unittest |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 8 | from test.fork_wait import ForkWait |
Zachary Ware | 38c707e | 2015-04-13 15:00:43 -0500 | [diff] [blame] | 9 | from test.support import reap_children, get_attribute |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 10 | |
R. David Murray | 6af6d26 | 2009-03-31 23:50:31 +0000 | [diff] [blame] | 11 | # If either of these do not exist, skip this test. |
| 12 | get_attribute(os, 'fork') |
| 13 | get_attribute(os, 'wait4') |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 14 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 15 | |
| 16 | class Wait4Test(ForkWait): |
| 17 | def wait_impl(self, cpid): |
Antoine Pitrou | be9c841 | 2013-07-04 21:03:10 +0200 | [diff] [blame] | 18 | option = os.WNOHANG |
| 19 | if sys.platform.startswith('aix'): |
| 20 | # Issue #11185: wait4 is broken on AIX and will always return 0 |
| 21 | # with WNOHANG. |
| 22 | option = 0 |
Victor Stinner | 1e48eb3 | 2014-03-18 00:39:04 +0100 | [diff] [blame] | 23 | deadline = time.monotonic() + 10.0 |
| 24 | while time.monotonic() <= deadline: |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 25 | # wait4() shouldn't hang, but some of the buildbots seem to hang |
| 26 | # in the forking tests. This is an attempt to fix the problem. |
Antoine Pitrou | be9c841 | 2013-07-04 21:03:10 +0200 | [diff] [blame] | 27 | spid, status, rusage = os.wait4(cpid, option) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 28 | if spid == cpid: |
| 29 | break |
Victor Stinner | 1e48eb3 | 2014-03-18 00:39:04 +0100 | [diff] [blame] | 30 | time.sleep(0.1) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 31 | self.assertEqual(spid, cpid) |
| 32 | self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) |
| 33 | self.assertTrue(rusage) |
| 34 | |
Zachary Ware | 38c707e | 2015-04-13 15:00:43 -0500 | [diff] [blame] | 35 | def tearDownModule(): |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 36 | reap_children() |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 37 | |
| 38 | if __name__ == "__main__": |
Zachary Ware | 38c707e | 2015-04-13 15:00:43 -0500 | [diff] [blame] | 39 | unittest.main() |