summaryrefslogtreecommitdiff
path: root/util/ec3po/interpreter.py
Commit message (Collapse)AuthorAgeFilesLines
* ec3po: use source name in loggerMary Ruthven2019-01-041-4/+6
| | | | | | | | | | | | | | | | Include the ec3po source name in the logger, so it is clear which console is logging the messages. BUG=none BRANCH=none TEST=none Change-Id: I8d3bb330c3928b8f05078fd90b0238c4b027d90b Signed-off-by: Mary Ruthven <mruthven@google.com> Reviewed-on: https://chromium-review.googlesource.com/1376776 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Mary Ruthven <mruthven@chromium.org> Reviewed-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
* ec3po: use a copy of the logger objectMary Ruthven2018-12-031-1/+4
| | | | | | | | | | | | | | | | | | | | | Use a copy of the console and interpreter logger objects, so modifying the log level for one console does not affect the others. With this change you can enable the debug log level on the cr50 console without enabling debug for the ec console. The ec console prints a lot more messages than cr50, so it can be difficult to debug cr50 console issues if both consoles are set to debug. BUG=none BRANCH=none TEST=verify setting cr50 loglevel does not affect the ec loglevel. Change-Id: I529bf686443bf9df004e209e880f811608eef6a8 Signed-off-by: Mary Ruthven <mruthven@google.com> Reviewed-on: https://chromium-review.googlesource.com/1355967 Commit-Ready: Mary Ruthven <mruthven@chromium.org> Tested-by: Mary Ruthven <mruthven@chromium.org> Reviewed-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
* ec3po console and interpreter: Handle EOFError from the pipes.Matthew Blecker2018-10-181-3/+13
| | | | | | | | | | | | | | | | | | | | | | | | EOF is expected sometimes upon shutdown, when one thread (console or interpreter) manages to close its write side of a pipe before the other thread receives the shutdown pipe unblocked notification. EOF is now considered another indication to shutdown. BRANCH=none BUG=b:79684405 TEST=With this change plus CL:1279145 to switch to threading, I am no longer able to reproduce the formerly occasional EOFError tracebacks upon shutdown, with either ctrl+c or SIGTERM. Basic servod functionality continues to work, including dut-control ec_uart_pty, servo_console_pty (both tested with minicom), dut_i2c_mux, enable_ite_dfu, get_ite_chipid. Testing performed with a servo_micro connected to an octopus_ite. I tested both without and with CL:1279145 i.e. both with subprocesses and with threads (though I only ever encountered EOFError with the latter). Change-Id: Iaa1ddc5f05a32ef806fa5f84d0ed0ad4739189ce Signed-off-by: Matthew Blecker <matthewb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1284509 Reviewed-by: Nick Sanders <nsanders@chromium.org> Reviewed-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
* ec3po: add missing traceback module import to interpreter.pyMatthew Blecker2018-10-181-0/+1
| | | | | | | | | | | BRANCH=none BUG=b:79684405 TEST=The import succeeds. Haven't repeated getting a traceback here yet. Change-Id: I720d93ea640c4bb13007b6a7c6e515b5871ef5c5 Signed-off-by: Matthew Blecker <matthewb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1286295 Reviewed-by: Nick Sanders <nsanders@chromium.org>
* ec3po: Update platform/ec/ side of ec3po to use threadproc_shim.py.Matthew Blecker2018-10-151-12/+14
| | | | | | | | | | | | | | | | | | | 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>
* ec3po: Add optional shutdown_pipe StartLoop() arguments.Matthew Blecker2018-10-151-17/+37
| | | | | | | | | | | | | | | | | | | | | | | | | When ec3po.console.StartLoop() or ec3po.interpreter.StartLoop() is given a shutdown_pipe file object, it will exit the loop when that file becomes readable (unblocked), and will close the file upon loop exit (as they do with the other files they poll). This will be used by the servod-side of ec3po (in hdctools repo) to replace use of multiprocessing.Process.terminate(), because that has no threading equivalent, and I am migrating ec3po to use threads instead of subprocesses. BRANCH=none BUG=b:79684405 TEST=With a corresponding servod-side change in hdctools to use shutdown_pipe args instead of terminate(), servod shutdown via either ctrl+c or SIGTERM still happens correctly, without any delay, leftover processes, or tracebacks. Testing performed with a servo_micro attached to an octopus_ite. Change-Id: I82db2fd60620ac2a05a4d09afe263a57c141c615 Signed-off-by: Matthew Blecker <matthewb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1277615 Reviewed-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
* ec3po: Remove sys.exit() call from the end of StartLoop() functions.Matthew Blecker2018-10-121-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | This removes explicit process exit() from both console and interpeter ec3po StartLoop() functions. Use of exit() is incompatible with running these functions in threads instead of subprocesses. This should be a no-op, since letting execution finish in Python should be equivalent to sys.exit(). Since exit() in the finally: block effectively suppressed exceptions, the same behavior is now achieved in interpreter.StartLoop() by use of an except: block, same as console.StartLoop() already had. BRANCH=none BUG=b:79684405 TEST=All servod processes still exit promptly and without printing tracebacks, upon either ctrl+c from console where servod launched, or from SIGTERM to parent servod process. I confirmed that the new code was in use by adding an extra logging line on each of ec3po console and interpreter loop start (not present in uploaded patch). Testing performed with a servo_micro attached to an octopus_ite. Change-Id: Ie92610de88fea78f6c50f5e49b9d0940f209cd92 Signed-off-by: Matthew Blecker <matthewb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1278085 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* Revert "ec3po: quit console & interpreter loop when parent process changes."Nick Sanders2018-08-271-6/+3
| | | | | | | | | | | | | | | | | | This reverts commit 3b39bc56d38511e10871447392b709b3b8e65637. Reason: wedges consoles on servod. BRANCH=None BUG=b:113246887 TEST=reverting unbreaks servod Change-Id: I2f4dd65727347ce4757c4863664e3b2e46c826fc Signed-off-by: Nick Sanders <nsanders@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1191383 Tested-by: Raul E Rangel <rrangel@chromium.org> Tested-by: Simon Glass <sjg@chromium.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
* ec3po: quit console & interpreter loop when parent process changes.Ruben Rodriguez Buchillon2018-08-241-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Right now, when the parent process dies ungracefully - say kill -9 - then the interpreter, and console processes remain active. This leads to bugs in the servod implementation from holding on to sockets, to reinitialization issues of a new instance on the same servod device. This change quits the loops inside console & interpreter as soon as the parent pid changes (i.e. the parent dies). BRANCH=None BUG=chromium:841121 TEST=sudo servod -b soraka ps aux | grep servod >xxxxx servod >xxxxy servod >xxxyx servod >xxxaa grep servod sudo kill -9 xxxxx ps aux | grep servod >xxxab grep servod Before this, just kill -9 on the main thread did not take the children with it. Change-Id: I547bd92bf8732bff8aef2b72840417c809ba27d6 Signed-off-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1186299 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Nick Sanders <nsanders@chromium.org>
* ec3po: less chatty debug printNick Sanders2017-03-011-7/+7
| | | | | | | | | | | | | | | ec3po had very, very chatty debug printing. Reduce some of this so that -d is a bit easier to read. BUG=None BRANCH=None TEST=sudo servod -b electro -d Change-Id: I163e1362dd1e90f374ca3c37e1f1e0aa7fd7a1e2 Reviewed-on: https://chromium-review.googlesource.com/441919 Commit-Ready: Nick Sanders <nsanders@chromium.org> Tested-by: Nick Sanders <nsanders@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* util: ec3po: Allow changing interrogation modes.Aseda Aboagye2016-02-101-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, a majority of the users don't use the experimental EC console and as it stands, they have to wait approximately 300ms after pressing enter after every command. This commit adds a OOBM command to change the interrogation mode. Additionally, it allows this command to be entered from the EC console. Usage: interrogate <never | always | auto> [enhanced] Type the percent key to enter the (primitive) OOBM console. From there a user can enter 'interrogate never' followed by enter to completely disable the interrogation that occurs. By default, the EC-3PO console will start in the 'always' state. BUG=None BRANCH=None TEST=./util/ec3po/run_tests.sh TEST=Run cros lint --debug for all changed files. Change-Id: I10eef0c796eab4e0af1c232a3d3da8898ba3d348 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/327035 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Wai-Hong Tam <waihong@chromium.org>
* util: ec3po: Add OOBM queue and dynamic loglevels.Aseda Aboagye2016-02-031-0/+8
| | | | | | | | | | | | | | | | | | | | | | This commit adds an Out Of Band Managament queue which will allow the console to receive commands outside of the PTY which it can take action on. The first use of this is to dynamically change the logging level. Prior to this change, changing the log level using dut-control would not affect the log level of the console or interpreter. BUG=None BRANCH=None TEST=Launch modified servod; issue dut-control loglevel:debug, verify that debug messages from both servod and ec3po are emitted. Then issue dut-control loglevel:info and verify that no debug messages from either are emitted. Change-Id: I692824742b018da9540a81305985f6f355f716e6 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/325134 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* util: ec3po: Add support to disconnect from UART.Aseda Aboagye2016-01-111-5/+63
| | | | | | | | | | | | | | | | | | | | | | This commit adds support for the EC-3PO interpreter to disconnect and reconnect to the EC UART. This is handy so that other tools that need to use the raw UART directly can do so without interference from EC-3PO. BUG=chromium:571170 BRANCH=None TEST=For both enhanced and non-enhanced EC images, issue disconnect command and verify that no debug prints were emitted and no commands were sent to the EC. Then issue reconnect and verify that the console works as normal and that no commands were buffered. TEST=./util/ec3po/run_tests.sh Change-Id: Ic572e25d24d5e45fbe2eeb84a534235c4ec98d38 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/321084 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* util: ec3po: Add served PTY to logging.Aseda Aboagye2016-01-051-1/+10
| | | | | | | | | | | | | | | | | | | | Some devices have multiple ECs (main EC and PD MCU) and therefore there are multiple consoles and interpreters running concurrently. This commit prepends each log message with the served PTY to identify which of the console or interpreter instances the log message comes from. BUG=None BRANCH=None TEST=Ran ec3po in servo for samus. Noticed each debug print with the different PTYs for the main EC as well as the PD MCU. TEST=util/ec3po/run_tests.sh Change-Id: Icc69d2257172f4fedc217572ad0b6d15dac40387 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/320597 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Wai-Hong Tam <waihong@chromium.org>
* util: ec3po: Change interrogation timeouts.Aseda Aboagye2016-01-051-2/+0
| | | | | | | | | | | | | | | | | | | | | | In testing, it was found that certain ECs couldn't respond to the EC_SYN in less than 0.1s. Therefore, this commit changes the interrogation timeouts. For non-enhanced EC images, the timeout has been increased to 0.3 seconds. This is small enough that there's not too much of a delay, but long enough that enhanced EC images can respond in time. With an enhanced EC image on veyron_jerry, EC_ACKs were arriving after ~0.2s. BUG=None BRANCH=None TEST=Flash enhanced EC image on veyron_jerry, start console/interpreter pair and verify that the console is functional. TEST=util/ec3po/run_tests.sh Change-Id: I4931aaee908653ae302a8e57941444e5f0b6ce2b Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/320594 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* ec3po: Add graceful exit.Aseda Aboagye2015-12-171-16/+27
| | | | | | | | | | | | | | | | | | | | | | | | The console and interpreter are usually killed by KeyboardInterrupt whether or not it's run standalone or by servod. This commit tries to make the exit graceful by closing pipes, file descriptors, and exiting each process. BUG=chromium:570526 BRANCH=None TEST=Run ec3po standalone and hit Ctrl+C to kill it. Observe no traceback and no leftover processes. TEST=Repeat above test, but inside servod TEST=cros lint --debug util/ec3po/console.py TEST=cros lint --debug util/ec3po/interpreter.py TEST=python2 -b util/ec3po/console_interpreter.py TEST=python2 -b util/ec3po/console_interpreter.py Change-Id: Ia151b9ede8adf7f8dec6c07277f62d097c13e63e Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/319252 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Wai-Hong Tam <waihong@chromium.org>
* ec3po: Clean up and stylistic changes.Aseda Aboagye2015-12-081-17/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | It was brought to my attention that there were some issues with the ec3po code. This commit addresses those issues raised. - executable bits dropped from __init__.py and interpreter.py. - sys.argv[1:] is now passed into console.py:main(). - Added blank lines at top of header. - Removed dummy exception class (MoveCursorError). - Added name of modules in the logger, so that it's not just 'root' when included in other modules. BUG=chrome-os-partner:46054 BRANCH=None TEST=./util/ec3po/console_unittest.py -b TEST=./util/ec3po/interpreter_unittest.py -b TEST=cros lint --debug ./util/ec3po/console.py TEST=cros lint --debug ./util/ec3po/console_unittest.py TEST=cros lint --debug ./util/ec3po/interpreter.py TEST=cros lint --debug ./util/ec3po/interpreter_unittest.py Change-Id: I00db368906958d1089c3662eb253be23f81cc70c Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/316479 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Mike Frysinger <vapier@chromium.org>
* ec3po: Add compatibility for older EC images.Aseda Aboagye2015-11-261-69/+135
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The EC-3PO console and interpreter could be used to talk to EC images which do not have the necessary changes to support the new enhancements. If this was the case, the interpreter would be very confused and the user wouldn't be able to use the console. This commit adds compatibility support for talking to both non-enhanced and enhanced EC images. When the console and interpreter are instantiated, they assume by default that the EC image they are talking to is non-enhanced. When the user presses the carriage return key, the console initiates an interrogation with the EC image. The interrogation is a simple EC_SYN(0xEC) and waits EC_INTERROGATION_TIMEOUT for the correct EC_ACK(0xC0). Enhanced EC images will try to reply immediately to a EC_SYN. Non-enhanced EC images will just ignore the EC_SYN as it's not a printable character. Once the interrogation is complete, the console will either simply pass everything forwards to the EC or provide the console interface itself. BUG=chrome-os-partner:46063 BRANCH=None TEST=Enabled CONFIG_EXPERIMENTAL_CONSOLE on GLaDOS. Entered some commands and verified console was working. Disabled CONFIG_EXPERIMENTAL_CONSOLE on GLaDOS, reflashed, and verified console was still working without restarting the EC-3PO console. TEST=./util/ec3po/console_unittest.py -b TEST=./util/ec3po/interpreter_unittest.py -b TEST=cros lint --debug util/ec3po/console.py TEST=cros lint --debug util/ec3po/console_unittest.py TEST=cros lint --debug util/ec3po/interpreter.py TEST=cros lint --debug util/ec3po/interpreter_unittest.py Change-Id: I4f472afbdd7e898bee308c239b68ace0f4049842 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/313002 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* util: Add EC-3PO, the EC console interpreter.Aseda Aboagye2015-11-111-0/+259
EC-3PO is the console interpreter that will one day replace the EC console that we have today. EC-3PO aims to migrate our rich debug console from the EC itself to the host. This allows us to maintain our rich debug console without impacting our EC image sizes while also allowing us to add new features. This commit is the 1st of three phases, the insertion phase. The main goal of this insertion phase is to get EC-3PO in place between servo and the EC UART, while not modifying the behaviour of the console too much. At this point, EC-3PO is capable of the following things: - Replicate command editing. - Save command history. - Performs error checking with console commands. The command editing should be at parity with the current EC console. With EC-3PO, one can have a much longer command history which also persists across EC reboots. And lastly, with a cooperating EC image, EC-3PO can perform error checking with console commands. Automatically retrying console commands if the command was incorrectly received at the EC end. Currently, commands are sent to the EC in a "packed" plaintext form. The next phase will introduce the host command packet communication. console.py is the module that provides the console interface between the user and the interpreter. It handles the presentation of the console including command editing. It also has an accompanying set of unit tests in console_unittest.py. It currently has 1 test suite to test the various console editing methods. interpreter.py is the module that provides the interpretation layer between the EC and the user. It also is responsible for the automatic command retrying. It requires pipe connections to be made to it for command and debug data communication. BUG=chrome-os-partner:46054 BRANCH=None TEST=util/ec3po/console_unittest.py TEST=Flash GLaDOS with a modified EC build. Run console.py passing the EC UART, verify that I can edit commands, send commands, view command history, and receive output from the EC. TEST=cros lint --log-level debug ./util/ec3po/console.py TEST=cros lint --log-level debug ./util/ec3po/interpreter.py TEST=cros lint --log-level debug ./util/ec3po/console_unittest.py Change-Id: I38ae425836efd69044334e1ed0daf3f88a95917c Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/308615 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Wai-Hong Tam <waihong@chromium.org>