blob: 150783b6555e3b3b768fc16b99ba6c267cd28839 [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
Benjamin Petersonbec087f2009-03-26 21:10:30 +00006import unittest
Neal Norwitz05a45592006-03-20 06:30:08 +00007from test.fork_wait import ForkWait
Benjamin Petersonbec087f2009-03-26 21:10:30 +00008from test.test_support import run_unittest, reap_children
Neal Norwitz05a45592006-03-20 06:30:08 +00009
10try:
11 os.fork
12except AttributeError:
Benjamin Petersonbec087f2009-03-26 21:10:30 +000013 raise unittest.SkipTest, "os.fork not defined -- skipping test_wait3"
Neal Norwitz05a45592006-03-20 06:30:08 +000014
15try:
16 os.wait3
17except AttributeError:
Benjamin Petersonbec087f2009-03-26 21:10:30 +000018 raise unittest.SkipTest, "os.wait3 not defined -- skipping test_wait3"
Neal Norwitz05a45592006-03-20 06:30:08 +000019
20class Wait3Test(ForkWait):
21 def wait_impl(self, cpid):
Neal Norwitz84bc19a2006-07-07 06:03:15 +000022 for i in range(10):
23 # wait3() shouldn't hang, but some of the buildbots seem to hang
24 # in the forking tests. This is an attempt to fix the problem.
25 spid, status, rusage = os.wait3(os.WNOHANG)
Anthony Baxter46fa48a2006-03-20 07:10:01 +000026 if spid == cpid:
27 break
Neal Norwitz84bc19a2006-07-07 06:03:15 +000028 time.sleep(1.0)
29
Neal Norwitz05a45592006-03-20 06:30:08 +000030 self.assertEqual(spid, cpid)
31 self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
32 self.assertTrue(rusage)
33
34def test_main():
35 run_unittest(Wait3Test)
Neal Norwitzb15ac312006-06-29 04:10:08 +000036 reap_children()
Neal Norwitz05a45592006-03-20 06:30:08 +000037
38if __name__ == "__main__":
39 test_main()