Lines Matching refs:self
60 def __init__(self, console, check_type): argument
61 self.console = console
62 self.check_type = check_type
64 def __enter__(self): argument
65 self.console.disable_check_count[self.check_type] += 1
66 self.console.eval_bad_patterns()
68 def __exit__(self, extype, value, traceback): argument
69 self.console.disable_check_count[self.check_type] -= 1
70 self.console.eval_bad_patterns()
80 def __init__(self, console, check_type, check_pattern): argument
81 self.console = console
82 self.check_type = check_type
83 self.check_pattern = check_pattern
85 def __enter__(self): argument
87 self.default_bad_patterns = bad_pattern_defs
88 bad_pattern_defs += ((self.check_type, self.check_pattern),)
89 self.console.disable_check_count = {pat[PAT_ID]: 0 for pat in bad_pattern_defs}
90 self.console.eval_bad_patterns()
92 def __exit__(self, extype, value, traceback): argument
94 bad_pattern_defs = self.default_bad_patterns
95 self.console.disable_check_count = {pat[PAT_ID]: 0 for pat in bad_pattern_defs}
96 self.console.eval_bad_patterns()
103 def __init__(self, console, timeout): argument
104 self.p = console.p
105 self.orig_timeout = self.p.timeout
106 self.p.timeout = timeout
108 def __enter__(self): argument
109 return self
111 def __exit__(self, extype, value, traceback): argument
112 self.p.timeout = self.orig_timeout
120 def __init__(self, log, config, max_fifo_fill): argument
140 self.log = log
141 self.config = config
142 self.max_fifo_fill = max_fifo_fill
144 self.logstream = self.log.get_stream('console', sys.stdout)
147 self.prompt = self.config.buildconfig['config_sys_prompt'][1:-1]
148 self.prompt_compiled = re.compile('^' + re.escape(self.prompt), re.MULTILINE)
149 self.p = None
150 self.disable_check_count = {pat[PAT_ID]: 0 for pat in bad_pattern_defs}
151 self.eval_bad_patterns()
153 self.at_prompt = False
154 self.at_prompt_logevt = None
155 self.lab_mode = False
157 def get_spawn(self): argument
165 def eval_bad_patterns(self): argument
166 self.bad_patterns = [pat[PAT_RE] for pat in bad_pattern_defs \
167 if self.disable_check_count[pat[PAT_ID]] == 0]
168 self.bad_pattern_ids = [pat[PAT_ID] for pat in bad_pattern_defs \
169 if self.disable_check_count[pat[PAT_ID]] == 0]
171 def close(self): argument
185 if self.p:
186 self.log.start_section('Stopping U-Boot')
187 close_type = self.p.close()
188 self.log.info(f'Close type: {close_type}')
189 self.log.end_section('Stopping U-Boot')
190 self.logstream.close()
192 def set_lab_mode(self): argument
198 self.log.info(f'test.py: Lab mode is active')
199 self.p.timeout = TIMEOUT_PREPARE_MS
200 self.lab_mode = True
202 def wait_for_boot_prompt(self, loop_num = 1): argument
206 self.log.info('Waiting for U-Boot to be ready')
207 bcfg = self.config.buildconfig
209 env_spl_skipped = self.config.env.get('env__spl_skipped', False)
210 env_spl_banner_times = self.config.env.get('env__spl_banner_times', 1)
212 while not self.lab_mode and loop_num > 0:
215 m = self.p.expect([pattern_u_boot_spl_signon,
216 pattern_lab_mode] + self.bad_patterns)
218 self.set_lab_mode()
222 self.bad_pattern_ids[m - 1])
225 if not self.lab_mode:
226 m = self.p.expect([pattern_u_boot_main_signon,
227 pattern_lab_mode] + self.bad_patterns)
229 self.set_lab_mode()
232 self.bad_pattern_ids[m - 1])
233 if not self.lab_mode:
234 self.u_boot_version_string = self.p.after
236 m = self.p.expect([self.prompt_compiled, pattern_ready_prompt,
237 pattern_stop_autoboot_prompt] + self.bad_patterns)
239 self.log.info(f'Found ready prompt {m}')
242 m = pattern_ready_prompt.search(self.p.after)
243 self.u_boot_version_string = m.group(2)
244 self.log.info(f'Lab: Board is ready')
245 self.p.timeout = TIMEOUT_MS
248 self.log.info(f'Found autoboot prompt {m}')
249 self.p.send(' ')
251 if not self.lab_mode:
253 self.bad_pattern_ids[m - 3])
254 self.log.info(f'U-Boot is ready')
257 self.log.timestamp()
259 def run_command(self, cmd, wait_for_echo=True, send_nl=True, argument
301 if self.at_prompt and \
302 self.at_prompt_logevt != self.logstream.logfile.cur_evt:
303 self.logstream.write(self.prompt, implicit=True)
306 self.at_prompt = False
307 if not self.p:
314 with self.temporary_timeout(TIMEOUT_CMD_MS):
317 chunk = rem[:self.max_fifo_fill]
318 rem = rem[self.max_fifo_fill:]
319 self.p.send(chunk)
324 m = self.p.expect([chunk] + self.bad_patterns)
326 self.at_prompt = False
328 self.bad_pattern_ids[m - 1])
332 self.wait_for_boot_prompt()
334 m = self.p.expect([self.prompt_compiled] + self.bad_patterns)
336 self.at_prompt = False
338 self.bad_pattern_ids[m - 1])
339 self.at_prompt = True
340 self.at_prompt_logevt = self.logstream.logfile.cur_evt
343 return self.p.before.strip('\r\n')
345 handle_exception(self.config, self, self.log, exc,
349 handle_exception(self.config, self, self.log, exc,
351 True, self.get_spawn_output())
354 self.log.timestamp()
356 def run_command_list(self, cmds): argument
370 output.append(self.run_command(cmd))
373 def send(self, msg): argument
375 self.run_command(msg, wait_for_prompt=False, wait_for_echo=False,
378 def ctrl(self, char): argument
387 self.log.action(f'Sending Ctrl-{char}')
388 self.send(chr(ord(char) - ord('@')))
390 def ctrlc(self): argument
396 self.ctrl('C')
398 def wait_for(self, text): argument
415 m = self.p.expect([text] + self.bad_patterns)
419 self.bad_pattern_ids[m - 1])
421 def drain_console(self): argument
443 if not self.p:
446 orig_timeout = self.p.timeout
449 self.p.timeout = 1000
452 self.p.expect(['This should never match U-Boot output'])
466 self.p.timeout = orig_timeout
468 def ensure_spawned(self, expect_reset=False): argument
485 if self.p:
488 if not self.config.gdbserver:
489 self.p.timeout = TIMEOUT_MS
492 self.log.start_section('Starting U-Boot')
493 self.at_prompt = False
494 self.p = self.get_spawn()
499 if not self.config.gdbserver:
500 self.p.timeout = TIMEOUT_MS
501 self.p.logfile_read = self.logstream
502 if self.config.use_running_system:
506 self.run_command(' ')
512 self.wait_for_boot_prompt(loop_num = loop_num)
513 self.at_prompt = True
514 self.at_prompt_logevt = self.logstream.logfile.cur_evt
516 self.log.error(str(ex))
517 self.cleanup_spawn()
520 self.log.timestamp()
521 self.log.end_section('Starting U-Boot')
523 def cleanup_spawn(self): argument
539 if self.p:
540 self.p.close()
543 self.p = None
545 def restart_uboot(self, expect_reset=False): argument
547 self.cleanup_spawn()
548 self.ensure_spawned(expect_reset)
550 def get_spawn_output(self): argument
556 if self.p:
557 return self.p.get_expect_output()
560 def validate_version_string_in_text(self, text): argument
573 assert(self.u_boot_version_string in text)
575 def disable_check(self, check_type): argument
589 return ConsoleDisableCheck(self, check_type)
591 def enable_check(self, check_type, check_pattern): argument
607 return ConsoleEnableCheck(self, check_type, check_pattern)
609 def temporary_timeout(self, timeout): argument
622 return ConsoleSetupTimeout(self, timeout)