diff options
author | Yilin Yang <kerker@google.com> | 2020-09-18 16:51:01 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-09-26 02:04:14 +0000 |
commit | 58d1886f5bba0cea0b79b3d4c1cc62e9222ff252 (patch) | |
tree | b5994cecb1ab328129b4c15b584a15b159b6c442 /util/ec3po | |
parent | da114d8e76ef7aa85212f7798c50509199b15095 (diff) | |
download | chrome-ec-58d1886f5bba0cea0b79b3d4c1cc62e9222ff252.tar.gz |
ec3po: Migrate console.py to python2/3 compatible
BUG=chromium:1031705
BRANCH=master
TEST=`python2 console_unittest.py` pass
TEST=`python3 console_unittest.py` pass
TEST=same with https://crrev.com/c/2418191
Signed-off-by: kerker <kerker@chromium.org>
Change-Id: I9fb782923e68189f5526bf9e6b9e35c47facf2aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2418192
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'util/ec3po')
-rwxr-xr-x | util/ec3po/console.py | 120 | ||||
-rwxr-xr-x | util/ec3po/console_unittest.py | 400 |
2 files changed, 234 insertions, 286 deletions
diff --git a/util/ec3po/console.py b/util/ec3po/console.py index 93286a9b60..aec237ac16 100755 --- a/util/ec3po/console.py +++ b/util/ec3po/console.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python # Copyright 2015 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -10,6 +10,8 @@ handles the presentation of the EC console including editing methods as well as session-persistent command history. """ +# Note: This is a py2/3 compatible file. + from __future__ import print_function import argparse @@ -26,11 +28,13 @@ import stat import sys import traceback +import six + import interpreter import threadproc_shim -PROMPT = '> ' +PROMPT = b'> ' CONSOLE_INPUT_LINE_SIZE = 80 # Taken from the CONFIG_* with the same name. CONSOLE_MAX_READ = 100 # Max bytes to read at a time from the user. LOOK_BUFFER_SIZE = 256 # Size of search window when looking for the enhanced EC @@ -40,9 +44,9 @@ LOOK_BUFFER_SIZE = 256 # Size of search window when looking for the enhanced EC # enabled. Enhanced images will print a slightly different string. These # regular expressions are used to determine at reboot whether the EC image is # enhanced or not. -ENHANCED_IMAGE_RE = re.compile(r'Enhanced Console is enabled ' - r'\(v([0-9]+\.[0-9]+\.[0-9]+)\)') -NON_ENHANCED_IMAGE_RE = re.compile(r'Console is enabled; ') +ENHANCED_IMAGE_RE = re.compile(br'Enhanced Console is enabled ' + br'\(v([0-9]+\.[0-9]+\.[0-9]+)\)') +NON_ENHANCED_IMAGE_RE = re.compile(br'Console is enabled; ') # The timeouts are really only useful for enhanced EC images, but otherwise just # serve as a delay for non-enhanced EC images. Therefore, we can keep this @@ -57,9 +61,8 @@ NON_ENHANCED_EC_INTERROGATION_TIMEOUT = 0.3 # Maximum number of seconds to wait ENHANCED_EC_INTERROGATION_TIMEOUT = 1.0 # Maximum number of seconds to wait for # a response to an interrogation of an # enhanced EC image. -INTERROGATION_MODES = ['never', 'always', 'auto'] # List of modes which control - # when interrogations are - # performed with the EC. +# List of modes which control when interrogations are performed with the EC. +INTERROGATION_MODES = [b'never', b'always', b'auto'] # Format for printing host timestamp HOST_STRFTIME="%y-%m-%d %H:%M:%S.%f" @@ -106,7 +109,7 @@ class Console(object): represents the console's read-only side of the debug pipe. This must be a unidirectional pipe attached to the intepreter. EC debug messages use this pipe. - oobm_queue: A Queue.Queue or multiprocessing.Queue which is used for out of + oobm_queue: A queue.Queue or multiprocessing.Queue which is used for out of band management for the interactive console. input_buffer: A string representing the current input command. input_buffer_pos: An integer representing the current position in the buffer @@ -166,9 +169,9 @@ class Console(object): self.cmd_pipe = cmd_pipe self.dbg_pipe = dbg_pipe self.oobm_queue = threadproc_shim.Queue() - self.input_buffer = '' + self.input_buffer = b'' self.input_buffer_pos = 0 - self.partial_cmd = '' + self.partial_cmd = b'' self.esc_state = 0 self.line_limit = CONSOLE_INPUT_LINE_SIZE self.history = [] @@ -177,10 +180,10 @@ class Console(object): self.enhanced_ec = False self.interrogation_timeout = NON_ENHANCED_EC_INTERROGATION_TIMEOUT self.receiving_oobm_cmd = False - self.pending_oobm_cmd = '' - self.interrogation_mode = 'auto' + self.pending_oobm_cmd = b'' + self.interrogation_mode = b'auto' self.timestamp_enabled = True - self.look_buffer = '' + self.look_buffer = b'' self.raw_debug = False self.output_line_log_buffer = [] @@ -197,7 +200,7 @@ class Console(object): string.append('input_buffer_pos: %d' % self.input_buffer_pos) string.append('esc_state: %d' % self.esc_state) string.append('line_limit: %d' % self.line_limit) - string.append('history: [\'' + '\', \''.join(self.history) + '\']') + string.append('history: [\'' + '%s' % repr(self.history) + '\']') string.append('history_pos: %d' % self.history_pos) string.append('prompt: \'%s\'' % self.prompt) string.append('partial_cmd: \'%s\''% self.partial_cmd) @@ -251,9 +254,9 @@ class Console(object): """Print the history of entered commands.""" fd = self.master_pty # Make it pretty by figuring out how wide to pad the numbers. - wide = (len(self.history) / 10) + 1 + wide = (len(self.history) // 10) + 1 for i in range(len(self.history)): - line = ' %*d %s\r\n' % (wide, i, self.history[i]) + line = b' %*d %s\r\n' % (wide, i, self.history[i]) os.write(fd, line) def ShowPreviousCommand(self): @@ -317,7 +320,7 @@ class Console(object): self.input_buffer = self.partial_cmd self.input_buffer_pos = len(self.input_buffer) # Now that we've printed it, clear the partial cmd storage. - self.partial_cmd = '' + self.partial_cmd = b'' # Reset history position. self.history_pos = len(self.history) return @@ -352,7 +355,7 @@ class Console(object): # Write the rest of the line moved_col = os.write(fd, self.input_buffer[self.input_buffer_pos:]) # Write a space to clear out the last char - moved_col += os.write(fd, ' ') + moved_col += os.write(fd, b' ') # Update the input buffer position. self.input_buffer_pos += moved_col # Reset the cursor @@ -476,7 +479,7 @@ class Console(object): self.history.append(self.input_buffer) # Split the command up by spaces. - line = self.input_buffer.split(' ') + line = self.input_buffer.split(b' ') self.logger.debug('cmd: %s', self.input_buffer) cmd = line[0].lower() @@ -546,14 +549,15 @@ class Console(object): self.logger.debug('Begin OOBM command.') self.receiving_oobm_cmd = True # Print a "prompt". - os.write(self.master_pty, '\r\n% ') + os.write(self.master_pty, b'\r\n% ') return # Add chars to the pending OOBM command if we're currently receiving one. if self.receiving_oobm_cmd and byte != ControlKey.CARRIAGE_RETURN: - self.pending_oobm_cmd += chr(byte) - self.logger.debug('%s', chr(byte)) - os.write(self.master_pty, chr(byte)) + tmp_bytes = six.int2byte(byte) + self.pending_oobm_cmd += tmp_bytes + self.logger.debug('%s', tmp_bytes) + os.write(self.master_pty, tmp_bytes) return if byte == ControlKey.CARRIAGE_RETURN: @@ -566,26 +570,26 @@ class Console(object): self.pending_oobm_cmd) # Reset the state. - os.write(self.master_pty, '\r\n' + self.prompt) - self.input_buffer = '' + os.write(self.master_pty, b'\r\n' + self.prompt) + self.input_buffer = b'' self.input_buffer_pos = 0 self.receiving_oobm_cmd = False - self.pending_oobm_cmd = '' + self.pending_oobm_cmd = b'' return - if self.interrogation_mode == 'never': + if self.interrogation_mode == b'never': self.logger.debug('Skipping interrogation because interrogation mode' ' is set to never.') - elif self.interrogation_mode == 'always': + elif self.interrogation_mode == b'always': # Only interrogate the EC if the interrogation mode is set to 'always'. self.enhanced_ec = self.CheckForEnhancedECImage() self.logger.debug('Enhanced EC image? %r', self.enhanced_ec) if not self.enhanced_ec: # Send everything straight to the EC to handle. - self.cmd_pipe.send(chr(byte)) + self.cmd_pipe.send(six.int2byte(byte)) # Reset the input buffer. - self.input_buffer = '' + self.input_buffer = b'' self.input_buffer_pos = 0 self.logger.log(1, 'Reset input buffer.') return @@ -612,7 +616,7 @@ class Console(object): if byte == ControlKey.CARRIAGE_RETURN: self.logger.debug('Enter key pressed.') # Put a carriage return/newline and the print the prompt. - os.write(fd, '\r\n') + os.write(fd, b'\r\n') # TODO(aaboagye): When we control the printing of all output, print the # prompt AFTER printing all the output. We can't do it yet because we @@ -623,12 +627,12 @@ class Console(object): # Process the input. self.ProcessInput() # Now, clear the buffer. - self.input_buffer = '' + self.input_buffer = b'' self.input_buffer_pos = 0 # Reset history buffer pos. self.history_pos = len(self.history) # Clear partial command. - self.partial_cmd = '' + self.partial_cmd = b'' # Backspace elif byte == ControlKey.BACKSPACE: @@ -696,14 +700,14 @@ class Console(object): self.logger.debug('Dropped char: %c(%d)', byte, byte) return # Print the character. - os.write(fd, chr(byte)) + os.write(fd, six.int2byte(byte)) # Print the rest of the line (if any). extra_bytes_written = os.write(fd, self.input_buffer[self.input_buffer_pos:]) # Recreate the input buffer. self.input_buffer = (self.input_buffer[0:self.input_buffer_pos] + - ('%c' % byte) + + six.int2byte(byte) + self.input_buffer[self.input_buffer_pos:]) # Update the input buffer position. self.input_buffer_pos += 1 + extra_bytes_written @@ -730,12 +734,12 @@ class Console(object): if not count: return fd = self.master_pty - seq = '\033[' + str(count) + seq = b'\033[' + str(count).encode('ascii') if direction == 'left': # Bind the movement. if count > self.input_buffer_pos: count = self.input_buffer_pos - seq += 'D' + seq += b'D' self.logger.debug('move cursor left %d', count) self.input_buffer_pos -= count @@ -743,7 +747,7 @@ class Console(object): # Bind the movement. if (count + self.input_buffer_pos) > len(self.input_buffer): count = 0 - seq += 'C' + seq += b'C' self.logger.debug('move cursor right %d', count) self.input_buffer_pos += count @@ -777,15 +781,15 @@ class Console(object): def SendBackspace(self): """Backspace a character on the console.""" - os.write(self.master_pty, '\033[1D \033[1D') + os.write(self.master_pty, b'\033[1D \033[1D') def ProcessOOBMQueue(self): """Retrieve an item from the OOBM queue and process it.""" item = self.oobm_queue.get() self.logger.debug('OOBM cmd: %s', item) - cmd = item.split(' ') + cmd = item.split(b' ') - if cmd[0] == 'loglevel': + if cmd[0] == b'loglevel': # An integer is required in order to set the log level. if len(cmd) < 2: self.logger.debug('Insufficient args') @@ -803,22 +807,22 @@ class Console(object): # Ignoring the request if an integer was not provided. self.PrintOOBMHelp() - elif cmd[0] == 'timestamp': + elif cmd[0] == b'timestamp': mode = cmd[1].lower() self.timestamp_enabled = mode == 'on' self.logger.info('%sabling uart timestamps.', 'En' if self.timestamp_enabled else 'Dis') - elif cmd[0] == 'rawdebug': + elif cmd[0] == b'rawdebug': mode = cmd[1].lower() self.raw_debug = mode == 'on' self.logger.info('%sabling per interrupt debug logs.', 'En' if self.raw_debug else 'Dis') - elif cmd[0] == 'interrogate' and len(cmd) >= 2: + elif cmd[0] == b'interrogate' and len(cmd) >= 2: enhanced = False mode = cmd[1] - if len(cmd) >= 3 and cmd[2] == 'enhanced': + if len(cmd) >= 3 and cmd[2] == b'enhanced': enhanced = True # Set the mode if correct. @@ -831,7 +835,7 @@ class Console(object): self.logger.debug('Enhanced EC image is now %r', self.enhanced_ec) # Send command to interpreter as well. - self.cmd_pipe.send('enhanced ' + str(self.enhanced_ec)) + self.cmd_pipe.send(b'enhanced ' + str(self.enhanced_ec).encode('ascii')) else: self.PrintOOBMHelp() @@ -841,10 +845,10 @@ class Console(object): def PrintOOBMHelp(self): """Prints out the OOBM help.""" # Print help syntax. - os.write(self.master_pty, '\r\n' + 'Known OOBM commands:\r\n') - os.write(self.master_pty, ' interrogate <never | always | auto> ' - '[enhanced]\r\n') - os.write(self.master_pty, ' loglevel <int>\r\n') + os.write(self.master_pty, b'\r\n' + b'Known OOBM commands:\r\n') + os.write(self.master_pty, b' interrogate <never | always | auto> ' + b'[enhanced]\r\n') + os.write(self.master_pty, b' loglevel <int>\r\n') def CheckBufferForEnhancedImage(self, data): """Adds data to a look buffer and checks to see for enhanced EC image. @@ -872,11 +876,11 @@ class Console(object): self.enhanced_ec = False # Inform the interpreter of the result. - self.cmd_pipe.send('enhanced ' + str(self.enhanced_ec)) + self.cmd_pipe.send(b'enhanced ' + str(self.enhanced_ec).encode('ascii')) self.logger.debug('Enhanced EC image? %r', self.enhanced_ec) # Clear look buffer since a match was found. - self.look_buffer = '' + self.look_buffer = b'' # Move the sliding window. self.look_buffer = self.look_buffer[-LOOK_BUFFER_SIZE:] @@ -891,7 +895,7 @@ def CanonicalizeTimeString(timestr): Returns: A string with 3 digits msec and an extra space. """ - return timestr[:-3] + ' ' + return timestr[:-3].encode('ascii') + b' ' def IsPrintable(byte): @@ -1021,7 +1025,7 @@ def StartLoop(console, command_active, shutdown_pipe=None): console.logger.debug('ec3po console received EOF from dbg_pipe') continue_looping = False else: - if console.interrogation_mode == 'auto': + if console.interrogation_mode == b'auto': # Search look buffer for enhanced EC image string. console.CheckBufferForEnhancedImage(data) # Write it to the user console. @@ -1043,15 +1047,15 @@ def StartLoop(console, command_active, shutdown_pipe=None): # Insert timestamps into the middle where appropriate # except if the last character is a newline - nls_found = data.count('\n', 0, end) + nls_found = data.count(b'\n', 0, end) now = datetime.now() tm = CanonicalizeTimeString(now.strftime('\n' + HOST_STRFTIME)) - data_tm = data.replace('\n', tm, nls_found) + data_tm = data.replace(b'\n', tm, nls_found) else: data_tm = data # timestamp required on next input - if data[end] == '\n': + if data[end] == b'\n': tm_req = True os.write(console.master_pty, data_tm) if command_active.value: diff --git a/util/ec3po/console_unittest.py b/util/ec3po/console_unittest.py index b648f6d0c8..66f47be358 100755 --- a/util/ec3po/console_unittest.py +++ b/util/ec3po/console_unittest.py @@ -1,10 +1,12 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python # Copyright 2015 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Unit tests for the EC-3PO Console interface.""" +# Note: This is a py2/3 compatible file. + from __future__ import print_function import binascii @@ -14,11 +16,13 @@ import mock import tempfile import unittest +import six + import console import interpreter import threadproc_shim -ESC_STRING = chr(console.ControlKey.ESC) +ESC_STRING = six.int2byte(console.ControlKey.ESC) class Keys(object): """A class that contains the escape sequences for special keys.""" @@ -45,7 +49,7 @@ class OutputStream(object): the cursor moved left. """ string = ESC_STRING - string += '[' + str(count) + 'D' + string += b'[' + str(count).encode('ascii') + b'D' return string @staticmethod @@ -60,102 +64,31 @@ class OutputStream(object): the cursor moved right. """ string = ESC_STRING - string += '[' + str(count) + 'C' + string += b'[' + str(count).encode('ascii') + b'C' return string -BACKSPACE_STRING = '' +BACKSPACE_STRING = b'' # Move cursor left 1 column. BACKSPACE_STRING += OutputStream.MoveCursorLeft(1) # Write a space. -BACKSPACE_STRING += ' ' +BACKSPACE_STRING += b' ' # Move cursor left 1 column. BACKSPACE_STRING += OutputStream.MoveCursorLeft(1) -def StringToByteList(string): - """Converts a string to list of bytes. +def BytesToByteList(string): + """Converts a bytes string to list of bytes. Args: - string: A literal string to turn into a list of bytes. + string: A literal bytes to turn into a list of bytes. Returns: A list of integers representing the byte value of each character in the string. """ + if six.PY3: + return [c for c in string] return [ord(c) for c in string] -def BadConsoleOutput(expected, got): - """Format the console output into readable text. - - Args: - expected: A list of bytes representing the expected output console - stream. - got: A list of byte representing the actual output console stream. - - Returns: - string: A formatted string which shows the expected console output stream - and the actual console output stream. - """ - esc_state = 0 - string = 'Incorrect console output stream.\n' - string += 'exp: |' - count = 0 - for char in expected: - if esc_state != 0: - if esc_state == console.EscState.ESC_START: - if char == '[': - esc_state = console.EscState.ESC_BRACKET - elif esc_state == console.EscState.ESC_BRACKET: - if char == 'D': - string += '[cursor left ' + str(count) + ' cols]' - esc_state = 0 - elif char == 'C': - string += '[cursor right ' + str(count) + ' cols]' - esc_state = 0 - else: - count = int(char) - # Print if it's printable. - elif console.IsPrintable(ord(char)): - string += char - else: - # It might be a sequence of some type. - if ord(char) == console.ControlKey.ESC: - # Need to look at the following sequence. - esc_state = console.EscState.ESC_START - else: - string += '{' + binascii.hexlify(char) + '}' - - string += '|\n\ngot: |' - for char in got: - if esc_state != 0: - if esc_state == console.EscState.ESC_START: - if char == '[': - esc_state = console.EscState.ESC_BRACKET - elif esc_state == console.EscState.ESC_BRACKET: - if char == 'D': - string += '[cursor left ' + str(count) + ' cols]' - esc_state = 0 - elif char == 'C': - string += '[cursor right ' + str(count) + ' cols]' - esc_state = 0 - else: - count = int(char) - # Print if it's printable. - elif console.IsPrintable(ord(char)): - string += char - else: - # It might be a sequence of some type. - if ord(char) == console.ControlKey.ESC: - # Need to look at the following sequence. - esc_state = console.EscState.ESC_START - else: - string += '{' + binascii.hexlify(char) + '}' - string += '|\n\n' - - # TODO(aaboagye): It would be nice to replace all those move left 1, ' ', - # move left 1, with backspace. - - return string - def CheckConsoleOutput(test_case, exp_console_out): """Verify what was sent out the console matches what we expect. @@ -167,10 +100,7 @@ def CheckConsoleOutput(test_case, exp_console_out): test_case.tempfile.seek(0) console_out = test_case.tempfile.read() - test_case.assertEqual(exp_console_out, - console_out, - (BadConsoleOutput(exp_console_out, console_out) - + str(test_case.console))) + test_case.assertEqual(exp_console_out, console_out) def CheckInputBuffer(test_case, exp_input_buffer): """Verify that the input buffer contains what we expect. @@ -181,10 +111,10 @@ def CheckInputBuffer(test_case, exp_input_buffer): buffer. """ test_case.assertEqual(exp_input_buffer, test_case.console.input_buffer, - ('input buffer does not match expected.\n' - 'expected: |' + exp_input_buffer + '|\n' - 'got: |' + test_case.console.input_buffer + - '|\n' + str(test_case.console))) + (b'input buffer does not match expected.\n' + b'expected: |' + exp_input_buffer + b'|\n' + b'got: |' + test_case.console.input_buffer + + b'|\n' + str(test_case.console).encode('ascii'))) def CheckInputBufferPosition(test_case, exp_pos): """Verify the input buffer position. @@ -216,10 +146,11 @@ def CheckHistoryBuffer(test_case, exp_history): # Next, check the actual contents of the history buffer. for i in range(len(exp_history)): test_case.assertEqual(exp_history[i], test_case.console.history[i], - ('history buffer contents are incorrect.\n' - 'exp: ' + exp_history[i] + '\n' - 'got: ' + test_case.console.history[i] + '\n' - 'internal state:\n' + str(test_case.console))) + (b'history buffer contents are incorrect.\n' + b'exp: ' + exp_history[i] + b'\n' + b'got: ' + test_case.console.history[i] + b'\n' + b'internal state:\n' + + str(test_case.console).encode('ascii'))) class TestConsoleEditingMethods(unittest.TestCase): @@ -252,8 +183,8 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_EnteringChars(self): """Verify that characters are echoed onto the console.""" - test_str = 'abc' - input_stream = StringToByteList(test_str) + test_str = b'abc' + input_stream = BytesToByteList(test_str) # Send the characters in. for byte in input_stream: @@ -273,8 +204,8 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_EnteringDeletingMoreCharsThanEntered(self): """Verify that we can press backspace more than we have entered chars.""" - test_str = 'spamspam' - input_stream = StringToByteList(test_str) + test_str = b'spamspam' + input_stream = BytesToByteList(test_str) # Send the characters in. for byte in input_stream: @@ -302,9 +233,9 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_EnteringMoreThanCharLimit(self): """Verify that we drop characters when the line is too long.""" - test_str = self.console.line_limit * 'o' # All allowed. - test_str += 5 * 'x' # All should be dropped. - input_stream = StringToByteList(test_str) + test_str = self.console.line_limit * b'o' # All allowed. + test_str += 5 * b'x' # All should be dropped. + input_stream = BytesToByteList(test_str) # Send the characters in. for byte in input_stream: @@ -326,11 +257,11 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_ValidKeysOnLongLine(self): """Verify that we can still press valid keys if the line is too long.""" # Fill the line. - test_str = self.console.line_limit * 'o' + test_str = self.console.line_limit * b'o' exp_console_out = test_str # Try to fill it even more; these should all be dropped. - test_str += 5 * 'x' - input_stream = StringToByteList(test_str) + test_str += 5 * b'x' + input_stream = BytesToByteList(test_str) # We should be able to press the following keys: # - Backspace @@ -344,8 +275,8 @@ class TestConsoleEditingMethods(unittest.TestCase): input_stream.append(console.ControlKey.BACKSPACE) exp_console_out += BACKSPACE_STRING # Refill the line. - input_stream.extend(StringToByteList('o')) - exp_console_out += 'o' + input_stream.extend(BytesToByteList(b'o')) + exp_console_out += b'o' # Left arrow key. input_stream.extend(Keys.LEFT_ARROW) @@ -365,7 +296,7 @@ class TestConsoleEditingMethods(unittest.TestCase): # Let's press enter now so we can test up and down. input_stream.append(console.ControlKey.CARRIAGE_RETURN) - exp_console_out += '\r\n' + self.console.prompt + exp_console_out += b'\r\n' + self.console.prompt # Up arrow key. input_stream.extend(Keys.UP_ARROW) @@ -413,7 +344,7 @@ class TestConsoleEditingMethods(unittest.TestCase): input_stream.extend(Keys.DEL) # This should look like a space, and then move cursor left 1 column since # we're at the end of line. - exp_console_out += ' ' + OutputStream.MoveCursorLeft(1) + exp_console_out += b' ' + OutputStream.MoveCursorLeft(1) # Send the sequence out. for byte in input_stream: @@ -436,18 +367,18 @@ class TestConsoleEditingMethods(unittest.TestCase): CheckInputBufferPosition(self, exp_pos) # Check that buffer is empty. - exp_input_buffer = '' + exp_input_buffer = b'' CheckInputBuffer(self, exp_input_buffer) # Check that the console output is empty. - exp_console_out = '' + exp_console_out = b'' CheckConsoleOutput(self, exp_console_out) def test_BackspaceWithinLine(self): """Verify that we shift the chars over when backspacing within a line.""" # Misspell 'help' - test_str = 'heelp' - input_stream = StringToByteList(test_str) + test_str = b'heelp' + input_stream = BytesToByteList(test_str) # Use the arrow key to go back to fix it. # Move cursor left 1 column. input_stream.extend(2*Keys.LEFT_ARROW) @@ -459,7 +390,7 @@ class TestConsoleEditingMethods(unittest.TestCase): self.console.HandleChar(byte) # Verify the input buffer - exp_input_buffer = 'help' + exp_input_buffer = b'help' CheckInputBuffer(self, exp_input_buffer) # Verify the input buffer position. It should be at 2 (cursor over the 'l') @@ -474,7 +405,7 @@ class TestConsoleEditingMethods(unittest.TestCase): # Move cursor left 1 column. exp_console_out += OutputStream.MoveCursorLeft(1) # Rest of the line and a space. (test_str in this case) - exp_console_out += 'lp ' + exp_console_out += b'lp ' # Reset the cursor 2 + 1 to the left. exp_console_out += OutputStream.MoveCursorLeft(3) @@ -484,8 +415,8 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_JumpToBeginningOfLineViaCtrlA(self): """Verify that we can jump to the beginning of a line with Ctrl+A.""" # Enter some chars and press CTRL+A - test_str = 'abc' - input_stream = StringToByteList(test_str) + [console.ControlKey.CTRL_A] + test_str = b'abc' + input_stream = BytesToByteList(test_str) + [console.ControlKey.CTRL_A] # Send the characters in. for byte in input_stream: @@ -506,8 +437,8 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_JumpToBeginningOfLineViaHomeKey(self): """Jump to beginning of line via HOME key.""" - test_str = 'version' - input_stream = StringToByteList(test_str) + test_str = b'version' + input_stream = BytesToByteList(test_str) input_stream.extend(Keys.HOME) # Send out the stream. @@ -527,8 +458,8 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_JumpToEndOfLineViaEndKey(self): """Jump to the end of the line using the END key.""" - test_str = 'version' - input_stream = StringToByteList(test_str) + test_str = b'version' + input_stream = BytesToByteList(test_str) input_stream += [console.ControlKey.CTRL_A] # Now, jump to the end of the line. input_stream.extend(Keys.END) @@ -553,8 +484,8 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_JumpToEndOfLineViaCtrlE(self): """Enter some chars and then try to jump to the end. (Should be a no-op)""" - test_str = 'sysinfo' - input_stream = StringToByteList(test_str) + test_str = b'sysinfo' + input_stream = BytesToByteList(test_str) input_stream.append(console.ControlKey.CTRL_E) # Send out the stream @@ -598,8 +529,8 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_MoveLeftWithArrowKey(self): """Move cursor left one column with arrow key.""" - test_str = 'tastyspam' - input_stream = StringToByteList(test_str) + test_str = b'tastyspam' + input_stream = BytesToByteList(test_str) input_stream.extend(Keys.LEFT_ARROW) # Send the sequence out. @@ -620,8 +551,8 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_MoveLeftWithCtrlB(self): """Move cursor back one column with Ctrl+B.""" - test_str = 'tastyspam' - input_stream = StringToByteList(test_str) + test_str = b'tastyspam' + input_stream = BytesToByteList(test_str) input_stream.append(console.ControlKey.CTRL_B) # Send the sequence out. @@ -642,8 +573,8 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_MoveRightWithArrowKey(self): """Move cursor one column to the right with the arrow key.""" - test_str = 'version' - input_stream = StringToByteList(test_str) + test_str = b'version' + input_stream = BytesToByteList(test_str) # Jump to beginning of line. input_stream.append(console.ControlKey.CTRL_A) # Press right arrow key. @@ -671,8 +602,8 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_MoveRightWithCtrlF(self): """Move cursor forward one column with Ctrl+F.""" - test_str = 'panicinfo' - input_stream = StringToByteList(test_str) + test_str = b'panicinfo' + input_stream = BytesToByteList(test_str) input_stream.append(console.ControlKey.CTRL_A) # Now, move right one column. input_stream.append(console.ControlKey.CTRL_F) @@ -707,14 +638,14 @@ class TestConsoleEditingMethods(unittest.TestCase): self.console.HandleChar(byte) # Nothing should have been output. - exp_console_output = '' + exp_console_output = b'' CheckConsoleOutput(self, exp_console_output) # The input buffer position should still be 0. CheckInputBufferPosition(self, 0) # The input buffer itself should be empty. - CheckInputBuffer(self, '') + CheckInputBuffer(self, b'') def test_ImpossibleMoveRightWithArrowKey(self): """Verify that we can't move right at the end of the line.""" @@ -726,19 +657,19 @@ class TestConsoleEditingMethods(unittest.TestCase): self.console.HandleChar(byte) # Nothing should have been output. - exp_console_output = '' + exp_console_output = b'' CheckConsoleOutput(self, exp_console_output) # The input buffer position should still be 0. CheckInputBufferPosition(self, 0) # The input buffer itself should be empty. - CheckInputBuffer(self, '') + CheckInputBuffer(self, b'') def test_KillEntireLine(self): """Verify that we can kill an entire line with Ctrl+K.""" - test_str = 'accelinfo on' - input_stream = StringToByteList(test_str) + test_str = b'accelinfo on' + input_stream = BytesToByteList(test_str) # Jump to beginning of line and then kill it with Ctrl+K. input_stream.extend([console.ControlKey.CTRL_A, console.ControlKey.CTRL_K]) @@ -747,7 +678,7 @@ class TestConsoleEditingMethods(unittest.TestCase): self.console.HandleChar(byte) # First, we expect that the input buffer is empty. - CheckInputBuffer(self, '') + CheckInputBuffer(self, b'') # The buffer position should be 0. CheckInputBufferPosition(self, 0) @@ -769,8 +700,8 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_KillPartialLine(self): """Verify that we can kill a portion of a line.""" - test_str = 'accelread 0 1' - input_stream = StringToByteList(test_str) + test_str = b'accelread 0 1' + input_stream = BytesToByteList(test_str) len_to_kill = 5 for _ in range(len_to_kill): # Move cursor left @@ -806,17 +737,17 @@ class TestConsoleEditingMethods(unittest.TestCase): CheckConsoleOutput(self, exp_console_out) def test_InsertingCharacters(self): - """Verify that we can insert charcters within the line.""" - test_str = 'accel 0 1' # Here we forgot the 'read' part in 'accelread' - input_stream = StringToByteList(test_str) + """Verify that we can insert characters within the line.""" + test_str = b'accel 0 1' # Here we forgot the 'read' part in 'accelread' + input_stream = BytesToByteList(test_str) # We need to move over to the 'l' and add read. - insertion_point = test_str.find('l') + 1 + insertion_point = test_str.find(b'l') + 1 for i in range(len(test_str) - insertion_point): # Move cursor left. input_stream.extend(Keys.LEFT_ARROW) # Now, add in 'read' - added_str = 'read' - input_stream.extend(StringToByteList(added_str)) + added_str = b'read' + input_stream.extend(BytesToByteList(added_str)) # Send the sequence out. for byte in input_stream: @@ -843,7 +774,7 @@ class TestConsoleEditingMethods(unittest.TestCase): # right one column. for i in range(len(added_str)): # Printed character. - exp_console_out += added_str[i] + exp_console_out += added_str[i:i+1] # The rest of the line exp_console_out += test_str[insertion_point:] # Reset the cursor back left @@ -856,12 +787,12 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_StoreCommandHistory(self): """Verify that entered commands are stored in the history.""" test_commands = [] - test_commands.append('help') - test_commands.append('version') - test_commands.append('accelread 0 1') + test_commands.append(b'help') + test_commands.append(b'version') + test_commands.append(b'accelread 0 1') input_stream = [] for c in test_commands: - input_stream.extend(StringToByteList(c)) + input_stream.extend(BytesToByteList(c)) input_stream.append(console.ControlKey.CARRIAGE_RETURN) # Send the sequence out. @@ -875,10 +806,10 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_CycleUpThruCommandHistory(self): """Verify that the UP arrow key will print itmes in the history buffer.""" # Enter some commands. - test_commands = ['version', 'accelrange 0', 'battery', 'gettime'] + test_commands = [b'version', b'accelrange 0', b'battery', b'gettime'] input_stream = [] for command in test_commands: - input_stream.extend(StringToByteList(command)) + input_stream.extend(BytesToByteList(command)) input_stream.append(console.ControlKey.CARRIAGE_RETURN) # Now, hit the UP arrow key to print the previous entries. @@ -891,9 +822,9 @@ class TestConsoleEditingMethods(unittest.TestCase): # The expected output should be test commands with prompts printed in # between, followed by line kills with the previous test commands printed. - exp_console_out = '' + exp_console_out = b'' for i in range(len(test_commands)): - exp_console_out += test_commands[i] + '\r\n' + self.console.prompt + exp_console_out += test_commands[i] + b'\r\n' + self.console.prompt # When we press up, the line should be cleared and print the previous buffer # entry. @@ -919,8 +850,8 @@ class TestConsoleEditingMethods(unittest.TestCase): self.console.HandleChar(byte) # We expect nothing to have happened. - exp_console_out = '' - exp_input_buffer = '' + exp_console_out = b'' + exp_input_buffer = b'' exp_input_buffer_pos = 0 exp_history_buf = [] @@ -933,8 +864,8 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_UpArrowDoesNotGoOutOfBounds(self): """Verify that pressing the up arrow many times won't go out of bounds.""" # Enter one command. - test_str = 'help version' - input_stream = StringToByteList(test_str) + test_str = b'help version' + input_stream = BytesToByteList(test_str) input_stream.append(console.ControlKey.CARRIAGE_RETURN) # Then press the up arrow key twice. input_stream.extend(2 * Keys.UP_ARROW) @@ -949,7 +880,7 @@ class TestConsoleEditingMethods(unittest.TestCase): # We expect that the console output should only contain our entered command, # a new prompt, and then our command aggain. - exp_console_out = test_str + '\r\n' + self.console.prompt + exp_console_out = test_str + b'\r\n' + self.console.prompt # Pressing up should reprint the command we entered. exp_console_out += test_str @@ -959,10 +890,10 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_CycleDownThruCommandHistory(self): """Verify that we can select entries by hitting the down arrow.""" # Enter at least 4 commands. - test_commands = ['version', 'accelrange 0', 'battery', 'gettime'] + test_commands = [b'version', b'accelrange 0', b'battery', b'gettime'] input_stream = [] for command in test_commands: - input_stream.extend(StringToByteList(command)) + input_stream.extend(BytesToByteList(command)) input_stream.append(console.ControlKey.CARRIAGE_RETURN) # Now, hit the UP arrow key twice to print the previous two entries. @@ -980,9 +911,9 @@ class TestConsoleEditingMethods(unittest.TestCase): # prompts, then followed by our last two commands in reverse. Then, we # should see the last entry in the list, followed by the saved partial cmd # of a blank line. - exp_console_out = '' + exp_console_out = b'' for i in range(len(test_commands)): - exp_console_out += test_commands[i] + '\r\n' + self.console.prompt + exp_console_out += test_commands[i] + b'\r\n' + self.console.prompt # When we press up, the line should be cleared and print the previous buffer # entry. @@ -1002,7 +933,7 @@ class TestConsoleEditingMethods(unittest.TestCase): CheckConsoleOutput(self, exp_console_out) # Verify input buffer. - exp_input_buffer = '' # Empty because our partial command was empty. + exp_input_buffer = b'' # Empty because our partial command was empty. exp_input_buffer_pos = len(exp_input_buffer) CheckInputBuffer(self, exp_input_buffer) CheckInputBufferPosition(self, exp_input_buffer_pos) @@ -1010,13 +941,13 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_SavingPartialCommandWhenNavigatingHistory(self): """Verify that partial commands are saved when navigating history.""" # Enter a command. - test_str = 'accelinfo' - input_stream = StringToByteList(test_str) + test_str = b'accelinfo' + input_stream = BytesToByteList(test_str) input_stream.append(console.ControlKey.CARRIAGE_RETURN) # Enter a partial command. - partial_cmd = 'ver' - input_stream.extend(StringToByteList(partial_cmd)) + partial_cmd = b'ver' + input_stream.extend(BytesToByteList(partial_cmd)) # Hit the UP arrow key. input_stream.extend(Keys.UP_ARROW) @@ -1030,7 +961,7 @@ class TestConsoleEditingMethods(unittest.TestCase): # The expected output should be the command we entered, a prompt, the # partial command, clearing of the partial command, the command entered, # clearing of the command entered, and then the partial command. - exp_console_out = test_str + '\r\n' + self.console.prompt + exp_console_out = test_str + b'\r\n' + self.console.prompt exp_console_out += partial_cmd for _ in range(len(partial_cmd)): exp_console_out += BACKSPACE_STRING @@ -1058,8 +989,8 @@ class TestConsoleEditingMethods(unittest.TestCase): self.console.HandleChar(byte) # We expect nothing to have happened. - exp_console_out = '' - exp_input_buffer = '' + exp_console_out = b'' + exp_input_buffer = b'' exp_input_buffer_pos = 0 exp_history_buf = [] @@ -1071,8 +1002,8 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_DeleteCharsUsingDELKey(self): """Verify that we can delete characters using the DEL key.""" - test_str = 'version' - input_stream = StringToByteList(test_str) + test_str = b'version' + input_stream = BytesToByteList(test_str) # Hit the left arrow key 2 times. input_stream.extend(2 * Keys.LEFT_ARROW) @@ -1092,7 +1023,7 @@ class TestConsoleEditingMethods(unittest.TestCase): # Remove the char by shifting everything to the left one, slicing out the # remove char. - exp_console_out += test_str[-1:] + ' ' + exp_console_out += test_str[-1:] + b' ' # Reset the cursor by moving back 2 columns because of the 'n' and space. exp_console_out += OutputStream.MoveCursorLeft(2) @@ -1110,13 +1041,13 @@ class TestConsoleEditingMethods(unittest.TestCase): def test_RepeatedCommandInHistory(self): """Verify that we don't store 2 consecutive identical commands in history""" # Enter a few commands. - test_commands = ['version', 'accelrange 0', 'battery', 'gettime'] + test_commands = [b'version', b'accelrange 0', b'battery', b'gettime'] # Repeat the last command. test_commands.append(test_commands[len(test_commands)-1]) input_stream = [] for command in test_commands: - input_stream.extend(StringToByteList(command)) + input_stream.extend(BytesToByteList(command)) input_stream.append(console.ControlKey.CARRIAGE_RETURN) # Send the sequence out. @@ -1156,7 +1087,7 @@ class TestConsoleCompatibility(unittest.TestCase): method. """ # Set the interrogation mode to always so that we actually interrogate. - self.console.interrogation_mode = 'always' + self.console.interrogation_mode = b'always' # Assume EC interrogations indicate that the image is non-enhanced. mock_check.return_value = False @@ -1164,8 +1095,8 @@ class TestConsoleCompatibility(unittest.TestCase): # Press enter, followed by the command, and another enter. input_stream = [] input_stream.append(console.ControlKey.CARRIAGE_RETURN) - test_command = 'version' - input_stream.extend(StringToByteList(test_command)) + test_command = b'version' + input_stream.extend(BytesToByteList(test_command)) input_stream.append(console.ControlKey.CARRIAGE_RETURN) # Send the sequence out. @@ -1175,17 +1106,22 @@ class TestConsoleCompatibility(unittest.TestCase): # Expected calls to send down the pipe would be each character of the test # command. expected_calls = [] - expected_calls.append(mock.call(chr(console.ControlKey.CARRIAGE_RETURN))) + expected_calls.append(mock.call( + six.int2byte(console.ControlKey.CARRIAGE_RETURN))) for char in test_command: - expected_calls.append(mock.call(char)) - expected_calls.append(mock.call(chr(console.ControlKey.CARRIAGE_RETURN))) + if six.PY3: + expected_calls.append(mock.call(bytes([char]))) + else: + expected_calls.append(mock.call(char)) + expected_calls.append(mock.call( + six.int2byte(console.ControlKey.CARRIAGE_RETURN))) # Verify that the calls happened. self.console.cmd_pipe.send.assert_has_calls(expected_calls) # Since we're acting as a pass-thru, the input buffer should be empty and # input_buffer_pos is 0. - CheckInputBuffer(self, '') + CheckInputBuffer(self, b'') CheckInputBufferPosition(self, 0) @mock.patch('console.Console.CheckForEnhancedECImage') @@ -1197,7 +1133,7 @@ class TestConsoleCompatibility(unittest.TestCase): method. """ # Set the interrogation mode to always so that we actually interrogate. - self.console.interrogation_mode = 'always' + self.console.interrogation_mode = b'always' # First, assume that the EC interrogations indicate an enhanced EC image. mock_check.return_value = True @@ -1205,15 +1141,18 @@ class TestConsoleCompatibility(unittest.TestCase): # 'previous' EC) was a non-enhanced image. self.console.enhanced_ec = False - test_command = 'sysinfo' + test_command = b'sysinfo' input_stream = [] - input_stream.extend(StringToByteList(test_command)) + input_stream.extend(BytesToByteList(test_command)) expected_calls = [] # All keystrokes to the console should be directed straight through to the # EC until we press the enter key. for char in test_command: - expected_calls.append(mock.call(char)) + if six.PY3: + expected_calls.append(mock.call(bytes([char]))) + else: + expected_calls.append(mock.call(char)) # Press the enter key. input_stream.append(console.ControlKey.CARRIAGE_RETURN) @@ -1229,10 +1168,10 @@ class TestConsoleCompatibility(unittest.TestCase): 'enhanced EC image.')) # The command would have been dropped however, so verify this... - CheckInputBuffer(self, '') + CheckInputBuffer(self, b'') CheckInputBufferPosition(self, 0) # ...and repeat the command. - input_stream = StringToByteList(test_command) + input_stream = BytesToByteList(test_command) input_stream.append(console.ControlKey.CARRIAGE_RETURN) # Send the sequence out. @@ -1255,7 +1194,7 @@ class TestConsoleCompatibility(unittest.TestCase): method. """ # Set the interrogation mode to always so that we actually interrogate. - self.console.interrogation_mode = 'always' + self.console.interrogation_mode = b'always' # First, assume that the EC interrogations indicate an non-enhanced EC # image. @@ -1264,9 +1203,9 @@ class TestConsoleCompatibility(unittest.TestCase): # 'previous' EC) was an enhanced image. self.console.enhanced_ec = True - test_command = 'sysinfo' + test_command = b'sysinfo' input_stream = [] - input_stream.extend(StringToByteList(test_command)) + input_stream.extend(BytesToByteList(test_command)) input_stream.append(console.ControlKey.CARRIAGE_RETURN) # Send the sequence out. @@ -1277,15 +1216,16 @@ class TestConsoleCompatibility(unittest.TestCase): # Verify this. self.assertFalse(self.console.enhanced_ec, msg=('Did not negotiate to' 'non-enhanced EC image.')) - CheckInputBuffer(self, '') + CheckInputBuffer(self, b'') CheckInputBufferPosition(self, 0) # The carriage return should have passed through though. expected_calls = [] - expected_calls.append(mock.call(chr(console.ControlKey.CARRIAGE_RETURN))) + expected_calls.append(mock.call( + six.int2byte(console.ControlKey.CARRIAGE_RETURN))) # Since the command was dropped, repeat the command. - input_stream = StringToByteList(test_command) + input_stream = BytesToByteList(test_command) input_stream.append(console.ControlKey.CARRIAGE_RETURN) # Send the sequence out. @@ -1295,8 +1235,12 @@ class TestConsoleCompatibility(unittest.TestCase): # Since we're not enhanced now, we should have sent each character in the # entire command separately and a carriage return. for char in test_command: - expected_calls.append(mock.call(char)) - expected_calls.append(mock.call(chr(console.ControlKey.CARRIAGE_RETURN))) + if six.PY3: + expected_calls.append(mock.call(bytes([char]))) + else: + expected_calls.append(mock.call(char)) + expected_calls.append(mock.call( + six.int2byte(console.ControlKey.CARRIAGE_RETURN))) # Verify all of the calls. self.console.cmd_pipe.send.assert_has_calls(expected_calls) @@ -1318,12 +1262,12 @@ class TestConsoleCompatibility(unittest.TestCase): """Verify that the check returns false if byte received is wrong.""" # Make the debug pipe return the wrong byte. self.console.dbg_pipe.poll.return_value = True - self.console.dbg_pipe.recv.return_value = '\xff' + self.console.dbg_pipe.recv.return_value = b'\xff' self.assertFalse(self.console.CheckForEnhancedECImage()) def test_EnhancedCheckUsingBuffer(self): """Verify that given reboot output, enhanced EC images are detected.""" - enhanced_output_stream = """ + enhanced_output_stream = b""" --- UART initialized after reboot --- [Reset cause: reset-pin soft] [Image: RO, jerry_v1.1.4363-2af8572-dirty 2016-02-23 13:26:20 aaboagye@lithium.mtv.corp.google.com] @@ -1352,7 +1296,7 @@ Enhanced Console is enabled (v1.0.0); type HELP for help. [0.224060 hash done 41dac382e3a6e3d2ea5b4d789c1bc46525cae7cc5ff6758f0de8d8369b506f57] [0.375150 POWER_GOOD seen] """ - for line in enhanced_output_stream.split('\n'): + for line in enhanced_output_stream.split(b'\n'): self.console.CheckBufferForEnhancedImage(line) # Since the enhanced console string was present in the output, the console @@ -1360,11 +1304,11 @@ Enhanced Console is enabled (v1.0.0); type HELP for help. self.assertTrue(self.console.enhanced_ec) # Also should check that the command was sent to the interpreter. - self.console.cmd_pipe.send.assert_called_once_with('enhanced True') + self.console.cmd_pipe.send.assert_called_once_with(b'enhanced True') # Now test the non-enhanced EC image. self.console.cmd_pipe.reset_mock() - non_enhanced_output_stream = """ + non_enhanced_output_stream = b""" --- UART initialized after reboot --- [Reset cause: reset-pin soft] [Image: RO, jerry_v1.1.4363-2af8572-dirty 2016-02-23 13:03:15 aaboagye@lithium.mtv.corp.google.com] @@ -1388,7 +1332,7 @@ Console is enabled; type HELP for help. [0.010285 power on 2] [0.010385 power state 5 = S5->S3, in 0x0000] """ - for line in non_enhanced_output_stream.split('\n'): + for line in non_enhanced_output_stream.split(b'\n'): self.console.CheckBufferForEnhancedImage(line) # Since the default console string is present in the output, it should be @@ -1396,7 +1340,7 @@ Console is enabled; type HELP for help. self.assertFalse(self.console.enhanced_ec) # Check that command was also sent to the interpreter. - self.console.cmd_pipe.send.assert_called_once_with('enhanced False') + self.console.cmd_pipe.send.assert_called_once_with(b'enhanced False') class TestOOBMConsoleCommands(unittest.TestCase): @@ -1432,11 +1376,11 @@ class TestOOBMConsoleCommands(unittest.TestCase): # 'interrogate never' should disable the interrogation from happening at # all. - cmd = 'interrogate never' + cmd = b'interrogate never' # Enter the OOBM prompt. - input_stream.extend(StringToByteList('%')) + input_stream.extend(BytesToByteList(b'%')) # Type the command - input_stream.extend(StringToByteList(cmd)) + input_stream.extend(BytesToByteList(cmd)) # Press enter. input_stream.append(console.ControlKey.CARRIAGE_RETURN) @@ -1455,11 +1399,11 @@ class TestOOBMConsoleCommands(unittest.TestCase): self.console.ProcessOOBMQueue() # Type out a few commands. - input_stream.extend(StringToByteList('version')) + input_stream.extend(BytesToByteList(b'version')) input_stream.append(console.ControlKey.CARRIAGE_RETURN) - input_stream.extend(StringToByteList('flashinfo')) + input_stream.extend(BytesToByteList(b'flashinfo')) input_stream.append(console.ControlKey.CARRIAGE_RETURN) - input_stream.extend(StringToByteList('sysinfo')) + input_stream.extend(BytesToByteList(b'sysinfo')) input_stream.append(console.ControlKey.CARRIAGE_RETURN) # Send the sequence out. @@ -1479,11 +1423,11 @@ class TestOOBMConsoleCommands(unittest.TestCase): # 'interrogate auto' should not interrogate at all. It should only be # scanning the output stream for the 'console is enabled' strings. - cmd = 'interrogate auto' + cmd = b'interrogate auto' # Enter the OOBM prompt. - input_stream.extend(StringToByteList('%')) + input_stream.extend(BytesToByteList(b'%')) # Type the command - input_stream.extend(StringToByteList(cmd)) + input_stream.extend(BytesToByteList(cmd)) # Press enter. input_stream.append(console.ControlKey.CARRIAGE_RETURN) @@ -1503,11 +1447,11 @@ class TestOOBMConsoleCommands(unittest.TestCase): self.console.ProcessOOBMQueue() # Type out a few commands. - input_stream.extend(StringToByteList('version')) + input_stream.extend(BytesToByteList(b'version')) input_stream.append(console.ControlKey.CARRIAGE_RETURN) - input_stream.extend(StringToByteList('flashinfo')) + input_stream.extend(BytesToByteList(b'flashinfo')) input_stream.append(console.ControlKey.CARRIAGE_RETURN) - input_stream.extend(StringToByteList('sysinfo')) + input_stream.extend(BytesToByteList(b'sysinfo')) input_stream.append(console.ControlKey.CARRIAGE_RETURN) # Send the sequence out. @@ -1528,11 +1472,11 @@ class TestOOBMConsoleCommands(unittest.TestCase): # 'interrogate always' should, like its name implies, interrogate always # after each press of the enter key. This was the former way of doing # interrogation. - cmd = 'interrogate always' + cmd = b'interrogate always' # Enter the OOBM prompt. - input_stream.extend(StringToByteList('%')) + input_stream.extend(BytesToByteList(b'%')) # Type the command - input_stream.extend(StringToByteList(cmd)) + input_stream.extend(BytesToByteList(cmd)) # Press enter. input_stream.append(console.ControlKey.CARRIAGE_RETURN) @@ -1555,11 +1499,11 @@ class TestOOBMConsoleCommands(unittest.TestCase): mock_check.side_effect = [False, False, False] # Type out a few commands. - input_stream.extend(StringToByteList('help list')) + input_stream.extend(BytesToByteList(b'help list')) input_stream.append(console.ControlKey.CARRIAGE_RETURN) - input_stream.extend(StringToByteList('taskinfo')) + input_stream.extend(BytesToByteList(b'taskinfo')) input_stream.append(console.ControlKey.CARRIAGE_RETURN) - input_stream.extend(StringToByteList('hibdelay')) + input_stream.extend(BytesToByteList(b'hibdelay')) input_stream.append(console.ControlKey.CARRIAGE_RETURN) # Send the sequence out. @@ -1579,11 +1523,11 @@ class TestOOBMConsoleCommands(unittest.TestCase): mock_check.reset_mock() self.console.oobm_queue.reset_mock() input_stream = [] - cmd = 'interrogate never enhanced' + cmd = b'interrogate never enhanced' # Enter the OOBM prompt. - input_stream.extend(StringToByteList('%')) + input_stream.extend(BytesToByteList(b'%')) # Type the command - input_stream.extend(StringToByteList(cmd)) + input_stream.extend(BytesToByteList(cmd)) # Press enter. input_stream.append(console.ControlKey.CARRIAGE_RETURN) @@ -1603,11 +1547,11 @@ class TestOOBMConsoleCommands(unittest.TestCase): self.console.ProcessOOBMQueue() # Type out a few commands. - input_stream.extend(StringToByteList('chgstate')) + input_stream.extend(BytesToByteList(b'chgstate')) input_stream.append(console.ControlKey.CARRIAGE_RETURN) - input_stream.extend(StringToByteList('hash')) + input_stream.extend(BytesToByteList(b'hash')) input_stream.append(console.ControlKey.CARRIAGE_RETURN) - input_stream.extend(StringToByteList('sysjump rw')) + input_stream.extend(BytesToByteList(b'sysjump rw')) input_stream.append(console.ControlKey.CARRIAGE_RETURN) # Send the sequence out. |