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 |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6 | from test.fork_wait import ForkWait |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 7 | from test.support import TestSkipped, run_unittest, reap_children |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 8 | |
| 9 | try: |
| 10 | os.fork |
| 11 | except AttributeError: |
Collin Winter | 3add4d7 | 2007-08-29 23:37:32 +0000 | [diff] [blame] | 12 | raise TestSkipped("os.fork not defined -- skipping test_wait4") |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 13 | |
| 14 | try: |
| 15 | os.wait4 |
| 16 | except AttributeError: |
Collin Winter | 3add4d7 | 2007-08-29 23:37:32 +0000 | [diff] [blame] | 17 | raise TestSkipped("os.wait4 not defined -- skipping test_wait4") |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 18 | |
| 19 | class Wait4Test(ForkWait): |
| 20 | def wait_impl(self, cpid): |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 21 | 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 Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 28 | self.assertEqual(spid, cpid) |
| 29 | self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) |
| 30 | self.assertTrue(rusage) |
| 31 | |
| 32 | def test_main(): |
| 33 | run_unittest(Wait4Test) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 34 | reap_children() |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 35 | |
| 36 | if __name__ == "__main__": |
| 37 | test_main() |