1ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh"""This test checks for correct wait3() behavior. 2ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh""" 3ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh 4ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsiehimport os 5ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsiehimport time 6ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsiehimport unittest 7ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsiehfrom test.fork_wait import ForkWait 8ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsiehfrom test.test_support import run_unittest, reap_children 9ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh 10ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsiehtry: 11ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh os.fork 12ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsiehexcept AttributeError: 13ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh raise unittest.SkipTest, "os.fork not defined -- skipping test_wait3" 14ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh 15ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsiehtry: 16ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh os.wait3 17ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsiehexcept AttributeError: 18ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh raise unittest.SkipTest, "os.wait3 not defined -- skipping test_wait3" 19ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh 20ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsiehclass Wait3Test(ForkWait): 21ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh def wait_impl(self, cpid): 22ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh for i in range(10): 23ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh # wait3() shouldn't hang, but some of the buildbots seem to hang 24ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh # in the forking tests. This is an attempt to fix the problem. 25ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh spid, status, rusage = os.wait3(os.WNOHANG) 26ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh if spid == cpid: 27ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh break 28ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh time.sleep(1.0) 29ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh 30ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh self.assertEqual(spid, cpid) 31ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) 32ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh self.assertTrue(rusage) 33ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh 34ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsiehdef test_main(): 35ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh run_unittest(Wait3Test) 36ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh reap_children() 37ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh 38ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsiehif __name__ == "__main__": 39ffab958fd8d42ed7227d83007350e61555a1fa36Andrew Hsieh test_main() 40