spinel-cli: Add NCP build to TravisCI (#364)

* ncp: Added spinel-cli and initial travis CI test suite integration.

This PR adds a command line tool, named spinel-cli, that converts ot-cli shell commands (as documented in https://github.com/openthread/openthread/blob/master/src/cli/README.md) to spinel NCP commands (as documented in https://github.com/openthread/openthread/blob/master/src/ncp/PROTOCOL.md).

Also added is a patch to node.py that provides a way to run the existing continuous integration certification test suite against an NCP build rather than a CLI build (by prefacing the command to start the test with the environment variable setting NODE_TYPE=ncp-sim):

cd tests/scripts/thread-cert
NODE_TYPE=ncp-sim top_builddir=../../.. python Cert_5_1_02_ChildAddressTimeout.py
The power of this tool is three fold:

1) As a path to add testing of the NCP in simulation to continuous integration
2) As a path to automated testing of testbeds running NCP firmware on hardware
3) As a simple debugging tool for NCP builds of OpenThread

openthread$ cd tools/spinel-cli/
spinel-cli$ ./spinel-cli.py
Opening pipe to ../../examples/apps/ncp/ot-ncp 1
spinel-cli > help

Available commands (type help <name> for more information):
============================================================
channel            extaddr       mode              route
child              extpanid      netdataregister   router
childtimeout       h             networkidtimeout  routerupgradethreshold
clear              help          networkname       scan
contextreusedelay  history       panid             state
counter            ifconfig      ping              thread
debug              ipaddr        prefix            v
debug-term         keysequence   q                 version
eidcache           leaderdata    quit              whitelist
enabled            leaderweight  releaserouterid
exit               masterkey     rloc16

spinel-cli > version
OPENTHREAD/gd4d4e9d-dirty; Aug 11 2016 14:40:44
Done
spinel-cli > thread start
Done
spinel-cli > state
leader
Done
spinel-cli >

The tool provides three ways to connect to an NCP image:

1) pipe to stdin/stdout of a command line tool (default): -p ./ot-ncp
2) serial connection to a hardware device: -u /dev/ttyUSB0
3) socket connection to the port of a helper tool such as ncp-spi-driver: -s 1234

spinel-cli$ ./spinel-cli.py --help
Options:
  -h, --help            show this help message and exit
  -u UART, --uart=UART
  -p PIPE, --pipe=PIPE
  -s SOCKET, --socket=SOCKET
  -n NODEID, --nodeid=NODEID
  -q, --quiet
  -v, --verbose
This commit is contained in:
Martin Turon
2016-09-02 15:32:17 -07:00
committed by Jonathan Hui
parent 69eb23cd0c
commit 73060ae8e1
13 changed files with 3471 additions and 8 deletions
+3
View File
@@ -47,6 +47,9 @@ matrix:
- env: BUILD_TARGET="posix-distcheck" DISTCHECK_CONFIGURE_FLAGS="--with-examples=posix --enable-cli --enable-ncp --with-tests=all" VERBOSE=1
compiler: gcc
os: linux
- env: NODE_TYPE=ncp-sim BUILD_TARGET="posix-distcheck" DISTCHECK_CONFIGURE_FLAGS="--with-examples=posix --enable-cli --enable-ncp=uart --with-tests=all" VERBOSE=1 BuildJobs=10
compiler: gcc
os: linux
- env: BUILD_TARGET="posix"
compiler: gcc
os: osx
+7
View File
@@ -55,6 +55,13 @@ cd /tmp || die
[ $BUILD_TARGET != posix-32-bit ] || {
sudo apt-get install g++-multilib || die
}
[ $NODE_TYPE != ncp-sim ] || {
sudo easy_install pip || die
sudo pip install blessed || die
sudo pip install ipaddress || die
sudo pip install scapy || die
}
}
[ $TRAVIS_OS_NAME != osx ] || {
+1
View File
@@ -641,6 +641,7 @@ tools/Makefile
tools/harness-automation/Makefile
tools/harness-thci/Makefile
tools/spi-hdlc-adapter/Makefile
tools/spinel-cli/Makefile
tests/Makefile
tests/scripts/Makefile
tests/unit/Makefile
+20
View File
@@ -231,6 +231,26 @@ TESTS = \
$(check_SCRIPTS) \
$(NULL)
XFAIL_NCP_TESTS = \
thread-cert/Cert_5_3_07_DuplicateAddress.py \
thread-cert/Cert_5_6_01_NetworkDataRegisterBeforeAttachLeader.py \
thread-cert/Cert_5_6_02_NetworkDataRegisterBeforeAttachRouter.py \
thread-cert/Cert_5_6_03_NetworkDataRegisterAfterAttachLeader.py \
thread-cert/Cert_5_6_04_NetworkDataRegisterAfterAttachRouter.py \
thread-cert/Cert_5_6_05_NetworkDataRegisterAfterAttachRouter.py \
thread-cert/Cert_5_6_06_NetworkDataExpiration.py \
thread-cert/Cert_5_6_07_NetworkDataRequestREED.py \
thread-cert/Cert_5_6_08_ContextManagement.py \
thread-cert/Cert_6_3_02_NetworkDataUpdate.py \
thread-cert/Cert_7_1_01_BorderRouterAsLeader.py \
thread-cert/Cert_7_1_02_BorderRouterAsRouter.py \
thread-cert/Cert_7_1_03_BorderRouterAsLeader.py \
thread-cert/Cert_7_1_04_BorderRouterAsRouter.py \
thread-cert/Cert_7_1_05_BorderRouterAsRouter.py \
$(NULL)
XFAIL_TESTS = $(if $(filter $(NODE_TYPE),ncp-sim),$(XFAIL_NCP_TESTS))
endif # OPENTHREAD_BUILD_TESTS
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
@@ -99,7 +99,7 @@ class Cert_5_1_02_ChildAddressTimeout(unittest.TestCase):
if addr[0:4] != 'fe80':
try:
self.nodes[LEADER].ping(addr)
self.assertFalse()
self.fail()
except pexpect.TIMEOUT:
pass
@@ -109,7 +109,7 @@ class Cert_5_1_02_ChildAddressTimeout(unittest.TestCase):
if addr[0:4] != 'fe80':
try:
self.nodes[LEADER].ping(addr)
self.assertFalse()
self.fail()
except pexpect.TIMEOUT:
pass
@@ -138,7 +138,7 @@ class Cert_5_3_3_AddressQuery(unittest.TestCase):
if addr[0:4] != 'fe80':
try:
self.nodes[ED2].ping(addr)
self.assertFalse()
self.fail()
except pexpect.TIMEOUT:
pass
@@ -149,7 +149,7 @@ class Cert_5_3_3_AddressQuery(unittest.TestCase):
if addr[0:4] != 'fe80':
try:
self.nodes[BR].ping(addr)
self.assertFalse()
self.fail()
except pexpect.TIMEOUT:
pass
@@ -117,6 +117,9 @@ class Cert_5_3_7_DuplicateAddress(unittest.TestCase):
self.nodes[ED2].add_ipaddr('2001::1')
time.sleep(3)
# Harness assumes nodes will autoconfigure addresses on all prefixes,
# but manually configuring for now until spinel-cli does this.
self.nodes[ED3].add_ipaddr('2001::3')
self.nodes[ED3].ping('2001::1')
if __name__ == '__main__':
@@ -128,7 +128,7 @@ class Cert_5_3_9_AddressQuery(unittest.TestCase):
if addr[0:4] != 'fe80':
try:
self.nodes[SED2].ping(addr)
self.assertFalse()
self.fail()
except pexpect.TIMEOUT:
pass
@@ -140,7 +140,7 @@ class Cert_5_3_9_AddressQuery(unittest.TestCase):
if addr[0:4] != 'fe80':
try:
self.nodes[BR].ping(addr)
self.assertFalse()
self.fail()
except pexpect.TIMEOUT:
pass
+30 -2
View File
@@ -41,6 +41,8 @@ class Node:
if self.node_type == 'soc':
self.__init_soc(nodeid)
elif self.node_type == 'ncp-sim':
self.__init_ncp_sim(nodeid)
else:
self.__init_sim(nodeid)
@@ -68,6 +70,26 @@ class Node:
# Add delay to ensure that the process is ready to receive commands.
time.sleep(0.1)
def __init_ncp_sim(self, nodeid):
""" Initialize an NCP simulation node. """
if "top_builddir" in os.environ.keys():
builddir = os.environ['top_builddir']
if "top_srcdir" in os.environ.keys():
srcdir = os.environ['top_srcdir']
else:
srcdir = os.path.dirname(os.path.realpath(__file__))
srcdir += "/../../.."
cmd = 'python %s/tools/spinel-cli/spinel-cli.py -p %s/examples/apps/ncp/ot-ncp -n' % (srcdir, builddir)
else:
cmd = './ot-ncp'
cmd += ' %d' % nodeid
print ("%s" % cmd)
self.pexpect = pexpect.spawn(cmd, timeout=2)
time.sleep(0.1)
self.pexpect.expect('spinel-cli >')
def __init_soc(self, nodeid):
""" Initialize a System-on-a-chip node connected via UART. """
import fdpexpect
@@ -75,8 +97,11 @@ class Node:
self.pexpect = fdpexpect.fdspawn(os.open(serialPort, os.O_RDWR|os.O_NONBLOCK|os.O_NOCTTY))
def __del__(self):
self.pexpect.terminate()
self.pexpect.close(force=True)
if self.pexpect.isalive():
if self.node_type == 'ncp-sim':
self.pexpect.sendcontrol('c');
self.pexpect.terminate()
self.pexpect.close(force=True)
def send_command(self, cmd):
print ("%d: %s" % (self.nodeid, cmd))
@@ -99,6 +124,9 @@ class Node:
self.send_command(cmd)
self.pexpect.expect('Done')
def debug(self, level):
self.send_command('debug '+str(level))
def start(self):
self.send_command('ifconfig up')
self.pexpect.expect('Done')
+1
View File
@@ -34,6 +34,7 @@ DIST_SUBDIRS = \
harness-automation \
harness-thci \
spi-hdlc-adapter \
spinel-cli \
$(NULL)
# Always build (e.g. for 'make all') these subdirectories.
+35
View File
@@ -0,0 +1,35 @@
#
# Copyright (c) 2016, Nest Labs, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
EXTRA_DIST = \
spinel-cli.py \
$(NULL)
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
+365
View File
@@ -0,0 +1,365 @@
# Spinel CLI Reference
The Spinel CLI exposes the OpenThread configuration and management APIs
running on an NCP build via a command line interface. Spinel CLI is primarily
targeted for driving the automated continuous integration tests, and is
suitable for manual experimentation with controlling OpenThread NCP instances.
For a production grade host driver, see [wpantund]: https://github.com/openthread/wpantund.
Use the CLI to play with NCP builds of OpenThread on a Linux or Mac OS
platform, including starting a basic tunnel interface to allow IPv6
applications to run on the HOST and use the Thread network.
The power of this tool is three fold:
1. As a path to add testing of the NCP in simulation to continuous integration
2. As a path to automated testing of testbeds running NCP firmware on hardware
3. As a simple debugging tool for NCP builds of OpenThread
## System Requirements
| OS | Minimum Version |
|--------|------------------|
| Ubuntu | 14.04 Trusty |
| Mac OS | 10.11 El Capitan |
| Language | Minimum Version |
|----------|------------------|
| Python | 2.7.10 |
### Package Installation
```
sudo easy_install pip
sudo pip install blessed
sudo pip install ipaddress
sudo pip install scapy
```
## Usage
### NAME
spinel-cli.py - shell tool for controlling OpenThread NCP instances
### SYNOPSIS
spinel-cli.py [-hupsnqv]
### DESCRIPTION
```
-h, --help
Show this help message and exit
-u <UART>, --uart=<UART>
Open a serial connection to the OpenThread NCP device
where <UART> is a device path such as "/dev/ttyUSB0".
-p <PIPE>, --pipe=<PIPE>
Open a piped process connection to the OpenThread NCP device
where <PIPE> is the command to start an emulator, such as
"ot-ncp". Spinel-cli will communicate with the child process
via stdin/stdout.
-s <SOCKET>, --socket=<SOCKET>
Open a socket connection to the OpenThread NCP device
where <SOCKET> is the port to open.
This is useful for SPI configurations when used in conjunction
with a spinel spi-driver daemon.
Note: <SOCKET> will eventually map to hostname:port tuple.
-n NODEID, --nodeid=NODEID
The unique nodeid for the HOST and NCP instance.
-q, --quiet
Minimize debug and log output.
-v, --verbose
Maximize debug and log output.
```
## Quick Start
The spinel-cli tool provides an intuitive command line interface, including
all the standard OpenThread CLI commands, plus full history accessible by
pressing the up/down keys, or searchable via ^R. There are a few commands
that spinel-cli provides as well that aren't part of the standard set
documented in the command reference section.
```
openthread$ cd tools/spinel-cli/
spinel-cli$ ./spinel-cli.py
Opening pipe to ../../examples/apps/ncp/ot-ncp 1
spinel-cli > help
Available commands (type help <name> for more information):
============================================================
channel extaddr mode route
child extpanid netdataregister router
childtimeout h networkidtimeout routerupgradethreshold
clear help networkname scan
contextreusedelay history panid state
counter ifconfig ping thread
debug ipaddr prefix v
debug-term keysequence q version
eidcache leaderdata quit whitelist
enabled leaderweight releaserouterid
exit masterkey rloc16
spinel-cli > version
OPENTHREAD/gd4d4e9d-dirty; Aug 11 2016 14:40:44
Done
spinel-cli > thread start
Done
spinel-cli > state
leader
Done
spinel-cli >
```
## Running the NCP Tests
The OpenThread automated test suite can be run against any of the following
node types by passing the NODE_TYPE environment variable:
| NODE_TYPE | Description |
|---------------|----------------------------------------------------|
| sim (default) | Runs against ot-cli posix emulator |
| ncp-sim | Runs against ot-ncp posix emulator with spinel-cli |
| soc | Runs against CLI firmware on a device connected via /dev/ttyUSB<nodeid> |
### Manual run of NCP thread-cert test
```
# From top-level of openthread tree
./bootstrap
./configure --with-examples=posix --enable-cli --enable-ncp=uart
make
cd tests/scripts/thread-cert
NODE_TYPE=ncp-sim top_builddir=../../.. python Cert_5_1_02_ChildAddressTimeout.py VERBOSE=1
```
### Run entire NCP thread-cert suite
```
# From top-level of openthread tree
make distclean
./bootstrap
NODE_TYPE=ncp-sim BUILD_TARGET=posix-distcheck DISTCHECK_CONFIGURE_FLAGS="--with-examples=posix --enable-cli --enable-ncp=uart --with-tests=all" make -f examples/Makefile-posix distcheck BuildJobs=10 VERBOSE=1
```
## Command Reference
### OpenThread CLI Commands
The primary intent of spinel-cli is to support the exact syntax and output
of the OpenThread CLI command set in order to seamlessly reapply the
thread-cert automated test suite against NCP targets.
See [cli module][1] for more information on these commands.
[1]:../../src/cli/README.md
### Diagnostics CLI Commands
The Diagnostics module is enabled only when building OpenThread with
the --enable-diag configure option.
See [diag module][2] for more information on these commands.
[2]:../../src/diag/README.md
### NCP CLI Commands
These commands extend beyond the core OpenThread CLI, and are specific to
the spinel-cli tool for the purposes of debugging, access to NCP-specific
Spinel parameters, and support of advanced configurations.
* [help](#help)
* [?](#help)
* [v](#v)
* [exit](#exit)
* [quit](#quit)
* [q](#quit)
* [clear](#clear)
* [history](#history)
* [h](#history)
* [debug](#debug)
* [debug-term](#debug-term)
* [ncp-tun](#ncp-tun)
* [ncp-ml64](#ncp-ml64)
* [ncp-ll64](#ncp-ll64)
#### help
Display help all top-level commands supported by spinel-cli.
```bash
spinel-cli > help
Available commands (type help <name> for more information):
============================================================
channel diag-start leaderdata quit
child diag-stats leaderweight releaserouterid
childtimeout diag-stop masterkey rloc16
clear discover mode route
contextreusedelay eidcache ncp-ll64 router
counter exit ncp-ml64 routerupgradethreshold
debug extaddr ncp-tun scan
debug-term extpanid netdataregister state
diag h networkidtimeout thread
diag-channel help networkname tun
diag-power history panid v
diag-repeat ifconfig ping version
diag-send ipaddr prefix whitelist
diag-sleep keysequence q
```
#### help \<command\>
Display detailed help on a specific command.
```bash
spinel-cli > help version
version
Print the build version information.
> version
OPENTHREAD/gf4f2f04; Jul 1 2016 17:00:09
Done
```
#### v
Display version of spinel-cli tool.
```bash
spinel-cli > v
spinel-cli ver. 0.1.0
Copyright (c) 2016 Nest Labs, Inc.
```
#### exit
Exit spinel-cli. CTRL+C is also okay.
#### quit
Exit spinel-cli. CTRL+C is also okay.
### clear
Clear screen.
#### history
Display history of most recent commands run.
```bash
spinel-cli > history
ping fd00::1
quit
help
history
```
#### debug
Get whether debug verbose output is enabled.
```bash
spinel-cli > debug
DEBUG_ENABLE = 0
```
#### debug \<enabled\>
Set whether debug verbose output is enabled.
spinel-cli > debug
DEBUG_ENABLE = 0
```bash
spinel-cli > debug 1
DEBUG_ENABLE = 1
spinel-cli > version
TX Pay: (3) ['81', '02', '02']
RX Pay: (53) ['81', '06', '02', '4F', '50', '45', '4E', '54', '48', '52', '45', '41', '44', '2F', '67', '38', '62', '63', '34', '62', '31', '64', '2D', '64', '69', '72', '74', '79', '3B', '20', '41', '75', '67', '20', '33', '31', '20', '32', '30', '31', '36', '20', '31', '30', '3A', '34', '38', '3A', '35', '33', '00', '40', '33']
OPENTHREAD/g8bc4b1d-dirty; Aug 31 2016 10:48:53
Done
```
#### debug-term
Get whether debug terminal title bar is enabled.
#### debug-term \<enabled\>
Set whether debug terminal title bar is enabled.
#### ncp-tun
Control sideband tunnel interface.
#### ncp-tun up
Bring up Thread TUN interface.
```bash
spinel-cli > ncp-tun up
Done
```
#### ncp-tun down
Bring down Thread TUN interface.
```bash
spinel-cli > ncp-tun down
Done
```
#### ncp-tun add \<ipaddr\>
Add an IPv6 address to the Thread TUN interface.
```bash
spinel-cli > ncp-tun add 2001::dead:beef:cafe
Done
```
#### ncp-tun del \<ipaddr\>
Delete an IPv6 address from the Thread TUN interface.
```bash
spinel-cli > ncp-tun del 2001::dead:beef:cafe
Done
```
#### ncp-tun ping \<ipaddr\> \[size\] \[count\] \[interval\]
Send an ICMPv6 Echo Request via a posix host system call.
```bash
spinel-cli > ncp-tun ping fdde:ad00:beef:0:558:f56b:d688:799
16 bytes from fdde:ad00:beef:0:558:f56b:d688:799: icmp_seq=1 hlim=64 time=28ms
```
#### ncp-ml64
Return the Mesh Local 64-bit IPv6 address for the node.
```
spinel-cli > ncp-ml64
fdde:ad00:beef:0:558:f56b:d688:799
Done
```
#### ncp-ll64
Return the Link Local 64-bit IPv6 address for the node.
+3000
View File
File diff suppressed because it is too large Load Diff