blob: 474a15b9dbfc941c89e7194d2d9ae0db786a89f6 [file] [log] [blame]
Neal Norwitz05a45592006-03-20 06:30:08 +00001"""This test checks for correct wait3() behavior.
2"""
3
4import os
Neal Norwitz84bc19a2006-07-07 06:03:15 +00005import time
Neal Norwitz05a45592006-03-20 06:30:08 +00006from test.fork_wait import ForkWait
Benjamin Peterson888a39b2009-03-26 20:48:25 +00007from test.test_support import SkipTest, run_unittest, reap_children
Neal Norwitz05a45592006-03-20 06:30:08 +00008
9try:
10 os.fork
11except AttributeError:
Benjamin Peterson888a39b2009-03-26 20:48:25 +000012 raise SkipTest, "os.fork not defined -- skipping test_wait3"
Neal Norwitz05a45592006-03-20 06:30:08 +000013
14try:
15 os.wait3
16except AttributeError:
Benjamin Peterson888a39b2009-03-26 20:48:25 +000017 raise SkipTest, "os.wait3 not defined -- skipping test_wait3"
Neal Norwitz05a45592006-03-20 06:30:08 +000018
19class Wait3Test(ForkWait):
20 def wait_impl(self, cpid):
Neal Norwitz84bc19a2006-07-07 06:03:15 +000021 for i in range(10):
22 # wait3() 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.wait3(os.WNOHANG)
Anthony Baxter46fa48a2006-03-20 07:10:01 +000025 if spid == cpid:
26 break
Neal Norwitz84bc19a2006-07-07 06:03:15 +000027 time.sleep(1.0)
28
Neal Norwitz05a45592006-03-20 06:30:08 +000029 self.assertEqual(spid, cpid)
30 self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
31 self.assertTrue(rusage)
32
33def test_main():
34 run_unittest(Wait3Test)
Neal Norwitzb15ac312006-06-29 04:10:08 +000035 reap_children()
Neal Norwitz05a45592006-03-20 06:30:08 +000036
37if __name__ == "__main__":
38 test_main()