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 program requiring exclusive access c.sendline("vi exclusive_vi") # 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) #checks the number of active child processes #using a timeout based process count proc_check.count_children_timeout(c, 1, 1) #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,
def wait_for_fg_child(): proc_check.wait_until_child_is_in_foreground(console)
# 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 60") # The following call is necessary to ensure that the SIGINT # we are sending below reaches the 'sleep' child. proc_check.wait_until_child_is_in_foreground(c) #checks that our process is running proc_check.count_active_children(c, 1) # send SIGINT c.sendintr() #prompt check assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt" #checks that the process was ended proc_check.count_active_children(c, 0) c.sendline("exit")
def wait_for_fg_child(): proc_check.wait_until_child_is_in_foreground(console)