5
This license is approved by the OSI and FSF as GPL-compatible.
6
http://opensource.org/licenses/isc-license.txt
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.
22
import os, time, pexpect, sys
24
def getProcessResults(cmd, timeLimit=20):
26
executes 'cmd' as a child process and returns the child's output,
27
the duration of execution, and the process exit status. Aborts if
28
child process does not generate output for 'timeLimit' seconds.
31
startTime = time.time()
32
child = pexpect.spawn(cmd, timeout=10)
33
child.logfile = sys.stdout
37
# read_nonblocking will add to 'outout' one byte at a time
38
# newlines can show up as '\r\n' so we kill any '\r's which
39
# will mess up the formatting for the viewer
40
output += child.read_nonblocking(timeout=timeLimit).replace("\r","")
41
except pexpect.EOF as e:
43
# process terminated normally
45
except pexpect.TIMEOUT as e:
47
output += "\nProcess aborted by FlashTest after %s seconds.\n" % timeLimit
48
print(child.isalive())
53
child.close(force=True)
55
duration = endTime - startTime
56
exitStatus = child.exitstatus
58
return (output, duration, exitStatus)
62
result, duration, exitStatus = getProcessResults(cmd)
64
print("result: %s" % result)
65
print("duration: %s" % duration)
66
print("exit-status: %s" % exitStatus)