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
+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')