Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(166610)

Delta Between Two Patch Sets: Lib/test/test_cmd_line.py

Issue 18756: os.urandom() fails under high load
Left Patch Set: Created 5 years, 11 months ago
Right Patch Set: Created 5 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « Include/pythonrun.h ('k') | Lib/test/test_os.py » ('j') | Python/random.c » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 # Tests invocation of the interpreter with various command line arguments 1 # Tests invocation of the interpreter with various command line arguments
2 # Most tests are executed with environment variables ignored 2 # Most tests are executed with environment variables ignored
3 # See test_cmd_line_script.py for testing of script execution 3 # See test_cmd_line_script.py for testing of script execution
4 4
5 import test.support, unittest 5 import test.support, unittest
6 import os 6 import os
7 import shutil 7 import shutil
8 import sys 8 import sys
9 import subprocess 9 import subprocess
10 import tempfile 10 import tempfile
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 rc, out, err = assert_python_ok('-c', code) 354 rc, out, err = assert_python_ok('-c', code)
355 self.assertEqual(b'', err) 355 self.assertEqual(b'', err)
356 356
357 # Issue #7111: Python should work without standard streams 357 # Issue #7111: Python should work without standard streams
358 358
359 @unittest.skipIf(os.name != 'posix', "test needs POSIX semantics") 359 @unittest.skipIf(os.name != 'posix', "test needs POSIX semantics")
360 def _test_no_stdio(self, streams): 360 def _test_no_stdio(self, streams):
361 code = """if 1: 361 code = """if 1:
362 import os, sys 362 import os, sys
363 for i, s in enumerate({streams}): 363 for i, s in enumerate({streams}):
364 print(i, s)
Benjamin Peterson 2013/08/24 21:54:05 *cough*
364 if getattr(sys, s) is not None: 365 if getattr(sys, s) is not None:
365 os._exit(i + 1) 366 sys.exit(i + 1)
366 os._exit(42)""".format(streams=streams) 367 if os.name == 'posix':
368 # urandom() uses an early-allocated fd on POSIX, check
369 # that the fd wasn't butchered.
370 os.urandom(1)
371 sys.exit(42)""".format(streams=streams)
367 def preexec(): 372 def preexec():
368 if 'stdin' in streams: 373 if 'stdin' in streams:
369 os.close(0) 374 os.close(0)
370 if 'stdout' in streams: 375 if 'stdout' in streams:
371 os.close(1) 376 os.close(1)
372 if 'stderr' in streams: 377 if 'stderr' in streams:
373 os.close(2) 378 os.close(2)
374 p = subprocess.Popen( 379 p = subprocess.Popen(
375 [sys.executable, "-E", "-c", code], 380 [sys.executable, "-E", "-c", code],
376 stdin=subprocess.PIPE, 381 stdin=subprocess.PIPE,
377 stdout=subprocess.PIPE, 382 stdout=subprocess.PIPE,
378 stderr=subprocess.PIPE, 383 stderr=subprocess.PIPE,
379 preexec_fn=preexec) 384 preexec_fn=preexec)
380 out, err = p.communicate() 385 out, err = p.communicate()
381 self.assertEqual(test.support.strip_python_stderr(err), b'') 386 self.assertEqual(test.support.strip_python_stderr(err), b'')
382 self.assertEqual(p.returncode, 42) 387 self.assertEqual(p.returncode, 42, out)
383 388
384 def test_no_stdin(self): 389 def test_no_stdin(self):
385 self._test_no_stdio(['stdin']) 390 self._test_no_stdio(['stdin'])
386 391
387 def test_no_stdout(self): 392 def test_no_stdout(self):
388 self._test_no_stdio(['stdout']) 393 self._test_no_stdio(['stdout'])
389 394
390 def test_no_stderr(self): 395 def test_no_stderr(self):
391 self._test_no_stdio(['stderr']) 396 self._test_no_stdio(['stderr'])
392 397
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 out = subprocess.check_output([sys.executable, "-I", main], 469 out = subprocess.check_output([sys.executable, "-I", main],
465 cwd=tmpdir) 470 cwd=tmpdir)
466 self.assertEqual(out.strip(), b"ok") 471 self.assertEqual(out.strip(), b"ok")
467 472
468 def test_main(): 473 def test_main():
469 test.support.run_unittest(CmdLineTest) 474 test.support.run_unittest(CmdLineTest)
470 test.support.reap_children() 475 test.support.reap_children()
471 476
472 if __name__ == "__main__": 477 if __name__ == "__main__":
473 test_main() 478 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+