| 141 |
Kevin |
1 |
#!/usr/bin/python
|
|
|
2 |
#
|
|
|
3 |
# Tests that esh can run commands in the foreground
|
|
|
4 |
#
|
|
|
5 |
|
|
|
6 |
import sys, imp, atexit
|
|
|
7 |
sys.path.append("/home/courses/cs3214/software/pexpect-dpty/");
|
|
|
8 |
import pexpect, shellio, signal, time, os, re, proc_check
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
#Ensure the shell process is terminated
|
|
|
12 |
def force_shell_termination(shell_process):
|
|
|
13 |
c.close(force=True)
|
|
|
14 |
|
|
|
15 |
#pulling in the regular expression and other definitions
|
|
|
16 |
definitions_scriptname = sys.argv[1]
|
|
|
17 |
def_module = imp.load_source('', definitions_scriptname)
|
|
|
18 |
|
|
|
19 |
# start shell
|
|
|
20 |
c = pexpect.spawn(def_module.shell, drainpty=True, logfile=None)
|
|
|
21 |
atexit.register(force_shell_termination, shell_process=c)
|
|
|
22 |
|
|
|
23 |
# set timeout for all following 'expect*' calls to 4 seconds
|
|
|
24 |
c.timeout = 4
|
|
|
25 |
|
|
|
26 |
# ensure that shell prints expected prompt
|
|
|
27 |
assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt"
|
|
|
28 |
|
|
|
29 |
# run a command
|
|
|
30 |
c.sendline("/usr/bin/gcc")
|
|
|
31 |
|
|
|
32 |
assert c.expect("gcc: no input files") == 0, "Shell did not start gcc"
|
|
|
33 |
|
|
|
34 |
# make sure shell returns to prompt
|
|
|
35 |
assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt"
|
|
|
36 |
|
|
|
37 |
# send EOF
|
|
|
38 |
c.sendeof()
|
|
|
39 |
|
|
|
40 |
# send SIGINT in case the EOF doesn't quit their shell
|
|
|
41 |
c.sendintr()
|
|
|
42 |
|
|
|
43 |
shellio.success()
|