diff options
author | Matthew Blecker <matthewb@chromium.org> | 2018-10-12 12:19:01 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-10-15 23:28:47 -0700 |
commit | 35720d34cb1b853dce0f04e2909e2c7d92f324bc (patch) | |
tree | d57b74444cc9123b259695ccdf47606a8ed2a58d | |
parent | cb8555bcb6fc681f646e68c4baa8d3950ffbeaf2 (diff) | |
download | chrome-ec-35720d34cb1b853dce0f04e2909e2c7d92f324bc.tar.gz |
ec3po: Update platform/ec/ side of ec3po to use threadproc_shim.py.
This removes direct use of multiprocessing module from the platform/ec/
side of ec3po. Once the third_party/hdctools/ side has been updated to use
threadproc_shim.py as well, that library can be updated with
threading-oriented implementations.
BRANCH=none
BUG=b:79684405
TEST=With a servo_micro connected to an octopus_ite, functionality
involving the EC console continues to work. I tested dut-control
ec_uart_pty (including using the UART with minicom), dut_i2c_mux,
enable_ite_dfu, get_ite_chipid commands.
Change-Id: I68eb2d8cd1d927d63b12696938169281e51de6fc
Signed-off-by: Matthew Blecker <matthewb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1279153
Reviewed-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
-rwxr-xr-x | util/ec3po/console.py | 49 | ||||
-rwxr-xr-x | util/ec3po/console_unittest.py | 7 | ||||
-rw-r--r-- | util/ec3po/interpreter.py | 26 | ||||
-rwxr-xr-x | util/ec3po/interpreter_unittest.py | 10 |
4 files changed, 47 insertions, 45 deletions
diff --git a/util/ec3po/console.py b/util/ec3po/console.py index 29fc705d61..61d2315e7c 100755 --- a/util/ec3po/console.py +++ b/util/ec3po/console.py @@ -17,7 +17,6 @@ import ctypes import binascii # pylint: disable=cros-logging-import import logging -import multiprocessing import os import pty import re @@ -27,6 +26,7 @@ import sys import traceback import interpreter +import threadproc_shim PROMPT = '> ' @@ -96,14 +96,15 @@ class Console(object): master_pty: File descriptor to the master side of the PTY. Used for driving output to the user and receiving user input. user_pty: A string representing the PTY name of the served console. - cmd_pipe: A multiprocessing.Connection object which represents the console - side of the command pipe. This must be a bidirectional pipe. Console - commands and responses utilize this pipe. - dbg_pipe: A multiprocessing.Connection object which 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 multiprocessing.Queue which is used for out of band management - for the interactive console. + cmd_pipe: A socket.socket or multiprocessing.Connection object which + represents the console side of the command pipe. This must be a + bidirectional pipe. Console commands and responses utilize this pipe. + dbg_pipe: A socket.socket or multiprocessing.Connection object which + 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 + 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 to insert a char. @@ -139,12 +140,13 @@ class Console(object): user_pty: A string representing the PTY name of the served console. interface_pty: A string representing the PTY name of the served command interface. - cmd_pipe: A multiprocessing.Connection object which represents the console - side of the command pipe. This must be a bidirectional pipe. Console - commands and responses utilize this pipe. - dbg_pipe: A multiprocessing.Connection object which 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. + cmd_pipe: A socket.socket or multiprocessing.Connection object which + represents the console side of the command pipe. This must be a + bidirectional pipe. Console commands and responses utilize this pipe. + dbg_pipe: A socket.socket or multiprocessing.Connection object which + 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. """ logger = logging.getLogger('EC3PO.Console') self.logger = interpreter.LoggerAdapter(logger, {'pty': user_pty}) @@ -153,7 +155,7 @@ class Console(object): self.interface_pty = interface_pty self.cmd_pipe = cmd_pipe self.dbg_pipe = dbg_pipe - self.oobm_queue = multiprocessing.Queue() + self.oobm_queue = threadproc_shim.Queue() self.input_buffer = '' self.input_buffer_pos = 0 self.partial_cmd = '' @@ -822,8 +824,9 @@ def StartLoop(console, command_active, shutdown_pipe=None): Args: console: A Console object that has been properly initialzed. - command_active: multiprocessing.Value indicating if servod owns - the console, or user owns the console. This prevents input collisions. + command_active: ctypes data object or multiprocessing.Value indicating if + servod owns the console, or user owns the console. This prevents input + collisions. shutdown_pipe: A file object for a pipe or equivalent that becomes readable (not blocked) to indicate that the loop should exit. Can be None to never exit the loop. @@ -987,17 +990,17 @@ def main(argv): # Create some pipes to communicate between the interpreter and the console. # The command pipe is bidirectional. - cmd_pipe_interactive, cmd_pipe_interp = multiprocessing.Pipe() + cmd_pipe_interactive, cmd_pipe_interp = threadproc_shim.Pipe() # The debug pipe is unidirectional from interpreter to console only. - dbg_pipe_interactive, dbg_pipe_interp = multiprocessing.Pipe(duplex=False) + dbg_pipe_interactive, dbg_pipe_interp = threadproc_shim.Pipe(duplex=False) # Create an interpreter instance. itpr = interpreter.Interpreter(opts.ec_uart_pty, cmd_pipe_interp, dbg_pipe_interp, log_level) # Spawn an interpreter process. - itpr_process = multiprocessing.Process(target=interpreter.StartLoop, - args=(itpr,)) + itpr_process = threadproc_shim.ThreadOrProcess( + target=interpreter.StartLoop, args=(itpr,)) # Make sure to kill the interpreter when we terminate. itpr_process.daemon = True # Start the interpreter. @@ -1012,7 +1015,7 @@ def main(argv): console = Console(master_pty, os.ttyname(user_pty), cmd_pipe_interactive, dbg_pipe_interactive) # Start serving the console. - v = multiprocessing.Value(ctypes.c_bool, False) + v = threadproc_shim.Value(ctypes.c_bool, False) StartLoop(console, v) diff --git a/util/ec3po/console_unittest.py b/util/ec3po/console_unittest.py index 1e9dae9efd..22d468263b 100755 --- a/util/ec3po/console_unittest.py +++ b/util/ec3po/console_unittest.py @@ -11,12 +11,12 @@ import binascii # pylint: disable=cros-logging-import import logging import mock -import multiprocessing import tempfile import unittest import console import interpreter +import threadproc_shim ESC_STRING = chr(console.ControlKey.ESC) @@ -238,7 +238,7 @@ class TestConsoleEditingMethods(unittest.TestCase): # Create some dummy pipes. These won't be used since we'll mock out sends # to the interpreter. - dummy_pipe_end_0, dummy_pipe_end_1 = multiprocessing.Pipe() + dummy_pipe_end_0, dummy_pipe_end_1 = threadproc_shim.Pipe() self.console = console.Console(self.tempfile.fileno(), self.tempfile, tempfile.TemporaryFile(), dummy_pipe_end_0, dummy_pipe_end_1) @@ -250,9 +250,6 @@ class TestConsoleEditingMethods(unittest.TestCase): self.console.enhanced_ec = True self.console.CheckForEnhancedECImage = mock.MagicMock(return_value=True) - # Mock out sends to the interpreter. - multiprocessing.Pipe.send = mock.MagicMock() - def test_EnteringChars(self): """Verify that characters are echoed onto the console.""" test_str = 'abc' diff --git a/util/ec3po/interpreter.py b/util/ec3po/interpreter.py index 3957466dbf..e713c32f1a 100644 --- a/util/ec3po/interpreter.py +++ b/util/ec3po/interpreter.py @@ -47,12 +47,13 @@ class Interpreter(object): logger: A logger for this module. ec_uart_pty: An opened file object to the raw EC UART PTY. ec_uart_pty_name: A string containing the name of the raw EC UART PTY. - cmd_pipe: A multiprocessing.Connection object which represents the - Interpreter side of the command pipe. This must be a bidirectional pipe. - Commands and responses will utilize this pipe. - dbg_pipe: A multiprocessing.Connection object which represents the - Interpreter side of the debug pipe. This must be a unidirectional pipe - with write capabilities. EC debug output will utilize this pipe. + cmd_pipe: A socket.socket or multiprocessing.Connection object which + represents the Interpreter side of the command pipe. This must be a + bidirectional pipe. Commands and responses will utilize this pipe. + dbg_pipe: A socket.socket or multiprocessing.Connection object which + represents the Interpreter side of the debug pipe. This must be a + unidirectional pipe with write capabilities. EC debug output will utilize + this pipe. cmd_retries: An integer representing the number of attempts the console should retry commands if it receives an error. log_level: An integer representing the numeric value of the log level. @@ -77,12 +78,13 @@ class Interpreter(object): Args: ec_uart_pty: A string representing the EC UART to connect to. - cmd_pipe: A multiprocessing.Connection object which represents the - Interpreter side of the command pipe. This must be a bidirectional - pipe. Commands and responses will utilize this pipe. - dbg_pipe: A multiprocessing.Connection object which represents the - Interpreter side of the debug pipe. This must be a unidirectional pipe - with write capabilities. EC debug output will utilize this pipe. + cmd_pipe: A socket.socket or multiprocessing.Connection object which + represents the Interpreter side of the command pipe. This must be a + bidirectional pipe. Commands and responses will utilize this pipe. + dbg_pipe: A socket.socket or multiprocessing.Connection object which + represents the Interpreter side of the debug pipe. This must be a + unidirectional pipe with write capabilities. EC debug output will + utilize this pipe. cmd_retries: An integer representing the number of attempts the console should retry commands if it receives an error. log_level: An optional integer representing the numeric value of the log diff --git a/util/ec3po/interpreter_unittest.py b/util/ec3po/interpreter_unittest.py index 6eb6b3abda..8b9578a242 100755 --- a/util/ec3po/interpreter_unittest.py +++ b/util/ec3po/interpreter_unittest.py @@ -10,11 +10,11 @@ from __future__ import print_function # pylint: disable=cros-logging-import import logging import mock -import multiprocessing import tempfile import unittest import interpreter +import threadproc_shim class TestEnhancedECBehaviour(unittest.TestCase): """Test case to verify all enhanced EC interpretation tasks.""" @@ -29,8 +29,8 @@ class TestEnhancedECBehaviour(unittest.TestCase): self.tempfile = tempfile.NamedTemporaryFile() # Create the pipes that the interpreter will use. - self.cmd_pipe_user, self.cmd_pipe_itpr = multiprocessing.Pipe() - self.dbg_pipe_user, self.dbg_pipe_itpr = multiprocessing.Pipe(duplex=False) + self.cmd_pipe_user, self.cmd_pipe_itpr = threadproc_shim.Pipe() + self.dbg_pipe_user, self.dbg_pipe_itpr = threadproc_shim.Pipe(duplex=False) # Mock the open() function so we can inspect reads/writes to the EC. self.ec_uart_pty = mock.mock_open() @@ -264,8 +264,8 @@ class TestUARTDisconnection(unittest.TestCase): self.tempfile = tempfile.NamedTemporaryFile() # Create the pipes that the interpreter will use. - self.cmd_pipe_user, self.cmd_pipe_itpr = multiprocessing.Pipe() - self.dbg_pipe_user, self.dbg_pipe_itpr = multiprocessing.Pipe(duplex=False) + self.cmd_pipe_user, self.cmd_pipe_itpr = threadproc_shim.Pipe() + self.dbg_pipe_user, self.dbg_pipe_itpr = threadproc_shim.Pipe(duplex=False) # Mock the open() function so we can inspect reads/writes to the EC. self.ec_uart_pty = mock.mock_open() |