blob: 3e01be110295daa8a80cfc5f5fbaa81b559cf92b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0
Stephen Warren10e50632016-01-15 11:15:24 -07002# Copyright (c) 2015 Stephen Warren
3# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
Stephen Warren10e50632016-01-15 11:15:24 -07004
5# Common logic to interact with U-Boot via the console. This class provides
6# the interface that tests use to execute U-Boot shell commands and wait for
7# their results. Sub-classes exist to perform board-type-specific setup
8# operations, such as spawning a sub-process for Sandbox, or attaching to the
9# serial console of real hardware.
10
11import multiplexed_log
12import os
13import pytest
14import re
15import sys
Stephen Warren97a54662016-01-22 12:30:09 -070016import u_boot_spawn
Stephen Warren10e50632016-01-15 11:15:24 -070017
18# Regexes for text we expect U-Boot to send to the console.
Heiko Schocherce251232018-12-05 11:29:54 +010019pattern_u_boot_spl_signon = re.compile('(U-Boot SPL \\d{4}\\.\\d{2}[^\r\n]*\\))')
Stephen Warren5af83c42016-02-05 18:04:43 -070020pattern_u_boot_main_signon = re.compile('(U-Boot \\d{4}\\.\\d{2}[^\r\n]*\\))')
Stephen Warren10e50632016-01-15 11:15:24 -070021pattern_stop_autoboot_prompt = re.compile('Hit any key to stop autoboot: ')
22pattern_unknown_command = re.compile('Unknown command \'.*\' - try \'help\'')
23pattern_error_notification = re.compile('## Error: ')
Stephen Warren3bd79d32016-01-27 23:57:50 -070024pattern_error_please_reset = re.compile('### ERROR ### Please RESET the board ###')
Stephen Warren10e50632016-01-15 11:15:24 -070025
Stephen Warren1115a972016-01-27 23:57:48 -070026PAT_ID = 0
27PAT_RE = 1
28
29bad_pattern_defs = (
30 ('spl_signon', pattern_u_boot_spl_signon),
31 ('main_signon', pattern_u_boot_main_signon),
32 ('stop_autoboot_prompt', pattern_stop_autoboot_prompt),
33 ('unknown_command', pattern_unknown_command),
34 ('error_notification', pattern_error_notification),
Stephen Warren3bd79d32016-01-27 23:57:50 -070035 ('error_please_reset', pattern_error_please_reset),
Stephen Warren1115a972016-01-27 23:57:48 -070036)
37
Stephen Warren10e50632016-01-15 11:15:24 -070038class ConsoleDisableCheck(object):
Stephen Warren75e731e2016-01-26 13:41:30 -070039 """Context manager (for Python's with statement) that temporarily disables
Stephen Warren10e50632016-01-15 11:15:24 -070040 the specified console output error check. This is useful when deliberately
41 executing a command that is known to trigger one of the error checks, in
42 order to test that the error condition is actually raised. This class is
43 used internally by ConsoleBase::disable_check(); it is not intended for
Stephen Warren75e731e2016-01-26 13:41:30 -070044 direct usage."""
Stephen Warren10e50632016-01-15 11:15:24 -070045
46 def __init__(self, console, check_type):
47 self.console = console
48 self.check_type = check_type
49
50 def __enter__(self):
51 self.console.disable_check_count[self.check_type] += 1
Stephen Warren1115a972016-01-27 23:57:48 -070052 self.console.eval_bad_patterns()
Stephen Warren10e50632016-01-15 11:15:24 -070053
54 def __exit__(self, extype, value, traceback):
55 self.console.disable_check_count[self.check_type] -= 1
Stephen Warren1115a972016-01-27 23:57:48 -070056 self.console.eval_bad_patterns()
Stephen Warren10e50632016-01-15 11:15:24 -070057
Michal Simek6b463182016-05-19 07:57:41 +020058class ConsoleSetupTimeout(object):
59 """Context manager (for Python's with statement) that temporarily sets up
60 timeout for specific command. This is useful when execution time is greater
61 then default 30s."""
62
63 def __init__(self, console, timeout):
64 self.p = console.p
65 self.orig_timeout = self.p.timeout
66 self.p.timeout = timeout
67
68 def __enter__(self):
69 return self
70
71 def __exit__(self, extype, value, traceback):
72 self.p.timeout = self.orig_timeout
73
Stephen Warren10e50632016-01-15 11:15:24 -070074class ConsoleBase(object):
Stephen Warren75e731e2016-01-26 13:41:30 -070075 """The interface through which test functions interact with the U-Boot
Stephen Warren10e50632016-01-15 11:15:24 -070076 console. This primarily involves executing shell commands, capturing their
77 results, and checking for common error conditions. Some common utilities
Stephen Warren75e731e2016-01-26 13:41:30 -070078 are also provided too."""
Stephen Warren10e50632016-01-15 11:15:24 -070079
80 def __init__(self, log, config, max_fifo_fill):
Stephen Warren75e731e2016-01-26 13:41:30 -070081 """Initialize a U-Boot console connection.
Stephen Warren10e50632016-01-15 11:15:24 -070082
83 Can only usefully be called by sub-classes.
84
85 Args:
86 log: A mulptiplex_log.Logfile object, to which the U-Boot output
87 will be logged.
88 config: A configuration data structure, as built by conftest.py.
89 max_fifo_fill: The maximum number of characters to send to U-Boot
90 command-line before waiting for U-Boot to echo the characters
91 back. For UART-based HW without HW flow control, this value
92 should be set less than the UART RX FIFO size to avoid
93 overflow, assuming that U-Boot can't keep up with full-rate
94 traffic at the baud rate.
95
96 Returns:
97 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -070098 """
Stephen Warren10e50632016-01-15 11:15:24 -070099
100 self.log = log
101 self.config = config
102 self.max_fifo_fill = max_fifo_fill
103
104 self.logstream = self.log.get_stream('console', sys.stdout)
105
106 # Array slice removes leading/trailing quotes
107 self.prompt = self.config.buildconfig['config_sys_prompt'][1:-1]
Stephen Warren6d083402016-08-16 19:58:59 -0600108 self.prompt_compiled = re.compile('^' + re.escape(self.prompt), re.MULTILINE)
Stephen Warren10e50632016-01-15 11:15:24 -0700109 self.p = None
Stephen Warren1115a972016-01-27 23:57:48 -0700110 self.disable_check_count = {pat[PAT_ID]: 0 for pat in bad_pattern_defs}
111 self.eval_bad_patterns()
Stephen Warren10e50632016-01-15 11:15:24 -0700112
113 self.at_prompt = False
114 self.at_prompt_logevt = None
Stephen Warren10e50632016-01-15 11:15:24 -0700115
Simon Glassf7990762022-02-11 13:23:23 -0700116 def get_spawn(self):
117 # This is not called, ssubclass must define this.
118 # Return a value to avoid:
119 # u_boot_console_base.py:348:12: E1128: Assigning result of a function
120 # call, where the function returns None (assignment-from-none)
121 return u_boot_spawn.Spawn([])
122
123
Stephen Warren1115a972016-01-27 23:57:48 -0700124 def eval_bad_patterns(self):
125 self.bad_patterns = [pat[PAT_RE] for pat in bad_pattern_defs \
126 if self.disable_check_count[pat[PAT_ID]] == 0]
127 self.bad_pattern_ids = [pat[PAT_ID] for pat in bad_pattern_defs \
128 if self.disable_check_count[pat[PAT_ID]] == 0]
129
Stephen Warren10e50632016-01-15 11:15:24 -0700130 def close(self):
Stephen Warren75e731e2016-01-26 13:41:30 -0700131 """Terminate the connection to the U-Boot console.
Stephen Warren10e50632016-01-15 11:15:24 -0700132
133 This function is only useful once all interaction with U-Boot is
134 complete. Once this function is called, data cannot be sent to or
135 received from U-Boot.
136
137 Args:
138 None.
139
140 Returns:
141 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -0700142 """
Stephen Warren10e50632016-01-15 11:15:24 -0700143
144 if self.p:
145 self.p.close()
146 self.logstream.close()
147
Masami Hiramatsu4d3b9962022-02-16 15:16:02 +0900148 def wait_for_boot_prompt(self, loop_num = 1):
Masami Hiramatsu0ff22782022-02-16 15:15:52 +0900149 """Wait for the boot up until command prompt. This is for internal use only.
150 """
151 try:
152 bcfg = self.config.buildconfig
Masami Hiramatsu0ff22782022-02-16 15:15:52 +0900153 config_spl_serial = bcfg.get('config_spl_serial', 'n') == 'y'
154 env_spl_skipped = self.config.env.get('env__spl_skipped', False)
Tom Rini6d4527d2024-04-24 16:45:37 -0600155 env_spl_banner_times = self.config.env.get('env__spl_banner_times', 1)
Masami Hiramatsu0ff22782022-02-16 15:15:52 +0900156
Masami Hiramatsu4d3b9962022-02-16 15:16:02 +0900157 while loop_num > 0:
158 loop_num -= 1
Tom Rini6d4527d2024-04-24 16:45:37 -0600159 while config_spl_serial and not env_spl_skipped and env_spl_banner_times > 0:
Masami Hiramatsu4d3b9962022-02-16 15:16:02 +0900160 m = self.p.expect([pattern_u_boot_spl_signon] +
161 self.bad_patterns)
162 if m != 0:
163 raise Exception('Bad pattern found on SPL console: ' +
164 self.bad_pattern_ids[m - 1])
Tom Rini6d4527d2024-04-24 16:45:37 -0600165 env_spl_banner_times -= 1
166
Masami Hiramatsu4d3b9962022-02-16 15:16:02 +0900167 m = self.p.expect([pattern_u_boot_main_signon] + self.bad_patterns)
Masami Hiramatsu0ff22782022-02-16 15:15:52 +0900168 if m != 0:
Masami Hiramatsu4d3b9962022-02-16 15:16:02 +0900169 raise Exception('Bad pattern found on console: ' +
Masami Hiramatsu0ff22782022-02-16 15:15:52 +0900170 self.bad_pattern_ids[m - 1])
Masami Hiramatsu0ff22782022-02-16 15:15:52 +0900171 self.u_boot_version_string = self.p.after
172 while True:
173 m = self.p.expect([self.prompt_compiled,
174 pattern_stop_autoboot_prompt] + self.bad_patterns)
175 if m == 0:
176 break
177 if m == 1:
178 self.p.send(' ')
179 continue
180 raise Exception('Bad pattern found on console: ' +
181 self.bad_pattern_ids[m - 2])
182
183 except Exception as ex:
184 self.log.error(str(ex))
185 self.cleanup_spawn()
186 raise
187 finally:
188 self.log.timestamp()
189
Stephen Warren10e50632016-01-15 11:15:24 -0700190 def run_command(self, cmd, wait_for_echo=True, send_nl=True,
Masami Hiramatsu0ff22782022-02-16 15:15:52 +0900191 wait_for_prompt=True, wait_for_reboot=False):
Stephen Warren75e731e2016-01-26 13:41:30 -0700192 """Execute a command via the U-Boot console.
Stephen Warren10e50632016-01-15 11:15:24 -0700193
194 The command is always sent to U-Boot.
195
196 U-Boot echoes any command back to its output, and this function
197 typically waits for that to occur. The wait can be disabled by setting
198 wait_for_echo=False, which is useful e.g. when sending CTRL-C to
199 interrupt a long-running command such as "ums".
200
201 Command execution is typically triggered by sending a newline
202 character. This can be disabled by setting send_nl=False, which is
203 also useful when sending CTRL-C.
204
205 This function typically waits for the command to finish executing, and
206 returns the console output that it generated. This can be disabled by
207 setting wait_for_prompt=False, which is useful when invoking a long-
208 running command such as "ums".
209
210 Args:
211 cmd: The command to send.
Heinrich Schuchardtbec160a2017-09-14 12:27:07 +0200212 wait_for_echo: Boolean indicating whether to wait for U-Boot to
Stephen Warren10e50632016-01-15 11:15:24 -0700213 echo the command text back to its output.
214 send_nl: Boolean indicating whether to send a newline character
215 after the command string.
216 wait_for_prompt: Boolean indicating whether to wait for the
217 command prompt to be sent by U-Boot. This typically occurs
218 immediately after the command has been executed.
Masami Hiramatsu0ff22782022-02-16 15:15:52 +0900219 wait_for_reboot: Boolean indication whether to wait for the
220 reboot U-Boot. If this sets True, wait_for_prompt must also
221 be True.
Stephen Warren10e50632016-01-15 11:15:24 -0700222
223 Returns:
224 If wait_for_prompt == False:
225 Nothing.
226 Else:
227 The output from U-Boot during command execution. In other
228 words, the text U-Boot emitted between the point it echod the
229 command string and emitted the subsequent command prompts.
Stephen Warren75e731e2016-01-26 13:41:30 -0700230 """
Stephen Warren10e50632016-01-15 11:15:24 -0700231
Stephen Warren10e50632016-01-15 11:15:24 -0700232 if self.at_prompt and \
233 self.at_prompt_logevt != self.logstream.logfile.cur_evt:
234 self.logstream.write(self.prompt, implicit=True)
235
Stephen Warren10e50632016-01-15 11:15:24 -0700236 try:
237 self.at_prompt = False
238 if send_nl:
239 cmd += '\n'
240 while cmd:
241 # Limit max outstanding data, so UART FIFOs don't overflow
242 chunk = cmd[:self.max_fifo_fill]
243 cmd = cmd[self.max_fifo_fill:]
244 self.p.send(chunk)
245 if not wait_for_echo:
246 continue
247 chunk = re.escape(chunk)
248 chunk = chunk.replace('\\\n', '[\r\n]')
Stephen Warren1115a972016-01-27 23:57:48 -0700249 m = self.p.expect([chunk] + self.bad_patterns)
Stephen Warren10e50632016-01-15 11:15:24 -0700250 if m != 0:
251 self.at_prompt = False
252 raise Exception('Bad pattern found on console: ' +
Stephen Warren1115a972016-01-27 23:57:48 -0700253 self.bad_pattern_ids[m - 1])
Stephen Warren10e50632016-01-15 11:15:24 -0700254 if not wait_for_prompt:
255 return
Masami Hiramatsu0ff22782022-02-16 15:15:52 +0900256 if wait_for_reboot:
257 self.wait_for_boot_prompt()
258 else:
259 m = self.p.expect([self.prompt_compiled] + self.bad_patterns)
260 if m != 0:
261 self.at_prompt = False
262 raise Exception('Bad pattern found on console: ' +
263 self.bad_pattern_ids[m - 1])
Stephen Warren10e50632016-01-15 11:15:24 -0700264 self.at_prompt = True
265 self.at_prompt_logevt = self.logstream.logfile.cur_evt
266 # Only strip \r\n; space/TAB might be significant if testing
267 # indentation.
268 return self.p.before.strip('\r\n')
269 except Exception as ex:
270 self.log.error(str(ex))
271 self.cleanup_spawn()
272 raise
Stephen Warrenb1c556a2017-10-27 11:04:08 -0600273 finally:
274 self.log.timestamp()
Stephen Warren10e50632016-01-15 11:15:24 -0700275
Simon Glass2436bb02016-07-03 09:40:42 -0600276 def run_command_list(self, cmds):
277 """Run a list of commands.
278
279 This is a helper function to call run_command() with default arguments
280 for each command in a list.
281
282 Args:
Simon Glassd5deca02016-07-31 17:35:04 -0600283 cmd: List of commands (each a string).
Simon Glass2436bb02016-07-03 09:40:42 -0600284 Returns:
Simon Glass2ca73112016-07-31 17:35:09 -0600285 A list of output strings from each command, one element for each
286 command.
Simon Glass2436bb02016-07-03 09:40:42 -0600287 """
Simon Glass2ca73112016-07-31 17:35:09 -0600288 output = []
Simon Glass2436bb02016-07-03 09:40:42 -0600289 for cmd in cmds:
Simon Glass2ca73112016-07-31 17:35:09 -0600290 output.append(self.run_command(cmd))
Simon Glass2436bb02016-07-03 09:40:42 -0600291 return output
292
Stephen Warren10e50632016-01-15 11:15:24 -0700293 def ctrlc(self):
Stephen Warren75e731e2016-01-26 13:41:30 -0700294 """Send a CTRL-C character to U-Boot.
Stephen Warren10e50632016-01-15 11:15:24 -0700295
296 This is useful in order to stop execution of long-running synchronous
297 commands such as "ums".
298
299 Args:
300 None.
301
302 Returns:
303 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -0700304 """
Stephen Warren10e50632016-01-15 11:15:24 -0700305
Stephen Warrena88c4172016-01-22 12:30:10 -0700306 self.log.action('Sending Ctrl-C')
Stephen Warren10e50632016-01-15 11:15:24 -0700307 self.run_command(chr(3), wait_for_echo=False, send_nl=False)
308
Stephen Warrenef824f52016-01-22 12:30:12 -0700309 def wait_for(self, text):
Stephen Warren75e731e2016-01-26 13:41:30 -0700310 """Wait for a pattern to be emitted by U-Boot.
Stephen Warrenef824f52016-01-22 12:30:12 -0700311
312 This is useful when a long-running command such as "dfu" is executing,
313 and it periodically emits some text that should show up at a specific
314 location in the log file.
315
316 Args:
317 text: The text to wait for; either a string (containing raw text,
318 not a regular expression) or an re object.
319
320 Returns:
321 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -0700322 """
Stephen Warrenef824f52016-01-22 12:30:12 -0700323
324 if type(text) == type(''):
325 text = re.escape(text)
Stephen Warren68a9bb62016-01-27 23:57:49 -0700326 m = self.p.expect([text] + self.bad_patterns)
327 if m != 0:
328 raise Exception('Bad pattern found on console: ' +
329 self.bad_pattern_ids[m - 1])
Stephen Warrenef824f52016-01-22 12:30:12 -0700330
Stephen Warren97a54662016-01-22 12:30:09 -0700331 def drain_console(self):
Stephen Warren75e731e2016-01-26 13:41:30 -0700332 """Read from and log the U-Boot console for a short time.
Stephen Warren97a54662016-01-22 12:30:09 -0700333
334 U-Boot's console output is only logged when the test code actively
335 waits for U-Boot to emit specific data. There are cases where tests
336 can fail without doing this. For example, if a test asks U-Boot to
337 enable USB device mode, then polls until a host-side device node
338 exists. In such a case, it is useful to log U-Boot's console output
339 in case U-Boot printed clues as to why the host-side even did not
340 occur. This function will do that.
341
342 Args:
343 None.
344
345 Returns:
346 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -0700347 """
Stephen Warren97a54662016-01-22 12:30:09 -0700348
349 # If we are already not connected to U-Boot, there's nothing to drain.
350 # This should only happen when a previous call to run_command() or
351 # wait_for() failed (and hence the output has already been logged), or
352 # the system is shutting down.
353 if not self.p:
354 return
355
356 orig_timeout = self.p.timeout
357 try:
358 # Drain the log for a relatively short time.
359 self.p.timeout = 1000
360 # Wait for something U-Boot will likely never send. This will
361 # cause the console output to be read and logged.
362 self.p.expect(['This should never match U-Boot output'])
Stephen Warren677b9cc2018-09-20 16:55:03 -0600363 except:
364 # We expect a timeout, since U-Boot won't print what we waited
365 # for. Squash it when it happens.
366 #
367 # Squash any other exception too. This function is only used to
368 # drain (and log) the U-Boot console output after a failed test.
369 # The U-Boot process will be restarted, or target board reset, once
370 # this function returns. So, we don't care about detecting any
371 # additional errors, so they're squashed so that the rest of the
372 # post-test-failure cleanup code can continue operation, and
373 # correctly terminate any log sections, etc.
Stephen Warren97a54662016-01-22 12:30:09 -0700374 pass
375 finally:
376 self.p.timeout = orig_timeout
377
Masami Hiramatsu4d3b9962022-02-16 15:16:02 +0900378 def ensure_spawned(self, expect_reset=False):
Stephen Warren75e731e2016-01-26 13:41:30 -0700379 """Ensure a connection to a correctly running U-Boot instance.
Stephen Warren10e50632016-01-15 11:15:24 -0700380
381 This may require spawning a new Sandbox process or resetting target
382 hardware, as defined by the implementation sub-class.
383
384 This is an internal function and should not be called directly.
385
386 Args:
Masami Hiramatsu4d3b9962022-02-16 15:16:02 +0900387 expect_reset: Boolean indication whether this boot is expected
388 to be reset while the 1st boot process after main boot before
389 prompt. False by default.
Stephen Warren10e50632016-01-15 11:15:24 -0700390
391 Returns:
392 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -0700393 """
Stephen Warren10e50632016-01-15 11:15:24 -0700394
395 if self.p:
Bin Meng739b3862022-05-17 23:24:43 +0800396 # Reset the console timeout value as some tests may change
397 # its default value during the execution
398 if not self.config.gdbserver:
399 self.p.timeout = 30000
Stephen Warren10e50632016-01-15 11:15:24 -0700400 return
401 try:
Stephen Warren80eea632016-02-11 11:46:12 -0700402 self.log.start_section('Starting U-Boot')
Stephen Warren10e50632016-01-15 11:15:24 -0700403 self.at_prompt = False
Stephen Warren10e50632016-01-15 11:15:24 -0700404 self.p = self.get_spawn()
405 # Real targets can take a long time to scroll large amounts of
406 # text if LCD is enabled. This value may need tweaking in the
407 # future, possibly per-test to be optimal. This works for 'help'
408 # on board 'seaboard'.
Stephen Warren33db1ee2016-02-04 16:11:50 -0700409 if not self.config.gdbserver:
410 self.p.timeout = 30000
Stephen Warren10e50632016-01-15 11:15:24 -0700411 self.p.logfile_read = self.logstream
Masami Hiramatsu4d3b9962022-02-16 15:16:02 +0900412 if expect_reset:
413 loop_num = 2
414 else:
415 loop_num = 1
416 self.wait_for_boot_prompt(loop_num = loop_num)
Stephen Warren10e50632016-01-15 11:15:24 -0700417 self.at_prompt = True
418 self.at_prompt_logevt = self.logstream.logfile.cur_evt
419 except Exception as ex:
420 self.log.error(str(ex))
421 self.cleanup_spawn()
422 raise
Stephen Warren80eea632016-02-11 11:46:12 -0700423 finally:
Stephen Warrenb1c556a2017-10-27 11:04:08 -0600424 self.log.timestamp()
Stephen Warren80eea632016-02-11 11:46:12 -0700425 self.log.end_section('Starting U-Boot')
Stephen Warren10e50632016-01-15 11:15:24 -0700426
427 def cleanup_spawn(self):
Stephen Warren75e731e2016-01-26 13:41:30 -0700428 """Shut down all interaction with the U-Boot instance.
Stephen Warren10e50632016-01-15 11:15:24 -0700429
430 This is used when an error is detected prior to re-establishing a
431 connection with a fresh U-Boot instance.
432
433 This is an internal function and should not be called directly.
434
435 Args:
436 None.
437
438 Returns:
439 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -0700440 """
Stephen Warren10e50632016-01-15 11:15:24 -0700441
442 try:
443 if self.p:
444 self.p.close()
445 except:
446 pass
447 self.p = None
448
Masami Hiramatsu4d3b9962022-02-16 15:16:02 +0900449 def restart_uboot(self, expect_reset=False):
Simon Glass37c2ce12016-07-31 17:35:08 -0600450 """Shut down and restart U-Boot."""
451 self.cleanup_spawn()
Masami Hiramatsu4d3b9962022-02-16 15:16:02 +0900452 self.ensure_spawned(expect_reset)
Simon Glass37c2ce12016-07-31 17:35:08 -0600453
Simon Glass9bc20832016-07-04 11:58:39 -0600454 def get_spawn_output(self):
455 """Return the start-up output from U-Boot
456
457 Returns:
458 The output produced by ensure_spawed(), as a string.
459 """
460 if self.p:
461 return self.p.get_expect_output()
462 return None
463
Stephen Warren10e50632016-01-15 11:15:24 -0700464 def validate_version_string_in_text(self, text):
Stephen Warren75e731e2016-01-26 13:41:30 -0700465 """Assert that a command's output includes the U-Boot signon message.
Stephen Warren10e50632016-01-15 11:15:24 -0700466
467 This is primarily useful for validating the "version" command without
468 duplicating the signon text regex in a test function.
469
470 Args:
471 text: The command output text to check.
472
473 Returns:
474 Nothing. An exception is raised if the validation fails.
Stephen Warren75e731e2016-01-26 13:41:30 -0700475 """
Stephen Warren10e50632016-01-15 11:15:24 -0700476
477 assert(self.u_boot_version_string in text)
478
479 def disable_check(self, check_type):
Stephen Warren75e731e2016-01-26 13:41:30 -0700480 """Temporarily disable an error check of U-Boot's output.
Stephen Warren10e50632016-01-15 11:15:24 -0700481
482 Create a new context manager (for use with the "with" statement) which
483 temporarily disables a particular console output error check.
484
485 Args:
486 check_type: The type of error-check to disable. Valid values may
487 be found in self.disable_check_count above.
488
489 Returns:
490 A context manager object.
Stephen Warren75e731e2016-01-26 13:41:30 -0700491 """
Stephen Warren10e50632016-01-15 11:15:24 -0700492
493 return ConsoleDisableCheck(self, check_type)
Michal Simek6b463182016-05-19 07:57:41 +0200494
495 def temporary_timeout(self, timeout):
496 """Temporarily set up different timeout for commands.
497
498 Create a new context manager (for use with the "with" statement) which
499 temporarily change timeout.
500
501 Args:
502 timeout: Time in milliseconds.
503
504 Returns:
505 A context manager object.
506 """
507
508 return ConsoleSetupTimeout(self, timeout)