# spawn an instance of the shell c = pexpect.spawn(def_module.shell, drainpty=True, logfile=logfile) atexit.register(force_shell_termination, shell_process=c) # set timeout for all following 'expect*' calls to 2 seconds c.timeout = 2 # ensure that shell prints expected prompt assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt" # run a command c.sendline("sleep 30 &") # pull the jobid and pid from the background process printout (jobid, pid) = shellio.parse_regular_expression(c, def_module.bgjob_regex) # ensure that the shell prints the expected prompt assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt" #The job needs to be running when we call stop proc_check.count_children_timeout(c, 1, 1) # send the stop command to the process c.sendline(def_module.builtin_commands['stop'] % jobid) #Ensure that sleep has enough time to stop before we read its #/proc/ pid /stat file. time.sleep(.5) #Ensure that sleep is now stopped in the background, and is not
# spawn an instance of the shell c = pexpect.spawn(def_module.shell, drainpty=True, logfile=logfile) atexit.register(force_shell_termination, shell_process=c) # set timeout for all following 'expect*' calls to 2 seconds c.timeout = 2 # ensure that shell prints expected prompt assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt" # run program sleep c.sendline("sleep 30 &") # Used to get the jobid and pid of the sleep process (jobid, pid) = shellio.parse_regular_expression(c, def_module.bgjob_regex) # ensure that shell prints expected prompt assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt" # send the stop command to the process c.sendline(def_module.builtin_commands["stop"] % jobid) # Ensure that sleep has enough time to stop before we read its # /proc/ /stat file. proc_check.count_children_timeout(c, 1, 1) # Ensure that sleep is now stopped in the background, and is not # the foreground process.
def expect_regex(regex): return shellio.parse_regular_expression(console, regex)
#checks the number of active child processes #at this moment in time proc_check.count_active_children(c, 1) # send SIGTSTP to 'sleep' c.sendcontrol('z') # shell should pick up that 'sleep' was stopped and respond with job status # it should output a line such as [6]+ Stopped (sleep 60) # (note that the provided regexp assumes the job name appears in parentheses, # adjust your eshoutput.py if needed) (jobid, statusmsg, cmdline) = \ shellio.parse_regular_expression(c, def_module.job_status_regex) assert statusmsg == def_module.jobs_status_msg['stopped'], "Shell did not report stopped job" # move job into foreground c.sendline(def_module.builtin_commands['fg'] % jobid) # when moving a job in the foreground, bash outputs its command line assert c.expect_exact(cmdline) == 0, "Shell did not report the job moved into the foreground" # send SIGINT c.sendintr() #check that the prompt prints assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt"
def_module.prompt) == 0, "Shell did not print expected prompt (1)" # run a command c.sendline("sleep 60") # The following call is necessary to ensure that the SIGTSTP # we are sending below via 'sendcontrol' reaches the 'sleep' child. proc_check.wait_until_child_is_in_foreground(c) # send SIGTSTP to 'sleep' c.sendcontrol('z') # shell should pick up that 'sleep' was stopped and respond with job status # it should output a line such [6]+ Stopped sleep 60 (jobid, statusmsg, cmdline) = \ shellio.parse_regular_expression(c, def_module.job_status_regex) assert statusmsg == def_module.jobs_status_msg[ 'stopped'], "Shell did not report stopped job" # move job into foreground c.sendline(def_module.builtin_commands['fg'] % jobid) # when moving a job in the foreground, bash outputs its command line assert c.expect_exact( cmdline) == 0, "Shell did not report the job moved into the foreground" # end the program c.sendintr() # run a command c.sendline("sleep 30 &")
#Wait until the sleep command takes over the foreground proc_check.wait_until_child_is_in_foreground(c) #send the job to the background c.sendcontrol('z') # ensure that the shell prints the expected prompt assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt" #Request the jobs list c.sendline(def_module.builtin_commands['jobs']) #Check the jobs list (jobid, status_message, command_line) = shellio.parse_regular_expression(c, def_module.job_status_regex) assert status_message == def_module.jobs_status_msg['stopped'] and \ 'sleep 30' in command_line, "Job status not properly displayed" # ensure that the shell prints the expected prompt assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt" #Add another job c.sendline("sleep 300 &") # pick up the background job output (jobid, pid) = shellio.parse_regular_expression(c, def_module.bgjob_regex) assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt"
logfile = def_module.logfile #spawn an instance of the shell c = pexpect.spawn(def_module.shell + plugin_dir, drainpty=True, logfile=logfile) atexit.register(force_shell_termination, shell_process=c) # send the ls command with a single glob c.sendline("ls *.c") # Check output from os import listdir import re shellio.parse_regular_expression(c, "(\S+\.c)") # Get the output line output = shellio.parse_regular_expression(c, "(.+)\r\n") # Parse the output line for each file output = re.findall("(\S+\.c)", output[0]) for file in listdir('.'): if file[-2:] == ".c": assert file in output # Try a command with multiple globs c.sendline("ls *.c *.h") # Check output from os import listdir import re
# Give Pintos time to boot time.sleep(def_module.pintos_bootup) assert c.expect('Username:'******'kevin') assert c.expect('Password:'******'kevin') assert c.expect(def_module.prompt) == 0, "Shell did not start" c.sendline('cat etc/group') assert c.expect(def_module.prompt) == 0, "Shell did not start" c.sendline('sudo cat etc/group') name = shellio.parse_regular_expression(c, '\n\[Sudo] password for (\w+):') assert str(name[0]) == 'kevin', "sudo did not ask for password correctly" c.sendline('kevin') assert c.expect('root:x:0:root') == 0 assert c.expect('sudo:x:27:kevin mike ollie') == 0 #code = shellio.parse_regular_expression(c, 'cat: exit\((\d)\)') #assert code[0] == 0 #code2 = shellio.parse_regular_expression(c, 'sudo: exit\((\d)\)') #assert code2[0] == 0, str(code2) c.expect('"sudo cat etc/group": exit code 0') == 0 assert c.expect(def_module.prompt) == 0, "Shell did not start" c.send('exit\r')
time.sleep(1) #send the job to the background c.sendcontrol('z') # ensure that the shell prints the expected prompt assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt" #Request the jobs list c.sendline(def_module.builtin_commands['jobs']) #Check the jobs list (jobid, status_message, command_line) = shellio.parse_regular_expression(c, def_module.job_status_regex) assert status_message == def_module.jobs_status_msg['stopped'] and \ 'sleep 30' in command_line, "Job status not properly displayed" # ensure that the shell prints the expected prompt assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt" #Add another job c.sendline("sleep 300 &") # pick up the background job output (jobid, pid) = shellio.parse_regular_expression(c, def_module.bgjob_regex) assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt"
# run a command c.sendline("sleep 60") # The following call is necessary to ensure that the SIGTSTP # we are sending below via 'sendcontrol' reaches the 'sleep' child. proc_check.wait_until_child_is_in_foreground(c) # send SIGTSTP to 'sleep' c.sendcontrol('z') # shell should pick up that 'sleep' was stopped and respond with job status # it should output a line such [6]+ Stopped sleep 60 (jobid, statusmsg, cmdline) = \ shellio.parse_regular_expression(c, def_module.job_status_regex) assert statusmsg == def_module.jobs_status_msg['stopped'], "Shell did not report stopped job" # move job into foreground c.sendline(def_module.builtin_commands['fg'] % jobid) # when moving a job in the foreground, bash outputs its command line assert c.expect_exact(cmdline) == 0, "Shell did not report the job moved into the foreground" # end the program c.sendintr() # run a command c.sendline("sleep 30 &")