blob: fee593e1e86aa55687fb5bdc7a34173d47ffba6b [file] [log] [blame]
Neal Norwitz05a45592006-03-20 06:30:08 +00001"""This test checks for correct wait4() behavior.
2"""
3
4import os
Neal Norwitz10b835c2006-06-18 19:37:40 +00005import time
Neal Norwitz05a45592006-03-20 06:30:08 +00006from test.fork_wait import ForkWait
7from test.test_support import TestSkipped, run_unittest
8
9try:
10 os.fork
11except AttributeError:
12 raise TestSkipped, "os.fork not defined -- skipping test_wait4"
13
14try:
15 os.wait4
16except AttributeError:
17 raise TestSkipped, "os.wait4 not defined -- skipping test_wait4"
18
19class Wait4Test(ForkWait):
20 def wait_impl(self, cpid):
Neal Norwitz10b835c2006-06-18 19:37:40 +000021 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)
Neal Norwitz05a45592006-03-20 06:30:08 +000028 self.assertEqual(spid, cpid)
29 self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
30 self.assertTrue(rusage)
31
32def test_main():
33 run_unittest(Wait4Test)
34
35if __name__ == "__main__":
36 test_main()