X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=test%2Fpy%2Fu_boot_console_base.py;h=4606ad48bf5d49d7c90c2ade5418347f08b577bf;hb=ebe621d5fb2f5c15aff50e0610372f2751fd152f;hp=7e1e9d430ffa780e45cf87c35ebd8b4872914da1;hpb=c82ce04a3f38bb91465da6b2fd9d8dcb0e81f94b;p=platform%2Fkernel%2Fu-boot.git diff --git a/test/py/u_boot_console_base.py b/test/py/u_boot_console_base.py index 7e1e9d4..4606ad4 100644 --- a/test/py/u_boot_console_base.py +++ b/test/py/u_boot_console_base.py @@ -56,6 +56,22 @@ class ConsoleDisableCheck(object): self.console.disable_check_count[self.check_type] -= 1 self.console.eval_bad_patterns() +class ConsoleSetupTimeout(object): + """Context manager (for Python's with statement) that temporarily sets up + timeout for specific command. This is useful when execution time is greater + then default 30s.""" + + def __init__(self, console, timeout): + self.p = console.p + self.orig_timeout = self.p.timeout + self.p.timeout = timeout + + def __enter__(self): + return self + + def __exit__(self, extype, value, traceback): + self.p.timeout = self.orig_timeout + class ConsoleBase(object): """The interface through which test functions interact with the U-Boot console. This primarily involves executing shell commands, capturing their @@ -200,6 +216,22 @@ class ConsoleBase(object): self.cleanup_spawn() raise + def run_command_list(self, cmds): + """Run a list of commands. + + This is a helper function to call run_command() with default arguments + for each command in a list. + + Args: + cmd: List of commands (each a string) + Returns: + Combined output of all commands, as a string + """ + output = '' + for cmd in cmds: + output += self.run_command(cmd) + return output + def ctrlc(self): """Send a CTRL-C character to U-Boot. @@ -293,8 +325,8 @@ class ConsoleBase(object): if self.p: return try: + self.log.start_section('Starting U-Boot') self.at_prompt = False - self.log.action('Starting U-Boot') self.p = self.get_spawn() # Real targets can take a long time to scroll large amounts of # text if LCD is enabled. This value may need tweaking in the @@ -303,10 +335,17 @@ class ConsoleBase(object): if not self.config.gdbserver: self.p.timeout = 30000 self.p.logfile_read = self.logstream - if self.config.buildconfig.get('CONFIG_SPL', False) == 'y': - m = self.p.expect([pattern_u_boot_spl_signon] + self.bad_patterns) + bcfg = self.config.buildconfig + config_spl = bcfg.get('config_spl', 'n') == 'y' + config_spl_serial_support = bcfg.get('config_spl_serial_support', + 'n') == 'y' + env_spl_skipped = self.config.env.get('env__spl_skipped', + False) + if config_spl and config_spl_serial_support and not env_spl_skipped: + m = self.p.expect([pattern_u_boot_spl_signon] + + self.bad_patterns) if m != 0: - raise Exception('Bad pattern found on console: ' + + raise Exception('Bad pattern found on SPL console: ' + self.bad_pattern_ids[m - 1]) m = self.p.expect([pattern_u_boot_main_signon] + self.bad_patterns) if m != 0: @@ -319,7 +358,7 @@ class ConsoleBase(object): if m == 0: break if m == 1: - self.p.send(chr(3)) # CTRL-C + self.p.send(' ') continue raise Exception('Bad pattern found on console: ' + self.bad_pattern_ids[m - 2]) @@ -329,6 +368,8 @@ class ConsoleBase(object): self.log.error(str(ex)) self.cleanup_spawn() raise + finally: + self.log.end_section('Starting U-Boot') def cleanup_spawn(self): """Shut down all interaction with the U-Boot instance. @@ -352,6 +393,16 @@ class ConsoleBase(object): pass self.p = None + def get_spawn_output(self): + """Return the start-up output from U-Boot + + Returns: + The output produced by ensure_spawed(), as a string. + """ + if self.p: + return self.p.get_expect_output() + return None + def validate_version_string_in_text(self, text): """Assert that a command's output includes the U-Boot signon message. @@ -382,3 +433,18 @@ class ConsoleBase(object): """ return ConsoleDisableCheck(self, check_type) + + def temporary_timeout(self, timeout): + """Temporarily set up different timeout for commands. + + Create a new context manager (for use with the "with" statement) which + temporarily change timeout. + + Args: + timeout: Time in milliseconds. + + Returns: + A context manager object. + """ + + return ConsoleSetupTimeout(self, timeout)