From afb4d2e72aa6f44a3f90aa2efea2a26b2e1d129e Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Tue, 11 Sep 2018 08:40:23 +0800 Subject: [PATCH] [travis] add code coverage flag (#3037) --- .travis/script.sh | 20 +++++++++++--------- examples/platforms/posix/sim/platform-sim.c | 19 +++++++++++++++++-- src/posix/Makefile-posix | 5 +++++ src/posix/platform/radio_spinel.cpp | 2 +- tests/scripts/thread-cert/node_cli.py | 4 +--- tests/scripts/thread-cert/simulator.py | 2 +- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/.travis/script.sh b/.travis/script.sh index 62f0313bc..07cec8125 100755 --- a/.travis/script.sh +++ b/.travis/script.sh @@ -548,15 +548,16 @@ set -x [ $BUILD_TARGET != posix-app-cli ] || { ./bootstrap || die - VIRTUAL_TIME_UART=1 make -f examples/Makefile-posix || die - make -f src/posix/Makefile-posix || die - PYTHONUNBUFFERED=1 OT_CLI_PATH="$(pwd)/$(ls output/posix/*/bin/ot-cli)" RADIO_DEVICE="$(pwd)/$(ls output/*/bin/ot-ncp-radio)" COVERAGE=1 make -f src/posix/Makefile-posix check || die + # enable code coverage for OpenThread transceiver only + COVERAGE=1 VIRTUAL_TIME_UART=1 make -f examples/Makefile-posix || die + COVERAGE=1 make -f src/posix/Makefile-posix || die + COVERAGE=1 PYTHONUNBUFFERED=1 OT_CLI_PATH="$(pwd)/$(ls output/posix/*/bin/ot-cli)" RADIO_DEVICE="$(pwd)/$(ls output/*/bin/ot-ncp-radio)" make -f src/posix/Makefile-posix check || die } [ $BUILD_TARGET != posix-app-pty ] || { ./bootstrap - make -f examples/Makefile-posix - make -f src/posix/Makefile-posix + COVERAGE=1 make -f examples/Makefile-posix + COVERAGE=1 make -f src/posix/Makefile-posix SOCAT_OUTPUT=/tmp/ot-socat socat -d -d pty,raw,echo=0 pty,raw,echo=0 > /dev/null 2> $SOCAT_OUTPUT & @@ -611,14 +612,15 @@ EOF [ $BUILD_TARGET != posix-app-ncp ] || { ./bootstrap || die - VIRTUAL_TIME_UART=1 make -f examples/Makefile-posix || die - make -f src/posix/Makefile-posix || die - PYTHONUNBUFFERED=1 OT_NCP_PATH="$(pwd)/$(ls output/posix/*/bin/ot-ncp)" RADIO_DEVICE="$(pwd)/$(ls output/*/bin/ot-ncp-radio)" COVERAGE=1 NODE_TYPE=ncp-sim make -f src/posix/Makefile-posix check || die + COVERAGE=1 VIRTUAL_TIME_UART=1 make -f examples/Makefile-posix || die + # enable code coverage for OpenThread posix radio + COVERAGE=1 make -f src/posix/Makefile-posix || die + COVERAGE=1 PYTHONUNBUFFERED=1 OT_NCP_PATH="$(pwd)/$(ls output/posix/*/bin/ot-ncp)" RADIO_DEVICE="$(pwd)/$(ls output/*/bin/ot-ncp-radio)" NODE_TYPE=ncp-sim make -f src/posix/Makefile-posix check || die } [ $BUILD_TARGET != posix-ncp ] || { ./bootstrap || die - PYTHONUNBUFFERED=1 NODE_TYPE=ncp-sim make -f examples/Makefile-posix check || die + COVERAGE=1 PYTHONUNBUFFERED=1 NODE_TYPE=ncp-sim make -f examples/Makefile-posix check || die } [ $BUILD_TARGET != toranj-test-framework ] || { diff --git a/examples/platforms/posix/sim/platform-sim.c b/examples/platforms/posix/sim/platform-sim.c index bb9515fb4..58bfcf6f5 100644 --- a/examples/platforms/posix/sim/platform-sim.c +++ b/examples/platforms/posix/sim/platform-sim.c @@ -53,7 +53,8 @@ uint32_t NODE_ID = 1; uint32_t WELLKNOWN_NODE_ID = 34; -extern bool gPlatformPseudoResetWasRequested; +extern bool gPlatformPseudoResetWasRequested; +static volatile bool gTerminate = false; int gArgumentsCount = 0; char **gArguments = NULL; @@ -62,6 +63,12 @@ uint64_t sNow = 0; // microseconds int sSockFd; uint16_t sPortOffset; +static void handleSignal(int aSignal) +{ + (void)aSignal; + gTerminate = true; +} + void otSimSendEvent(const struct Event *aEvent) { ssize_t rval; @@ -236,6 +243,9 @@ void otSysInit(int argc, char *argv[]) platformAlarmInit(1); platformRadioInit(); platformRandomInit(); + + signal(SIGTERM, &handleSignal); + signal(SIGHUP, &handleSignal); } bool otSysPseudoResetWasRequested(void) @@ -256,6 +266,11 @@ void otSysProcessDrivers(otInstance *aInstance) int max_fd = -1; int rval; + if (gTerminate) + { + exit(0); + } + FD_ZERO(&read_fds); FD_ZERO(&write_fds); FD_ZERO(&error_fds); @@ -279,7 +294,7 @@ void otSysProcessDrivers(otInstance *aInstance) exit(EXIT_FAILURE); } - if (FD_ISSET(sSockFd, &read_fds)) + if (rval > 0 && FD_ISSET(sSockFd, &read_fds)) { receiveEvent(aInstance); } diff --git a/src/posix/Makefile-posix b/src/posix/Makefile-posix index b0405d50b..a543bf8d2 100644 --- a/src/posix/Makefile-posix +++ b/src/posix/Makefile-posix @@ -46,6 +46,7 @@ BuildJobs ?= 10 configure_OPTIONS = \ --enable-application-coap \ + --enable-border-agent \ --enable-border-router \ --enable-cert-log \ --enable-child-supervision \ @@ -67,6 +68,10 @@ configure_OPTIONS = \ --with-ncp-bus=uart \ $(NULL) +ifeq ($(COVERAGE),1) +configure_OPTIONS += --enable-coverage +endif + TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST))))../.. AbsTopSourceDir := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))../.. diff --git a/src/posix/platform/radio_spinel.cpp b/src/posix/platform/radio_spinel.cpp index f7e8e1f77..4428864af 100644 --- a/src/posix/platform/radio_spinel.cpp +++ b/src/posix/platform/radio_spinel.cpp @@ -272,7 +272,7 @@ static int OpenPty(const char *aFile, const char *aConfig) close(static_cast(i)); } - rval = snprintf(cmd, sizeof(cmd), "%s %s", aFile, aConfig); + rval = snprintf(cmd, sizeof(cmd), "exec %s %s", aFile, aConfig); VerifyOrExit(rval > 0 && static_cast(rval) < sizeof(cmd), otLogCritPlat(mInstance, "NCP file and configuration is too long!")); diff --git a/tests/scripts/thread-cert/node_cli.py b/tests/scripts/thread-cert/node_cli.py index b1e017cae..7dd18a32f 100644 --- a/tests/scripts/thread-cert/node_cli.py +++ b/tests/scripts/thread-cert/node_cli.py @@ -141,11 +141,9 @@ class otCli: if self.pexpect and self.pexpect.isalive(): print("%d: exit" % self.nodeid) self.pexpect.send('exit\n') + self.pexpect.expect(pexpect.EOF) self.pexpect.terminate() - self._expect(pexpect.EOF) - self.pexpect.wait() self.pexpect = None - sys.stdout.flush() def send_command(self, cmd, go=True): print("%d: %s" % (self.nodeid, cmd)) diff --git a/tests/scripts/thread-cert/simulator.py b/tests/scripts/thread-cert/simulator.py index f38ebcbc9..7cb5b8c1d 100644 --- a/tests/scripts/thread-cert/simulator.py +++ b/tests/scripts/thread-cert/simulator.py @@ -58,7 +58,7 @@ class RealTime: def get_messages_sent_by(self, nodeid): return self._sniffer.get_messages_sent_by(nodeid) - def go(self, duration): + def go(self, duration, nodeid=None): time.sleep(duration) def stop(self):