blob: 3adbec4abc33ffbc54d98531725dab73356d29ac [file] [log] [blame]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001"""This test checks for correct wait3() behavior.
2"""
3
4import os
Thomas Wouters0e3f5912006-08-11 14:57:12 +00005import time
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00006from test.fork_wait import ForkWait
Thomas Wouters0e3f5912006-08-11 14:57:12 +00007from test.test_support import TestSkipped, run_unittest, reap_children
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00008
9try:
10 os.fork
11except AttributeError:
Collin Winter3add4d72007-08-29 23:37:32 +000012 raise TestSkipped("os.fork not defined -- skipping test_wait3")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000013
14try:
15 os.wait3
16except AttributeError:
Collin Winter3add4d72007-08-29 23:37:32 +000017 raise TestSkipped("os.wait3 not defined -- skipping test_wait3")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000018
19class Wait3Test(ForkWait):
20 def wait_impl(self, cpid):
Thomas Wouters0e3f5912006-08-11 14:57:12 +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)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000025 if spid == cpid:
26 break
Thomas Wouters0e3f5912006-08-11 14:57:12 +000027 time.sleep(1.0)
28
Thomas Wouters49fd7fa2006-04-21 10:40:58 +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)
Thomas Wouters0e3f5912006-08-11 14:57:12 +000035 reap_children()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000036
37if __name__ == "__main__":
38 test_main()