From 4f85283fb3770cd06045c98abe3fd04dc3e02d60 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 10 Jun 2020 06:33:56 -0700 Subject: [PATCH] [toranj] allow verbose mode (on all nodes) to be enabled using env variable (#5078) This commit adds additional mechanism in `toranj` to enable verbose mode on all nodes by setting the env variable `TORANJ_VERBOSE` (this is in addition to existing mechanism where verbose mode can be enabled per node from a test script). When `TORANJ_VERBOSE` env is used to enable verbose mode, it also enables OT logging on all nodes (OT logs are collected in the `wpantund-logs.log` files along with `wpantund` logs). This commit also updates the `toranj/README.md` to describe the new mechanism. --- tests/toranj/README.md | 4 ++-- tests/toranj/wpan.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/toranj/README.md b/tests/toranj/README.md index c74fec609..4a3351944 100644 --- a/tests/toranj/README.md +++ b/tests/toranj/README.md @@ -306,13 +306,13 @@ Every `wpan.Node()` instance will save its corresponding `wpantund` logs. By def When `start.sh` script is used to run all test-cases, if any test fails, to help with debugging of the issue, the last 30 lines of `wpantund` logs of every node involved in the test-case is dumped to `stdout`. -A `wpan.Node()` instance can also provide additional logs and info as the test-cases are run (verbose mode). By default this is disabled. It can be enabled for a node instance when it is created: +A `wpan.Node()` instance can also provide additional logs and info as the test-cases are run (verbose mode). It can be enabled for a node instance when it is created: ```python node = wpan.Node(verbose=True) # `node` instance will provide extra logs. ``` -Alternatively, `wpan.Node._VERBOSE` settings can be changed to enable verbose logging for all nodes. +Alternatively, `wpan.Node._VERBOSE` settings can be changed to enable verbose logging for all nodes. The default value of `wpan.Node._VERBOSE` is determined from environment variable `TORANJ_VERBOSE` (verbose mode is enabled when env variable is set to any of `1`, `True`, `Yes`, `Y`, `On` (case-insensitive)), otherwise it is disabled. When `TORANJ_VERBOSE` is enabled, the OpenThread logging is also enabled (and collected in `wpantund-log.log`files) on all nodes. Here is example of small test script and its corresponding log output with `verbose` mode enabled: diff --git a/tests/toranj/wpan.py b/tests/toranj/wpan.py index 6c72c84ae..a84355665 100644 --- a/tests/toranj/wpan.py +++ b/tests/toranj/wpan.py @@ -281,7 +281,8 @@ class Node(object): """ A wpantund OT NCP instance """ # defines the default verbosity setting (can be changed per `Node`) - _VERBOSE = False + _VERBOSE = os.getenv('TORANJ_VERBOSE', + 'no').lower() in ['true', '1', 't', 'y', 'yes', 'on'] _SPEED_UP_FACTOR = 1 # defines the default time speed up factor # path to `wpantund`, `wpanctl`, `ot-ncp-ftd`,`ot-ncp` and `ot-rcp` @@ -687,7 +688,7 @@ class Node(object): # class methods @classmethod - def init_all_nodes(cls, disable_logs=True, wait_time=15): + def init_all_nodes(cls, disable_logs=not _VERBOSE, wait_time=15): """Issues a `wpanctl.leave` on all `Node` objects and waits for them to be ready""" random.seed(123456) time.sleep(0.5)