ยปCore Development>Code coverage>Lib/test/test_wait4.py

Python code coverage for Lib/test/test_wait4.py

#countcontent
1n/a"""This test checks for correct wait4() behavior.
2n/a"""
3n/a
4n/aimport os
5n/aimport time
6n/aimport sys
7n/aimport unittest
8n/afrom test.fork_wait import ForkWait
9n/afrom test.support import reap_children, get_attribute
10n/a
11n/a# If either of these do not exist, skip this test.
12n/aget_attribute(os, 'fork')
13n/aget_attribute(os, 'wait4')
14n/a
15n/a
16n/aclass Wait4Test(ForkWait):
17n/a def wait_impl(self, cpid):
18n/a option = os.WNOHANG
19n/a if sys.platform.startswith('aix'):
20n/a # Issue #11185: wait4 is broken on AIX and will always return 0
21n/a # with WNOHANG.
22n/a option = 0
23n/a deadline = time.monotonic() + 10.0
24n/a while time.monotonic() <= deadline:
25n/a # wait4() shouldn't hang, but some of the buildbots seem to hang
26n/a # in the forking tests. This is an attempt to fix the problem.
27n/a spid, status, rusage = os.wait4(cpid, option)
28n/a if spid == cpid:
29n/a break
30n/a time.sleep(0.1)
31n/a self.assertEqual(spid, cpid)
32n/a self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
33n/a self.assertTrue(rusage)
34n/a
35n/adef tearDownModule():
36n/a reap_children()
37n/a
38n/aif __name__ == "__main__":
39n/a unittest.main()