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