diff options
author | Aseda Aboagye <aaboagye@google.com> | 2016-02-01 18:21:28 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-02-03 17:16:33 -0800 |
commit | 086e501be397b3e14693b2dfd6a235dcc86844a0 (patch) | |
tree | 70b2d01a6287f977cb146fd3350a40ba9c47f1c9 | |
parent | f6f06c95d673c8912e2ddabe00a0606c20823b04 (diff) | |
download | chrome-ec-086e501be397b3e14693b2dfd6a235dcc86844a0.tar.gz |
util: ec3po: Add OOBM queue and dynamic loglevels.
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>
-rwxr-xr-x | util/ec3po/console.py | 17 | ||||
-rw-r--r-- | util/ec3po/interpreter.py | 8 |
2 files changed, 25 insertions, 0 deletions
diff --git a/util/ec3po/console.py b/util/ec3po/console.py index 2a426ac700..e75523e80b 100755 --- a/util/ec3po/console.py +++ b/util/ec3po/console.py @@ -86,6 +86,8 @@ class Console(object): 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. 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. @@ -127,6 +129,7 @@ class Console(object): self.user_pty = user_pty self.cmd_pipe = cmd_pipe self.dbg_pipe = dbg_pipe + self.oobm_queue = multiprocessing.Queue() self.input_buffer = '' self.input_buffer_pos = 0 self.partial_cmd = '' @@ -145,6 +148,7 @@ class Console(object): string.append('user_pty: %s' % self.user_pty) string.append('cmd_pipe: %s' % self.cmd_pipe) string.append('dbg_pipe: %s' % self.dbg_pipe) + string.append('oobm_queue: %s' % self.oobm_queue) string.append('input_buffer: %s' % self.input_buffer) string.append('input_buffer_pos: %d' % self.input_buffer_pos) string.append('esc_state: %d' % self.esc_state) @@ -695,6 +699,19 @@ def StartLoop(console): console.logger.debug('|DBG|->\'%s\'', data) os.write(console.master_pty, data) + while not console.oobm_queue.empty(): + console.logger.debug('OOBM queue ready for reading.') + cmd = console.oobm_queue.get() + console.logger.debug('cmd: %s', cmd) + if cmd.startswith('loglevel'): + console.logger.debug('Log level change request.') + new_log_level = int(cmd.split(' ')[1]) + console.logger.logger.setLevel(new_log_level) + console.logger.info('Log level changed to %d.', new_log_level) + + # Forward the request to the interpreter as well. + console.cmd_pipe.send(cmd) + finally: # Close pipes. console.dbg_pipe.close() diff --git a/util/ec3po/interpreter.py b/util/ec3po/interpreter.py index 23e896c640..4875d66b74 100644 --- a/util/ec3po/interpreter.py +++ b/util/ec3po/interpreter.py @@ -240,6 +240,14 @@ class Interpreter(object): if len(command) == 0: return + # Handle log level change requests. + if command.startswith('loglevel'): + self.logger.debug('Log level change request.') + new_log_level = int(command.split(' ')[1]) + self.logger.logger.setLevel(new_log_level) + self.logger.info('Log level changed to %d.', new_log_level) + return + # Check for interrogation command. if command == EC_SYN: # User is requesting interrogation. Send SYN as is. |