Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
141 Kevin 1
#!/usr/bin/python
2
#
3
# Ctrl-C Test: Start a shell, send SIGINT, run a program, 
4
#              send SIGINT, then exit
5
#
6
# Requires the following commands to be implemented
7
# or otherwise usable:
8
#
9
#	sleep, ctrl-c control
10
#
11
 
12
import sys, imp, atexit
13
sys.path.append("/home/courses/cs3214/software/pexpect-dpty/");
14
import pexpect, proc_check, shellio, signal, time, threading
15
 
16
#Ensure the shell process is terminated
17
def force_shell_termination(shell_process):
18
	c.close(force=True)
19
 
20
#pulling in the regular expression and other definitions
21
definitions_scriptname = sys.argv[1]
22
def_module = imp.load_source('', definitions_scriptname)
23
logfile = None
24
if hasattr(def_module, 'logfile'):
25
    logfile = def_module.logfile
26
 
27
# spawn an instance of the shell
28
c = pexpect.spawn(def_module.shell, drainpty=True, logfile=logfile)
29
atexit.register(force_shell_termination, shell_process=c)
30
 
31
# set timeout for all following 'expect*' calls to 2 seconds
32
c.timeout = 2
33
 
34
# ensure that shell prints expected prompt
35
assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt"
36
 
37
# run a command
38
c.sendline("sleep 60")
39
 
40
# The following call is necessary to ensure that the SIGINT
41
# we are sending below reaches the 'sleep' child.
42
proc_check.wait_until_child_is_in_foreground(c)
43
 
44
#checks that our process is running
45
proc_check.count_active_children(c, 1)
46
 
47
# send SIGINT
48
c.sendintr()
49
 
50
#prompt check
51
assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt"
52
 
53
#checks that the process was ended
54
proc_check.count_active_children(c, 0)
55
 
56
 
57
 
58
c.sendline("exit")
59
 
60
assert c.expect_exact("exit\r\n") == 0, "Shell output extraneous characters"
61
 
62
 
63
shellio.success()