Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1 | """This test checks for correct wait3() behavior. |
| 2 | """ |
| 3 | |
| 4 | import os |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 5 | import time |
Benjamin Peterson | e549ead | 2009-03-28 21:42:05 +0000 | [diff] [blame] | 6 | import unittest |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7 | from test.fork_wait import ForkWait |
Benjamin Peterson | e549ead | 2009-03-28 21:42:05 +0000 | [diff] [blame] | 8 | from test.support import run_unittest, reap_children |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 9 | |
| 10 | try: |
| 11 | os.fork |
| 12 | except AttributeError: |
Benjamin Peterson | e549ead | 2009-03-28 21:42:05 +0000 | [diff] [blame] | 13 | raise unittest.SkipTest("os.fork not defined -- skipping test_wait3") |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 14 | |
| 15 | try: |
| 16 | os.wait3 |
| 17 | except AttributeError: |
Benjamin Peterson | e549ead | 2009-03-28 21:42:05 +0000 | [diff] [blame] | 18 | raise unittest.SkipTest("os.wait3 not defined -- skipping test_wait3") |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 19 | |
| 20 | class Wait3Test(ForkWait): |
| 21 | def wait_impl(self, cpid): |
Antoine Pitrou | 606c3f5 | 2011-05-09 21:17:02 +0200 | [diff] [blame] | 22 | # This many iterations can be required, since some previously run |
| 23 | # tests (e.g. test_ctypes) could have spawned a lot of children |
| 24 | # very quickly. |
| 25 | for i in range(30): |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 26 | # wait3() shouldn't hang, but some of the buildbots seem to hang |
| 27 | # in the forking tests. This is an attempt to fix the problem. |
| 28 | spid, status, rusage = os.wait3(os.WNOHANG) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 29 | if spid == cpid: |
| 30 | break |
Antoine Pitrou | 606c3f5 | 2011-05-09 21:17:02 +0200 | [diff] [blame] | 31 | time.sleep(0.1) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 32 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 33 | self.assertEqual(spid, cpid) |
| 34 | self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) |
| 35 | self.assertTrue(rusage) |
| 36 | |
| 37 | def test_main(): |
| 38 | run_unittest(Wait3Test) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 39 | reap_children() |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 40 | |
| 41 | if __name__ == "__main__": |
| 42 | test_main() |