aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--afm-test.cmake13
-rw-r--r--afm-test.native.sh141
-rwxr-xr-xafm-test.target.sh (renamed from afm-test)4
-rw-r--r--test/CMakeLists.txt4
-rwxr-xr-xtest/afb-test.sh43
6 files changed, 151 insertions, 56 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 37a35cc..e6c1ff0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -22,5 +22,3 @@ include(CTest)
enable_testing()
include(${CMAKE_CURRENT_SOURCE_DIR}/conf.d/cmake/config.cmake)
-
-INSTALL(PROGRAMS afm-test DESTINATION ${CMAKE_INSTALL_BINDIR})
diff --git a/afm-test.cmake b/afm-test.cmake
index 4162188..7a73f10 100644
--- a/afm-test.cmake
+++ b/afm-test.cmake
@@ -16,11 +16,10 @@
# limitations under the License.
###########################################################################
-#INSTALL(PROGRAMS afm-test DESTINATION ${CMAKE_INSTALL_BINDIR})
-PROJECT_TARGET_ADD(afm-test-script)
+if("${OSRELEASE}" STREQUAL "poky-agl" OR "${OSRELEASE}" STREQUAL "yocto-build")
+ set(AFM_TEST "afm-test.target.sh")
+else()
+ set(AFM_TEST "afm-test.native.sh")
+endif()
-add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/afm-test
- COMMAND install -m 775 ${CMAKE_CURRENT_SOURCE_DIR}/afm-test ${CMAKE_CURRENT_BINARY_DIR}/afm-test
-)
-
-add_custom_target(${TARGET_NAME} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/afm-test)
+install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/${AFM_TEST} DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME afm-test)
diff --git a/afm-test.native.sh b/afm-test.native.sh
new file mode 100644
index 0000000..e117ada
--- /dev/null
+++ b/afm-test.native.sh
@@ -0,0 +1,141 @@
+#!/bin/bash
+
+###########################################################################
+# Copyright (C) 2017, 2018 IoT.bzh
+#
+# Author: Romain Forlot <romain.forlot@iot.bzh>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+###########################################################################
+
+trap "cleanNexit 1" SIGHUP SIGINT SIGABRT SIGTERM
+cleanNexit() {
+ rm -f $SOCKETSERVICE 2> /dev/null
+ trap '' EXIT SIGHUP SIGINT SIGABRT SIGTERM
+ [ $1 -ne 0 ] && echo "Error: Test launch failed. Code: $1" && cat ${LOGFILETEST} ${LOGFILESERVICE}
+ exit $1
+}
+
+function usage() {
+ cat >&2 << EOF
+Usage: $0 <binding-wgt-rootdir> <test-wgt-rootdir> [mode] [timeout]
+binding-wgt-rootdir: path to the test wgt file
+test-wgt-rootdir: path to the test folder file
+mode: SOLO (1 binder) or SERVICE (2 binders)
+timeout: default 3 seconds
+EOF
+}
+
+BINDER=$(command -v afb-daemon)
+AFBTEST="$(pkg-config --variable libdir afb-test)/aft.so"
+PORT=1234
+PORTSERVICE=$((PORT+1))
+TOKEN=
+
+if [ "$1" ] && [ "$2" ]
+then
+ SERVICEPACKAGEDIR="$(readlink -f $1)"
+ TESTPACKAGEDIR="$(readlink -f $2)"
+else
+ echo "Error: you doesn't specified either the binding folder location either test widget folder location."
+ usage
+ cleanNexit 1
+fi
+
+if [ "$3" ]
+then
+ MODE="$3"
+else
+ MODE="SOLO"
+fi
+
+if [ "$4" ]
+then
+ TIMEOUT=$4
+else
+ TIMEOUT=3
+fi
+
+TESTCFGFILE=$(find "${TESTPACKAGEDIR}" -name "aft-*.json" -print | head -n1)
+TESTPROCNAME=$(grep '\"api\"' "${TESTCFGFILE}" | cut -d'"' -f4)
+
+API=$(grep "provided-api" "${SERVICEPACKAGEDIR}/config.xml" -A1 2> /dev/null | sed -r -e '1d' -e 's:.*"(.*)" v.*:\1:' 2> /dev/null)
+if [ -z "$API" ] && [ "$MODE" = "SERVICE" ]
+then
+ echo "Error: you doesn't have the config.xml file. Please call 'make widget'"
+ cleanNexit 2
+else
+ ENV_API=$(echo ${API} | sed 's:[^a-zA-Z0-9_]:_:g')
+ declare AFT_${ENV_API}_CONFIG_PATH="${SERVICEPACKAGEDIR}"
+ declare AFT_$(echo ${ENV_API} | sed 's:[^a-zA-Z0-9_]:_:g')_PLUGIN_PATH="${SERVICEPACKAGEDIR}"
+ export AFT_${ENV_API}_CONFIG_PATH
+ export AFT_${ENV_API}_PLUGIN_PATH
+ PROCNAME="afbd-${API}"
+ SOCKETSERVICE="/tmp/$API"
+fi
+
+export AFT_CONFIG_PATH="${TESTPACKAGEDIR}"
+export AFT_PLUGIN_PATH="${TESTPACKAGEDIR}"
+
+LOGFILESERVICE="test-service.log"
+LOGFILETEST="test.log"
+
+if [ ${MODE} = "SOLO" ]
+then
+ pkill "${TESTPROCNAME}"
+
+ timeout -s 9 ${TIMEOUT} \
+ ${BINDER} --name="${TESTPROCNAME}" \
+ --port="${PORT}" \
+ --roothttp=. \
+ --tracereq=common \
+ --token=${TOKEN} \
+ --workdir="${TESTPACKAGEDIR}" \
+ --ldpaths=${SERVICEPACKAGEDIR} \
+ --binding="${AFBTEST}" \
+ --call="${TESTPROCNAME}/launch_all_tests:{}" \
+ --call="${TESTPROCNAME}/exit:{}" \
+ -vvv &> ${LOGFILETEST}
+elif [ ${MODE} = "SERVICE" ]
+then
+ pkill "$TESTPROCNAME"
+ pkill "$PROCNAME"
+
+ timeout -s 9 ${TIMEOUT} ${BINDER} --name=${PROCNAME} \
+ --workdir="${SERVICEPACKAGEDIR}" \
+ --port=${PORTSERVICE} \
+ --ldpaths=. \
+ -vvv \
+ --ws-server=unix:${SOCKETSERVICE} &> ${LOGFILESERVICE} &
+
+ sleep 0.3
+
+ timeout -s 9 ${TIMEOUT} ${BINDER} --name="${TESTPROCNAME}" \
+ --port="${PORT}" \
+ --no-httpd \
+ --tracereq=common \
+ --token=${TOKEN} \
+ --workdir="${TESTPACKAGEDIR}" \
+ --binding="${AFBTEST}" \
+ --ws-client=unix:${SOCKETSERVICE} \
+ --call="${TESTPROCNAME}/launch_all_tests:{}" \
+ --call="${TESTPROCNAME}/exit:{}" \
+ -vvv &> ${LOGFILETEST}
+
+else
+ echo "Error: No mode selected. Choose between SOLO or SERVICE"
+ usage
+ cleanNexit 3
+fi
+
+cleanNexit $?
diff --git a/afm-test b/afm-test.target.sh
index 000ab4c..f24ca83 100755
--- a/afm-test
+++ b/afm-test.target.sh
@@ -34,11 +34,11 @@ EOF
}
function error() {
- echo "FAIL: $@" >&2
+ echo "FAIL: $*" >&2
cleanup
}
function info() {
- echo "PASS: $@" >&2
+ echo "PASS: $*" >&2
}
# check application name passed as first arg
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 94dca38..d75b1c9 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -22,6 +22,6 @@
PROJECT_SUBDIRS_ADD(${PROJECT_SRC_DIR_PATTERN})
ADD_TEST(NAME AFB-TEST_TESTS
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- COMMAND afb-test.sh "${CMAKE_BINARY_DIR}"
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ COMMAND afm-test "${CMAKE_BINARY_DIR}/package" "${CMAKE_BINARY_DIR}/package-test" SERVICE
)
diff --git a/test/afb-test.sh b/test/afb-test.sh
deleted file mode 100755
index cd722cc..0000000
--- a/test/afb-test.sh
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/sh
-
-trap "cleanup 1" SIGINT SIGTERM SIGABRT SIGHUP
-trap "cleanup 0" EXIT
-
-cleanup() {
- trap '' SIGINT SIGTERM SIGABRT SIGHUP EXIT
- kill $AFTESTPID > /dev/null 2>&1
- rm -f $AFTESTSOCKET
- pkill $PROCNAME
- exit $1
-}
-
-BINDER=$(command -v afb-daemon)
-PROCNAME="aft-aftest"
-PORT=1234
-TOKEN=
-AFTESTSOCKET=/tmp/afTest
-
-[ "$1" ] && BUILDDIR="$1" || exit 1
-
-pkill $PROCNAME
-
-${BINDER} --name=afbd-aftest \
---workdir="${BUILDDIR}/package" \
---binding=lib/aft.so \
---ws-server=unix:${AFTESTSOCKET} > /dev/null 2>&1 &
-AFTESTPID=$!
-
-sleep 0.3
-
-${BINDER} --name="${PROCNAME}" \
---port="${PORT}" \
---no-httpd \
---tracereq=common \
---token=${TOKEN} \
---workdir="${BUILDDIR}/package-test" \
---binding="${BUILDDIR}/package/lib/aft.so" \
---ws-client=unix:${AFTESTSOCKET} \
---call="aft-aftest/launch_all_tests:{}" \
---call="aft-aftest/exit:{}"
-
-find "${BUILDDIR}" -name test_results.log -exec cat {} \;