Home | History | Annotate | Download | only in test
      1 """This test checks for correct wait3() behavior.
      2 """
      3 
      4 import os
      5 import time
      6 import unittest
      7 from test.fork_wait import ForkWait
      8 from test.test_support import run_unittest, reap_children
      9 
     10 try:
     11     os.fork
     12 except AttributeError:
     13     raise unittest.SkipTest, "os.fork not defined -- skipping test_wait3"
     14 
     15 try:
     16     os.wait3
     17 except AttributeError:
     18     raise unittest.SkipTest, "os.wait3 not defined -- skipping test_wait3"
     19 
     20 class Wait3Test(ForkWait):
     21     def wait_impl(self, cpid):
     22         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)
     26             if spid == cpid:
     27                 break
     28             time.sleep(1.0)
     29 
     30         self.assertEqual(spid, cpid)
     31         self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
     32         self.assertTrue(rusage)
     33 
     34 def test_main():
     35     run_unittest(Wait3Test)
     36     reap_children()
     37 
     38 if __name__ == "__main__":
     39     test_main()
     40