Message ID | 20200120235159.18510-4-f4bug@amsat.org |
---|---|
State | New |
Headers | show |
Series | hw/arm/raspi: Run U-Boot on the raspi machines | expand |
On 20/01/2020 23:51, Philippe Mathieu-Daudé wrote: > We need a function to interrupt interactive consoles. > > Example: Interrupt U-Boot to set different environment values. > > Tested-by: Niek Linnenbank <nieklinnenbank@gmail.com> > Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Liam Merwick <liam.merwick@oracle.com> Tested-by: Liam Merwick <liam.merwick@oracle.com> > --- > tests/acceptance/avocado_qemu/__init__.py | 32 +++++++++++++++++++++-- > 1 file changed, 30 insertions(+), 2 deletions(-) >
On 1/20/20 9:51 PM, Philippe Mathieu-Daudé wrote: > We need a function to interrupt interactive consoles. > > Example: Interrupt U-Boot to set different environment values. > > Tested-by: Niek Linnenbank <nieklinnenbank@gmail.com> > Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > --- > tests/acceptance/avocado_qemu/__init__.py | 32 +++++++++++++++++++++-- > 1 file changed, 30 insertions(+), 2 deletions(-) Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com> > > diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py > index 0a50fcf2be..d4358eb431 100644 > --- a/tests/acceptance/avocado_qemu/__init__.py > +++ b/tests/acceptance/avocado_qemu/__init__.py > @@ -56,13 +56,15 @@ def pick_default_qemu_bin(arch=None): > > > def _console_interaction(test, success_message, failure_message, > - send_string): > + send_string, keep_sending=False): > + assert not keep_sending or send_string > console = test.vm.console_socket.makefile() > console_logger = logging.getLogger('console') > while True: > if send_string: > test.vm.console_socket.sendall(send_string.encode()) > - send_string = None # send only once > + if not keep_sending: > + send_string = None # send only once > msg = console.readline().strip() > if not msg: > continue > @@ -74,6 +76,32 @@ def _console_interaction(test, success_message, failure_message, > fail = 'Failure message found in console: %s' % failure_message > test.fail(fail) > > +def interrupt_interactive_console_until_pattern(test, success_message, > + failure_message=None, > + interrupt_string='\r'): > + """ > + Keep sending a string to interrupt a console prompt, while logging the > + console output. Typical use case is to break a boot loader prompt, such: > + > + Press a key within 5 seconds to interrupt boot process. > + 5 > + 4 > + 3 > + 2 > + 1 > + Booting default image... > + > + :param test: an Avocado test containing a VM that will have its console > + read and probed for a success or failure message > + :type test: :class:`avocado_qemu.Test` > + :param success_message: if this message appears, test succeeds > + :param failure_message: if this message appears, test fails > + :param interrupt_string: a string to send to the console before trying > + to read a new line > + """ > + _console_interaction(test, success_message, failure_message, > + interrupt_string, True) > + > def wait_for_console_pattern(test, success_message, failure_message=None): > """ > Waits for messages to appear on the console, while logging the content
On 1/21/20 12:51 AM, Philippe Mathieu-Daudé wrote: > We need a function to interrupt interactive consoles. > > Example: Interrupt U-Boot to set different environment values. > > Tested-by: Niek Linnenbank <nieklinnenbank@gmail.com> > Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > --- > tests/acceptance/avocado_qemu/__init__.py | 32 +++++++++++++++++++++-- > 1 file changed, 30 insertions(+), 2 deletions(-) > > diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py > index 0a50fcf2be..d4358eb431 100644 > --- a/tests/acceptance/avocado_qemu/__init__.py > +++ b/tests/acceptance/avocado_qemu/__init__.py > @@ -56,13 +56,15 @@ def pick_default_qemu_bin(arch=None): > > > def _console_interaction(test, success_message, failure_message, > - send_string): > + send_string, keep_sending=False): > + assert not keep_sending or send_string > console = test.vm.console_socket.makefile() > console_logger = logging.getLogger('console') > while True: > if send_string: > test.vm.console_socket.sendall(send_string.encode()) > - send_string = None # send only once > + if not keep_sending: > + send_string = None # send only once > msg = console.readline().strip() > if not msg: > continue > @@ -74,6 +76,32 @@ def _console_interaction(test, success_message, failure_message, > fail = 'Failure message found in console: %s' % failure_message > test.fail(fail) > > +def interrupt_interactive_console_until_pattern(test, success_message, > + failure_message=None, > + interrupt_string='\r'): > + """ > + Keep sending a string to interrupt a console prompt, while logging the > + console output. Typical use case is to break a boot loader prompt, such: > + > + Press a key within 5 seconds to interrupt boot process. > + 5 > + 4 > + 3 > + 2 > + 1 > + Booting default image... > + > + :param test: an Avocado test containing a VM that will have its console > + read and probed for a success or failure message > + :type test: :class:`avocado_qemu.Test` > + :param success_message: if this message appears, test succeeds > + :param failure_message: if this message appears, test fails > + :param interrupt_string: a string to send to the console before trying > + to read a new line > + """ > + _console_interaction(test, success_message, failure_message, > + interrupt_string, True) > + > def wait_for_console_pattern(test, success_message, failure_message=None): > """ > Waits for messages to appear on the console, while logging the content > Thanks, applied to my python-next tree: https://gitlab.com/philmd/qemu/commits/python-next
diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py index 0a50fcf2be..d4358eb431 100644 --- a/tests/acceptance/avocado_qemu/__init__.py +++ b/tests/acceptance/avocado_qemu/__init__.py @@ -56,13 +56,15 @@ def pick_default_qemu_bin(arch=None): def _console_interaction(test, success_message, failure_message, - send_string): + send_string, keep_sending=False): + assert not keep_sending or send_string console = test.vm.console_socket.makefile() console_logger = logging.getLogger('console') while True: if send_string: test.vm.console_socket.sendall(send_string.encode()) - send_string = None # send only once + if not keep_sending: + send_string = None # send only once msg = console.readline().strip() if not msg: continue @@ -74,6 +76,32 @@ def _console_interaction(test, success_message, failure_message, fail = 'Failure message found in console: %s' % failure_message test.fail(fail) +def interrupt_interactive_console_until_pattern(test, success_message, + failure_message=None, + interrupt_string='\r'): + """ + Keep sending a string to interrupt a console prompt, while logging the + console output. Typical use case is to break a boot loader prompt, such: + + Press a key within 5 seconds to interrupt boot process. + 5 + 4 + 3 + 2 + 1 + Booting default image... + + :param test: an Avocado test containing a VM that will have its console + read and probed for a success or failure message + :type test: :class:`avocado_qemu.Test` + :param success_message: if this message appears, test succeeds + :param failure_message: if this message appears, test fails + :param interrupt_string: a string to send to the console before trying + to read a new line + """ + _console_interaction(test, success_message, failure_message, + interrupt_string, True) + def wait_for_console_pattern(test, success_message, failure_message=None): """ Waits for messages to appear on the console, while logging the content