Neal Norwitz | 05a4559 | 2006-03-20 06:30:08 +0000 | [diff] [blame] | 1 | """This test checks for correct wait4() behavior. |
| 2 | """ |
| 3 | |
| 4 | import os |
Neal Norwitz | 84bc19a | 2006-07-07 06:03:15 +0000 | [diff] [blame] | 5 | import time |
Neal Norwitz | 05a4559 | 2006-03-20 06:30:08 +0000 | [diff] [blame] | 6 | from test.fork_wait import ForkWait |
R. David Murray | 840ac92 | 2009-03-31 23:45:39 +0000 | [diff] [blame^] | 7 | from test.test_support import run_unittest, reap_children, get_attribute |
Neal Norwitz | 05a4559 | 2006-03-20 06:30:08 +0000 | [diff] [blame] | 8 | |
R. David Murray | 840ac92 | 2009-03-31 23:45:39 +0000 | [diff] [blame^] | 9 | # If either of these do not exist, skip this test. |
| 10 | get_attribute(os, 'fork') |
| 11 | get_attribute(os, 'wait4') |
Neal Norwitz | 05a4559 | 2006-03-20 06:30:08 +0000 | [diff] [blame] | 12 | |
Neal Norwitz | 05a4559 | 2006-03-20 06:30:08 +0000 | [diff] [blame] | 13 | |
| 14 | class Wait4Test(ForkWait): |
| 15 | def wait_impl(self, cpid): |
Neal Norwitz | 84bc19a | 2006-07-07 06:03:15 +0000 | [diff] [blame] | 16 | 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) |
Neal Norwitz | 05a4559 | 2006-03-20 06:30:08 +0000 | [diff] [blame] | 23 | self.assertEqual(spid, cpid) |
| 24 | self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) |
| 25 | self.assertTrue(rusage) |
| 26 | |
| 27 | def test_main(): |
| 28 | run_unittest(Wait4Test) |
Neal Norwitz | b15ac31 | 2006-06-29 04:10:08 +0000 | [diff] [blame] | 29 | reap_children() |
Neal Norwitz | 05a4559 | 2006-03-20 06:30:08 +0000 | [diff] [blame] | 30 | |
| 31 | if __name__ == "__main__": |
| 32 | test_main() |