test_wait3.py 1.04 KB
Newer Older
1 2 3 4
"""This test checks for correct wait3() behavior.
"""

import os
Neal Norwitz's avatar
Neal Norwitz committed
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 11 12

try:
    os.fork
except AttributeError:
13
    raise unittest.SkipTest, "os.fork not defined -- skipping test_wait3"
14 15 16 17

try:
    os.wait3
except AttributeError:
18
    raise unittest.SkipTest, "os.wait3 not defined -- skipping test_wait3"
19 20 21

class Wait3Test(ForkWait):
    def wait_impl(self, cpid):
Neal Norwitz's avatar
Neal Norwitz committed
22 23 24 25
        for i in range(10):
            # wait3() shouldn't hang, but some of the buildbots seem to hang
            # in the forking tests.  This is an attempt to fix the problem.
            spid, status, rusage = os.wait3(os.WNOHANG)
Anthony Baxter's avatar
Anthony Baxter committed
26 27
            if spid == cpid:
                break
Neal Norwitz's avatar
Neal Norwitz committed
28 29
            time.sleep(1.0)

30 31 32 33 34 35
        self.assertEqual(spid, cpid)
        self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
        self.assertTrue(rusage)

def test_main():
    run_unittest(Wait3Test)
36
    reap_children()
37 38 39

if __name__ == "__main__":
    test_main()