Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Unified Diff: third_party/pexpect/tests/platform_checks/check.py

Issue 1398903002: Add third_party/pexpect (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@end-to-end-test
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/pexpect/tests/platform_checks/check.py
diff --git a/third_party/pexpect/tests/platform_checks/check.py b/third_party/pexpect/tests/platform_checks/check.py
new file mode 100644
index 0000000000000000000000000000000000000000..b41755a9635c805290fc3a2f1cbd0dc24810161d
--- /dev/null
+++ b/third_party/pexpect/tests/platform_checks/check.py
@@ -0,0 +1,77 @@
+#!/usr/bin/env python
+import signal
+import os
+import time
+import pty
+
+def signal_handler (signum, frame):
+ print 'Signal handler called with signal:', signum
+ print 'signal.SIGCHLD=', signal.SIGKILL
+
+# First thing we do is set up a handler for SIGCHLD.
+signal.signal (signal.SIGCHLD, signal.SIG_IGN)
+
+print 'PART 1 -- Test signal handling with empty pipe.'
+# Create a child process for us to kill.
+try:
+ pid, fd = pty.fork()
+except Exception as e:
+ print str(e)
+
+if pid == 0:
+# os.write (sys.stdout.fileno(), 'This is a test.\n This is a test.')
+ time.sleep(10000)
+
+print 'Sending SIGKILL to child pid:', pid
+os.kill (pid, signal.SIGKILL)
+
+# SIGCHLD should interrupt sleep.
+# Note that this is a race.
+# It is possible that the signal handler will get called
+# before we try to sleep, but this has not happened yet.
+# But in that case we can only tell by order of printed output.
+print 'Entering sleep...'
+try:
+ time.sleep(10)
+except:
+ print 'sleep was interrupted by signal.'
+
+# Just for fun let's see if the process is alive.
+try:
+ os.kill(pid, 0)
+ print 'Child is alive. This is ambiguous because it may be a Zombie.'
+except OSError as e:
+ print 'Child appears to be dead.'
+
+print 'PART 2 -- Test signal handling with full pipe.'
+# Create a child process for us to kill.
+try:
+ pid, fd = pty.fork()
+except Exception as e:
+ print str(e)
+
+if pid == 0:
+ os.write (sys.stdout.fileno(), 'This is a test.\n This is a test.')
+ time.sleep(10000)
+
+print 'Sending SIGKILL to child pid:', pid
+os.kill (pid, signal.SIGKILL)
+
+# SIGCHLD should interrupt sleep.
+# Note that this is a race.
+# It is possible that the signal handler will get called
+# before we try to sleep, but this has not happened yet.
+# But in that case we can only tell by order of printed output.
+print 'Entering sleep...'
+try:
+ time.sleep(10)
+except:
+ print 'sleep was interrupted by signal.'
+
+# Just for fun let's see if the process is alive.
+try:
+ os.kill(pid, 0)
+ print 'Child is alive. This is ambiguous because it may be a Zombie.'
+except OSError as e:
+ print 'Child appears to be dead.'
+
« no previous file with comments | « third_party/pexpect/tests/platform_checks/README ('k') | third_party/pexpect/tests/platform_checks/check2.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698