Skip to content

Commit

Permalink
[python] Enhanced manual test
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing committed May 27, 2021
1 parent 764df83 commit 61cbf25
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ WORKDIR /app

RUN apt-get update \
&& apt-get install --no-install-recommends -y sudo git ca-certificates psmisc dhcpcd5 wpasupplicant wireless-tools \
gdb python3 python3-pip libcairo2-dev libjpeg-dev libgif-dev python3-dev \
&& apt-get install -y libglib2.0 avahi-daemon libavahi-client3 \
&& ln -fs /usr/share/zoneinfo/UTC /etc/localtime \
&& git clone https://github.com/openthread/ot-br-posix . \
Expand All @@ -23,14 +24,8 @@ RUN apt-get update \
&& ./script/bootstrap \
&& ./script/setup \
&& chmod 644 /etc/bind/named.conf.options \
&& mv ./script /tmp \
&& mv ./etc /tmp \
&& find . -delete \
&& rm -rf /usr/include \
&& mv /tmp/script . \
&& mv /tmp/etc . \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false git ca-certificates \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false apt-utils build-essential psmisc ninja-build cmake wget ca-certificates \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false git psmisc \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false psmisc ninja-build cmake wget \
libreadline-dev libncurses-dev libcpputest-dev libdbus-1-dev libavahi-common-dev \
libavahi-client-dev libboost-dev libboost-filesystem-dev libboost-system-dev libjsoncpp-dev \
libnetfilter-queue-dev \
Expand Down
4 changes: 2 additions & 2 deletions scripts/tests/cirque_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ function cirquetest_run_test() {
# Start Cirque flash server
export CURRENT_TEST="$1"
export DEVICE_LOG_DIR="$LOG_DIR/$CURRENT_TEST"/device_logs
shift
mkdir -p "$DEVICE_LOG_DIR"
__cirquetest_start_flask &
sleep 5
cd "$TEST_DIR"
./"$1.sh"
"$TEST_DIR/$CURRENT_TEST.sh" "$@"
exitcode=$?
__cirquetest_clean_flask
# TODO: Do docker system prune, we cannot filter which container
Expand Down
36 changes: 2 additions & 34 deletions src/test_driver/linux-cirque/ManualTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,10 @@
# ./scripts/tests/cirque_tests.sh run_test ManualTest
# under CHIP checkout.

set -e
set -ex

SOURCE="${BASH_SOURCE[0]}"
SOURCE_DIR="$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)"
REPO_DIR="$SOURCE_DIR/../../../"

chip_tool_dir=$REPO_DIR/examples/chip-tool
chip_light_dir=$REPO_DIR/examples/lighting-app/linux

function build_chip_tool() {
# These files should be successfully compiled elsewhere.
source "$REPO_DIR/scripts/activate.sh" >/dev/null
set -x
cd "$chip_tool_dir"
gn gen --check --fail-on-unused-args out/debug >/dev/null
run_ninja -C out/debug
docker build -t chip_tool -f Dockerfile . 2>&1
}

function build_chip_lighting() {
source "$REPO_DIR/scripts/activate.sh" >/dev/null
set -x
cd "$chip_light_dir"
gn gen --check --fail-on-unused-args out/debug
run_ninja -C out/debug
docker build -t chip_server -f Dockerfile . 2>&1
set +x
}

function main() {
pushd .
build_chip_tool
build_chip_lighting
popd
python3 "$SOURCE_DIR/test-manual.py"
}

source "$SOURCE_DIR"/shell-helpers.sh
main
python3 "$SOURCE_DIR/test-manual.py" "$@"
11 changes: 7 additions & 4 deletions src/test_driver/linux-cirque/helper/CHIPTestBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__(self, cirque_url, device_config):
self.device_ids = []
self.devices = []
self.non_ap_devices = []
self.thread_devices = []
self.ap_devices = []

# The entrance of the whole test
Expand Down Expand Up @@ -198,7 +199,7 @@ def connect_to_thread_network(self):
this network.
'''
self.logger.info("Running commands to form default Thread network")
for device in self.non_ap_devices:
for device in self.thread_devices:
self.wait_for_device_output(device['id'], "Border router agent started.", 5)

otInitCommands = [
Expand All @@ -209,19 +210,19 @@ def connect_to_thread_network(self):
"ot-ctl thread start",
"ot-ctl dataset active", # Emit
]
for device in self.non_ap_devices:
for device in self.thread_devices:
# Set default openthread provisioning
for cmd in otInitCommands:
self.execute_device_cmd(device['id'], cmd)
self.logger.info("Waiting for Thread network to be formed...")
threadNetworkFormed = False
for i in range(30):
roles = list()
for device in self.non_ap_devices:
for device in self.thread_devices:
# We can only check the status of ot-agent by query its state.
reply = self.execute_device_cmd(device['id'], 'ot-ctl state')
roles.append(reply['output'].split()[0])
threadNetworkFormed = (roles.count('leader') == 1) and (roles.count('leader') + roles.count('router') + roles.count('child') == len(self.non_ap_devices))
threadNetworkFormed = (roles.count('leader') == 1) and (roles.count('leader') + roles.count('router') + roles.count('child') == len(self.thread_devices))
if threadNetworkFormed:
break
time.sleep(1)
Expand Down Expand Up @@ -348,6 +349,8 @@ def initialize_home(self):
self.device_ids = [device_id for device_id in self.device_config]
self.non_ap_devices = [device for device in self.device_config.values()
if device['type'] != 'wifi_ap']
self.thread_devices = [device for device in self.device_config.values()
if device['capability'].get('Thread', None) is not None]
self.ap_devices = [device for device in self.device_config.values()
if device['type'] == 'wifi_ap']

Expand Down
60 changes: 46 additions & 14 deletions src/test_driver/linux-cirque/test-manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import os
import time
import sys
import json
from optparse import OptionParser, OptionValueError

from helper.CHIPTestBase import CHIPVirtualHome

Expand All @@ -30,20 +32,7 @@
# base_image: The image of the container.
# capability: A list of capability of the container, Thread+Interactive should fit in most cases.
# rcp_mode: This is used for Thread network setup, set it to True for CHIP.
DEVICE_CONFIG = {
'device0': {
'type': 'CHIP-Server',
'base_image': 'chip_server',
'capability': ['Thread', 'Interactive'],
'rcp_mode': True,
},
'device1': {
'type': 'CHIP-Tool',
'base_image': 'chip_tool',
'capability': ['Thread', 'Interactive'],
'rcp_mode': True,
}
}
DEVICE_CONFIG = {}

# Set this to True to set up a test thread network if you don't want to test network commissioning.
# Note: If you enable this, all devices MUST have Thread capability or the script may fail.
Expand All @@ -57,6 +46,7 @@
#############################################################

CIRQUE_URL = "http://localhost:5000"
CHIP_REPO = os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "..", "..")

logger = logging.getLogger('CHIPCirqueTest')
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -92,6 +82,48 @@ def wait_for_interrupt(self):
except KeyboardInterrupt:
self.logger.info("KeyboardInterrupt received, quit now")

def _parse_mount_dir(config):
for v in config.values():
if "Mount" not in v.get("capability", {}):
continue
_mount_pairs = v.get("mount_pairs", [])
for mount in _mount_pairs:
mount[0] = mount[0].format(chip_repo = CHIP_REPO)
mount[1] = mount[1].format(chip_repo = CHIP_REPO)
v["mount_pairs"] = _mount_pairs
return config

if __name__ == "__main__":
optParser = OptionParser()
optParser.add_option(
"-t",
"--topology",
action="store",
dest="topologyFile",
type='str',
default=None,
help="The topology to be set up by cirque framework.",
metavar="<timeout-second>",
)
optParser.add_option(
"--default-thread-network",
action="store_true",
dest="setupDefaultThreadNetwork",
default=False,
help="Setup default thread network to nodes that supports thread."
)

(options, remainingArgs) = optParser.parse_args(sys.argv[1:])

if not options.topologyFile:
raise Exception("Must specify a topology file!")

with open(options.topologyFile, "r") as fp:
config_operations = [_parse_mount_dir]
DEVICE_CONFIG = json.load(fp)
for op in config_operations:
DEVICE_CONFIG = op(DEVICE_CONFIG)

SETUP_TEST_THREAD_NETWORK = options.setupDefaultThreadNetwork

sys.exit(TestManually(DEVICE_CONFIG).run_test())
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"device0": {
"type": "CHIP-00",
"base_image": "connectedhomeip/chip-cirque-device-base",
"capability": [
"Thread",
"Interactive",
"Mount"
],
"mount_pairs": [
[
"{chip_repo}",
"{chip_repo}"
]
],
"rcp_mode": true
},
"device1": {
"type": "CHIP-01",
"base_image": "connectedhomeip/chip-cirque-device-base",
"capability": [
"Thread",
"Interactive",
"Mount"
],
"mount_pairs": [
[
"{chip_repo}",
"{chip_repo}"
]
],
"rcp_mode": true
},
"device2": {
"type": "CHIP-02",
"base_image": "connectedhomeip/chip-cirque-device-base",
"capability": [
"Thread",
"Interactive",
"Mount"
],
"mount_pairs": [
[
"{chip_repo}",
"{chip_repo}"
]
],
"rcp_mode": true
}
}
34 changes: 34 additions & 0 deletions src/test_driver/linux-cirque/topologies/two_node_with_thread.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"device0": {
"type": "CHIP-00",
"base_image": "connectedhomeip/chip-cirque-device-base",
"capability": [
"Thread",
"Interactive",
"Mount"
],
"mount_pairs": [
[
"{chip_repo}",
"{chip_repo}"
]
],
"rcp_mode": true
},
"device1": {
"type": "CHIP-01",
"base_image": "connectedhomeip/chip-cirque-device-base",
"capability": [
"Thread",
"Interactive",
"Mount"
],
"mount_pairs": [
[
"{chip_repo}",
"{chip_repo}"
]
],
"rcp_mode": true
}
}

0 comments on commit 61cbf25

Please sign in to comment.