summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_wait3.py
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2019-09-09 15:48:32 (GMT)
committerT. Wouters <thomas@python.org>2019-09-09 15:48:32 (GMT)
commit682107cf458578ee6bd92b7cc6862113034a4fad (patch)
treeccde00cbac424b2a41058fddb53c003d06ea8885 /Lib/test/test_wait3.py
parentd91d4de31745fc1ed4c7e6c208917827c9c472b6 (diff)
downloadcpython-682107cf458578ee6bd92b7cc6862113034a4fad.zip
cpython-682107cf458578ee6bd92b7cc6862113034a4fad.tar.gz
cpython-682107cf458578ee6bd92b7cc6862113034a4fad.tar.bz2
bpo-36279: Ensure os.wait3() rusage is initialized (GH-15111)
Co-Authored-By: David Wilson <dw@botanicus.net>
Diffstat (limited to 'Lib/test/test_wait3.py')
-rw-r--r--Lib/test/test_wait3.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_wait3.py b/Lib/test/test_wait3.py
index eb51b2c..3825451 100644
--- a/Lib/test/test_wait3.py
+++ b/Lib/test/test_wait3.py
@@ -2,6 +2,8 @@
"""
import os
+import subprocess
+import sys
import time
import unittest
from test.fork_wait import ForkWait
@@ -31,6 +33,22 @@ class Wait3Test(ForkWait):
self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
self.assertTrue(rusage)
+ def test_wait3_rusage_initialized(self):
+ # Ensure a successful wait3() call where no child was ready to report
+ # its exit status does not return uninitialized memory in the rusage
+ # structure. See bpo-36279.
+ args = [sys.executable, '-c', 'import sys; sys.stdin.read()']
+ proc = subprocess.Popen(args, stdin=subprocess.PIPE)
+ try:
+ pid, status, rusage = os.wait3(os.WNOHANG)
+ self.assertEqual(0, pid)
+ self.assertEqual(0, status)
+ self.assertEqual(0, sum(rusage))
+ finally:
+ proc.stdin.close()
+ proc.wait()
+
+
def tearDownModule():
reap_children()