From 8d22fdd09cdce5c948ee576d32a2d22cc09e7205 Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Fri, 24 Jan 2020 11:45:51 +0800 Subject: [PATCH] [toranj] improve code coverage by using absolute path (#4491) Gcov sometimes cannot correctly find source files when the code is configured with relative path. This commit enables using absolute path to run toranj tests. --- .travis.yml | 4 ++-- .travis/script.sh | 2 +- tests/toranj/build.sh | 17 ++++++++++++++--- tests/toranj/start.sh | 3 +-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index b6e37dd55..52b05ecff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -182,11 +182,11 @@ jobs: os: linux compiler: gcc script: .travis/script.sh - - env: BUILD_TARGET="toranj-test-framework" VERBOSE=1 + - env: BUILD_TARGET="toranj-test-framework" COVERAGE=1 VERBOSE=1 os: linux compiler: gcc script: .travis/script.sh - - env: BUILD_TARGET="toranj-test-framework" VERBOSE=1 TORANJ_POSIX_APP_RCP_MODEL=1 + - env: BUILD_TARGET="toranj-test-framework" COVERAGE=1 VERBOSE=1 TORANJ_POSIX_APP_RCP_MODEL=1 os: linux compiler: gcc script: .travis/script.sh diff --git a/.travis/script.sh b/.travis/script.sh index 2f174675a..bd39ba243 100755 --- a/.travis/script.sh +++ b/.travis/script.sh @@ -637,7 +637,7 @@ build_samr21() { } [ $BUILD_TARGET != toranj-test-framework ] || { - ./tests/toranj/start.sh || die + top_builddir=$(pwd)/build/toranj ./tests/toranj/start.sh || die } [ $BUILD_TARGET != osx ] || { diff --git a/tests/toranj/build.sh b/tests/toranj/build.sh index 6c79e27db..f16fcc0ab 100755 --- a/tests/toranj/build.sh +++ b/tests/toranj/build.sh @@ -91,13 +91,22 @@ configure_options=" \ cppflags_config='-DOPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"../tests/toranj/openthread-core-toranj-config.h\"' +if [ -n "${top_builddir}" ]; then + top_srcdir=$(pwd) + mkdir -p "${top_builddir}" +else + top_srcdir=. + top_builddir=. +fi + case ${build_config} in ncp) echo "===================================================================================================" echo "Building OpenThread NCP FTD mode with POSIX platform" echo "===================================================================================================" ./bootstrap || die - ./configure \ + cd "${top_builddir}" + ${top_srcdir}/configure \ CPPFLAGS="$cppflags_config" \ --with-examples=posix \ $configure_options || die @@ -109,7 +118,8 @@ case ${build_config} in echo "Building OpenThread RCP (NCP in radio mode) with POSIX platform" echo "====================================================================================================" ./bootstrap || die - ./configure \ + cd "${top_builddir}" + ${top_srcdir}/configure \ CPPFLAGS="$cppflags_config" \ --enable-coverage=${coverage} \ --enable-ncp \ @@ -125,7 +135,8 @@ case ${build_config} in echo "Building OpenThread POSIX App NCP" echo "====================================================================================================" ./bootstrap || die - ./configure \ + cd "${top_builddir}" + ${top_srcdir}/configure \ CPPFLAGS="$cppflags_config -DOPENTHREAD_CONFIG_POSIX_APP_ENABLE_PTY_DEVICE=1 -DOPENTHREAD_POSIX_RCP_UART_ENABLE=1" \ --enable-posix-app \ $configure_options || die diff --git a/tests/toranj/start.sh b/tests/toranj/start.sh index 34de17bd2..39cbebd7f 100755 --- a/tests/toranj/start.sh +++ b/tests/toranj/start.sh @@ -77,8 +77,7 @@ run() { cd $(dirname $0) -# On Travis CI, the $BUILD_TARGET is defined as "toranj-test-framework". -if [ "$BUILD_TARGET" = "toranj-test-framework" ]; then +if [ "$COVERAGE" = 1 ]; then coverage_option="--enable-coverage" else coverage_option=""