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

Side by Side Diff: third_party/pexpect/tests/pexpectTest.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 unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 '''
3 PEXPECT LICENSE
4
5 This license is approved by the OSI and FSF as GPL-compatible.
6 http://opensource.org/licenses/isc-license.txt
7
8 Copyright (c) 2012, Noah Spurrier <noah@noah.org>
9 PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY
10 PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE
11 COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES.
12 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20 '''
21
22 import time
23 import pexpect
24 import sys
25
26 def getProcessResults(cmd, timeLimit=20):
27 '''
28 executes 'cmd' as a child process and returns the child's output,
29 the duration of execution, and the process exit status. Aborts if
30 child process does not generate output for 'timeLimit' seconds.
31 '''
32 output = ""
33 startTime = time.time()
34 child = pexpect.spawn(cmd, timeout=10)
35 child.logfile = sys.stdout
36
37 while 1:
38 try:
39 # read_nonblocking will add to 'outout' one byte at a time
40 # newlines can show up as '\r\n' so we kill any '\r's which
41 # will mess up the formatting for the viewer
42 output += child.read_nonblocking(timeout=timeLimit).replace("\r","")
43 except pexpect.EOF as e:
44 print(str(e))
45 # process terminated normally
46 break
47 except pexpect.TIMEOUT as e:
48 print(str(e))
49 output += "\nProcess aborted by FlashTest after %s seconds.\n" % timeLimit
50 print(child.isalive())
51 child.kill(9)
52 break
53
54 endTime = time.time()
55 child.close(force=True)
56
57 duration = endTime - startTime
58 exitStatus = child.exitstatus
59
60 return (output, duration, exitStatus)
61
62 cmd = "./ticker.py"
63
64 result, duration, exitStatus = getProcessResults(cmd)
65
66 print("result: %s" % result)
67 print("duration: %s" % duration)
68 print("exit-status: %s" % exitStatus)
69
OLDNEW
« no previous file with comments | « third_party/pexpect/tests/needs_kill.py ('k') | third_party/pexpect/tests/platform_checks/CSIGNALTEST/test.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698