diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2018-07-31 15:41:41 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2018-10-15 18:22:48 +0200 |
commit | 6b119a365b6c04279104f123456ed841b2ce987f (patch) | |
tree | edcb2ecc1d4ce256455d34ec431aac39de6485ea | |
parent | 48d3aa53006303379e455e8c56f7f1670e06270f (diff) |
Create a test widget
Create a test widget in addition of the normal one when you use
any build type except of RELEASE. This widget will only
provide the test files (configuration + test + fixtures ...).
It joins the test framework binding to your binding or app then
you only have to access to your defined test API and launch the
tests.
The entry point is a bash script which is in charge to launch all
tests it finds.
Change-Id: I8f4a670f17fd4e4319c53a861074fb5e10b63aad
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r-- | cmake/cmake.d/03-macros.cmake | 76 | ||||
-rw-r--r-- | docs/dev_guide/1_Quickstart.md | 14 | ||||
-rw-r--r-- | docs/dev_guide/3_advanced_usage.md | 37 | ||||
-rw-r--r-- | samples.d/config.cmake.sample | 1 | ||||
-rw-r--r-- | test-widget/launcher.sh.in | 60 | ||||
-rw-r--r-- | test-widget/test-config.xml.in | 25 |
6 files changed, 188 insertions, 25 deletions
diff --git a/cmake/cmake.d/03-macros.cmake b/cmake/cmake.d/03-macros.cmake index e8a95d7..835f7be 100644 --- a/cmake/cmake.d/03-macros.cmake +++ b/cmake/cmake.d/03-macros.cmake @@ -291,10 +291,24 @@ macro(project_targets_populate) set(PACKAGE_LIBDIR ${PROJECT_PKG_BUILD_DIR}/${LIBDIR}) set(PACKAGE_HTTPDIR ${PROJECT_PKG_BUILD_DIR}/${HTTPDIR}) set(PACKAGE_DATADIR ${PROJECT_PKG_BUILD_DIR}/${DATADIR}) + # Default test Widget default directory + string(REGEX REPLACE "/([^/]*)$" "/\\1-test" PROJECT_PKG_TEST_DIR "${PROJECT_PKG_BUILD_DIR}") + set(PACKAGE_TEST_BINDIR ${PROJECT_PKG_TEST_DIR}/${BINDIR}) + set(PACKAGE_TEST_ETCDIR ${PROJECT_PKG_TEST_DIR}/${ETCDIR}) + set(PACKAGE_TEST_LIBDIR ${PROJECT_PKG_TEST_DIR}/${LIBDIR}) + set(PACKAGE_TEST_HTTPDIR ${PROJECT_PKG_TEST_DIR}/${HTTPDIR}) + set(PACKAGE_TEST_DATADIR ${PROJECT_PKG_TEST_DIR}/${DATADIR}) - add_custom_command(OUTPUT ${PACKAGE_BINDIR} ${PACKAGE_ETCDIR} ${PACKAGE_LIBDIR} ${PACKAGE_HTTPDIR} ${PACKAGE_DATADIR} - COMMAND mkdir -p ${PACKAGE_BINDIR} ${PACKAGE_ETCDIR} ${PACKAGE_LIBDIR} ${PACKAGE_HTTPDIR} ${PACKAGE_DATADIR}) - add_custom_target(populate DEPENDS ${PACKAGE_BINDIR} ${PACKAGE_ETCDIR} ${PACKAGE_LIBDIR} ${PACKAGE_HTTPDIR} ${PACKAGE_DATADIR}) + if(NOT ${CMAKE_BUILD_TYPE} STREQUAL "RELEASE") + add_custom_command(OUTPUT ${PACKAGE_BINDIR} ${PACKAGE_ETCDIR} ${PACKAGE_LIBDIR} ${PACKAGE_HTTPDIR} ${PACKAGE_DATADIR} ${PACKAGE_TEST_BINDIR} ${PACKAGE_TEST_ETCDIR} ${PACKAGE_TEST_LIBDIR} ${PACKAGE_TEST_HTTPDIR} ${PACKAGE_TEST_DATADIR} + COMMAND mkdir -p ${PACKAGE_BINDIR} ${PACKAGE_ETCDIR} ${PACKAGE_LIBDIR} ${PACKAGE_HTTPDIR} ${PACKAGE_DATADIR} + COMMAND mkdir -p ${PACKAGE_TEST_BINDIR} ${PACKAGE_TEST_ETCDIR} ${PACKAGE_TEST_LIBDIR} ${PACKAGE_TEST_HTTPDIR} ${PACKAGE_TEST_DATADIR}) + add_custom_target(populate DEPENDS ${PACKAGE_BINDIR} ${PACKAGE_ETCDIR} ${PACKAGE_LIBDIR} ${PACKAGE_HTTPDIR} ${PACKAGE_DATADIR} ${PACKAGE_TEST_BINDIR} ${PACKAGE_TEST_ETCDIR} ${PACKAGE_TEST_LIBDIR} ${PACKAGE_TEST_HTTPDIR} ${PACKAGE_TEST_DATADIR}) + else() + add_custom_command(OUTPUT ${PACKAGE_BINDIR} ${PACKAGE_ETCDIR} ${PACKAGE_LIBDIR} ${PACKAGE_HTTPDIR} ${PACKAGE_DATADIR} + COMMAND mkdir -p ${PACKAGE_BINDIR} ${PACKAGE_ETCDIR} ${PACKAGE_LIBDIR} ${PACKAGE_HTTPDIR} ${PACKAGE_DATADIR}) + add_custom_target(populate DEPENDS ${PACKAGE_BINDIR} ${PACKAGE_ETCDIR} ${PACKAGE_LIBDIR} ${PACKAGE_HTTPDIR} ${PACKAGE_DATADIR}) + endif() # Dirty trick to define a default INSTALL command for app-templates handled # targets @@ -369,10 +383,14 @@ macro(project_targets_populate) endif() elseif(${T} STREQUAL "HTDOCS") generate_one_populate_target(${P}${OUT} ${PACKAGE_HTTPDIR}) - elseif(${T} STREQUAL "DATA") + elseif(${T} STREQUAL "DATA" ) generate_one_populate_target(${TARGET} ${PACKAGE_DATADIR}) - elseif(${T} STREQUAL "BINDING-CONFIG") + elseif(${T} STREQUAL "BINDING-CONFIG" ) generate_one_populate_target(${TARGET} ${PACKAGE_ETCDIR}) + elseif(NOT ${CMAKE_BUILD_TYPE} STREQUAL "RELEASE" AND ${T} STREQUAL "TEST-DATA") + generate_one_populate_target(${TARGET} ${PACKAGE_TEST_DATADIR}) + elseif(NOT ${CMAKE_BUILD_TYPE} STREQUAL "RELEASE" AND ${T} STREQUAL "TEST-CONFIG") + generate_one_populate_target(${TARGET} ${PACKAGE_TEST_ETCDIR}) endif() elseif(${CMAKE_BUILD_TYPE} MATCHES "[Dd][Ee][Bb][Uu][Gg]") MESSAGE("${Yellow}.. Warning: ${TARGET} ignored when packaging.${ColourReset}") @@ -460,19 +478,24 @@ macro(wgt_package_build) set(WIDGET_ENTRY_POINT lib) endif() + add_custom_command(OUTPUT ${PROJECT_PKG_BUILD_DIR}/config.xml + COMMAND ${CMAKE_COMMAND} -DINFILE=${WIDGET_CONFIG_TEMPLATE} -DOUTFILE=${PROJECT_PKG_BUILD_DIR}/config.xml -DPROJECT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/cmake/configure_file.cmake + COMMAND cp ${ICON_PATH} ${PROJECT_PKG_BUILD_DIR}/${PROJECT_ICON} + ) + add_custom_command(OUTPUT ${PROJECT_PKG_TEST_DIR}/test-config.xml ${PROJECT_PKG_TEST_DIR}/bin/launcher + COMMAND ${CMAKE_COMMAND} -DINFILE=${CMAKE_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/test-widget/test-config.xml.in -DOUTFILE=${PROJECT_PKG_TEST_DIR}/config.xml -DPROJECT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/cmake/configure_file.cmake + COMMAND cp ${ICON_PATH} ${PROJECT_PKG_TEST_DIR}/${PROJECT_ICON} + COMMAND cp ${CMAKE_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}//test-widget/launcher.sh.in ${PROJECT_PKG_TEST_DIR}/bin/launcher + ) + if(NOT ${CMAKE_BUILD_TYPE} STREQUAL "RELEASE") string(TOLOWER "${PROJECT_NAME}-${CMAKE_BUILD_TYPE}" WGT_NAME) + add_custom_target(packaging_wgt DEPENDS ${PROJECT_PKG_BUILD_DIR}/config.xml ${PROJECT_PKG_TEST_DIR}/test-config.xml ${PROJECT_PKG_TEST_DIR}/bin/launcher) else() string(TOLOWER "${PROJECT_NAME}" WGT_NAME) + add_custom_target(packaging_wgt DEPENDS ${PROJECT_PKG_BUILD_DIR}/config.xml) endif() - add_custom_command(OUTPUT ${PROJECT_PKG_BUILD_DIR}/config.xml - COMMAND ${CMAKE_COMMAND} -DINFILE=${WIDGET_CONFIG_TEMPLATE} -DOUTFILE=${PROJECT_PKG_BUILD_DIR}/config.xml -DPROJECT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/cmake/configure_file.cmake - COMMAND cp ${ICON_PATH} ${PROJECT_PKG_BUILD_DIR}/${PROJECT_ICON} - - ) - add_custom_target(packaging_wgt DEPENDS ${PROJECT_PKG_BUILD_DIR}/config.xml) - # Fulup ??? copy any extra file in wgt/etc into populate package before building the widget file(GLOB PROJECT_CONF_FILES "${TEMPLATE_DIR}/etc/*") if(${PROJECT_CONF_FILES}) @@ -482,10 +505,12 @@ macro(wgt_package_build) find_program(wgtpkgCMD "wgtpkg-pack") if(wgtpkgCMD) set(packCMD ${wgtpkgCMD} "-f" "-o" "${WGT_NAME}.wgt" ${PROJECT_PKG_BUILD_DIR}) + set(packCMDTest ${wgtpkgCMD} "-f" "-o" "${WGT_NAME}-test.wgt" ${PROJECT_PKG_TEST_DIR}) else() find_program(wgtpkgCMD "zip") if(wgtpkgCMD) set(packCMD ${CMAKE_COMMAND} -E cmake_echo_color --yellow "Warning: Widget will be built using Zip, NOT using the Application Framework widget pack command." && cd ${PROJECT_PKG_BUILD_DIR} && ${wgtpkgCMD} "../${WGT_NAME}.wgt" "*") + set(packCMDTest ${CMAKE_COMMAND} -E cmake_echo_color --yellow "Warning: Test widget will be built using Zip, NOT using the Application Framework widget pack command." && cd ${PROJECT_PKG_TEST_DIR} && ${wgtpkgCMD} "../${WGT_NAME}-test.wgt" "*") else() set(packCMD ${CMAKE_COMMAND} -E cmake_echo_color --red "Error: No utility found to build a widget. Either install wgtpkg-pack from App Framework or zip command") endif() @@ -496,7 +521,18 @@ macro(wgt_package_build) COMMAND ${packCMD} ) - add_custom_target(widget DEPENDS ${WGT_NAME}.wgt) + add_custom_command(OUTPUT ${WGT_NAME}-test.wgt + DEPENDS ${PROJECT_TARGETS} + COMMAND ${packCMDTest} + ) + + if(NOT ${CMAKE_BUILD_TYPE} STREQUAL "RELEASE") + add_custom_target(widget DEPENDS ${WGT_NAME}.wgt ${WGT_NAME}-test.wgt) + set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/${WGT_NAME}-test.wgt") + else() + add_custom_target(widget DEPENDS ${WGT_NAME}.wgt) + endif() + add_dependencies(widget populate packaging_wgt) set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/${WGT_NAME}.wgt") @@ -507,13 +543,13 @@ macro(wgt_package_build) COMMAND exit -1 ) else() - configure_files_in_dir(${TEMPLATE_DIR}) - add_custom_target(widget-target-install - DEPENDS widget - COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/target/install-wgt-on-${RSYNC_TARGET}.sh - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/target/install-wgt-on-${RSYNC_TARGET}.sh - ) -endif() + configure_files_in_dir(${TEMPLATE_DIR}) + add_custom_target(widget-target-install + DEPENDS widget + COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/target/install-wgt-on-${RSYNC_TARGET}.sh + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/target/install-wgt-on-${RSYNC_TARGET}.sh + ) + endif() if(PACKAGE_MESSAGE) add_custom_command(TARGET widget diff --git a/docs/dev_guide/1_Quickstart.md b/docs/dev_guide/1_Quickstart.md index 1df38c1..e910178 100644 --- a/docs/dev_guide/1_Quickstart.md +++ b/docs/dev_guide/1_Quickstart.md @@ -59,8 +59,15 @@ Choose between: *${OUTPUT_NAME}-apidef* of the target that describe the API with OpenAPI syntax (e.g: *mybinding-apidef*). Or Alternatively, you can choose the name, without the extension, using macro - **set_openapi_filename**. If you use C++, you have to set - **PROJECT_LANGUAGES** with *CXX*. + **set_openapi_filename**. If you use C++, you have to set **PROJECT_LANGUAGES** + with *CXX*. +- **BINDINGV3**: Shared library that be loaded by the AGL Application Framework + This has to be accompagnied with a JSON file named like the + *${OUTPUT_NAME}-apidef* of the target that describe the API with OpenAPI + syntax (e.g: *mybinding-apidef*). + Or Alternatively, you can choose the name, without the extension, using macro + **set_openapi_filename**. If you use C++, you have to set **PROJECT_LANGUAGES** + with *CXX*. - **PLUGIN**: Shared library meant to be used as a binding plugin. Binding would load it as a plugin to extend its functionnalities. It should be named with a special extension that you choose with SUFFIX cmake target property or @@ -73,6 +80,7 @@ Choose between: Application Framework - **LIBRARY**: An external 3rd party library bundled with the binding for its own purpose because platform doesn't provide it. +- **BINDING-CONFIG**: Any files used as configuration by your binding. > **TIP** you should use the prefix _afb-_ with your **BINDING* targets which > stand for **Application Framework Binding**. @@ -80,7 +88,7 @@ Choose between: ```cmake SET_TARGET_PROPERTIES(${TARGET_NAME} PREFIX "afb-" - LABELS "BINDINGV2" + LABELS "BINDINGV3" OUTPUT_NAME "file_output_name") ``` diff --git a/docs/dev_guide/3_advanced_usage.md b/docs/dev_guide/3_advanced_usage.md index 2ee78ce..114230f 100644 --- a/docs/dev_guide/3_advanced_usage.md +++ b/docs/dev_guide/3_advanced_usage.md @@ -35,8 +35,15 @@ Choose between: *${OUTPUT_NAME}-apidef* of the target that describe the API with OpenAPI syntax (e.g: *mybinding-apidef*). Or Alternatively, you can choose the name, without the extension, using macro - **set_openapi_filename**. If you use C++, you have to set - **PROJECT_LANGUAGES** with *CXX*. + **set_openapi_filename**. If you use C++, you have to set **PROJECT_LANGUAGES** + with *CXX*. +- **BINDINGV3**: Shared library that be loaded by the AGL Application Framework + This has to be accompagnied with a JSON file named like the + *${OUTPUT_NAME}-apidef* of the target that describe the API with OpenAPI + syntax (e.g: *mybinding-apidef*). + Or Alternatively, you can choose the name, without the extension, using macro + **set_openapi_filename**. If you use C++, you have to set **PROJECT_LANGUAGES** + with *CXX*. - **PLUGIN**: Shared library meant to be used as a binding plugin. Binding would load it as a plugin to extend its functionnalities. It should be named with a special extension that you choose with SUFFIX cmake target property or @@ -49,6 +56,32 @@ Choose between: Application Framework - **LIBRARY**: An external 3rd party library bundled with the binding for its own purpose because platform doesn't provide it. +- **BINDING-CONFIG**: Any files used as configuration by your binding. + +Two optionnals **LABELS** are available to define which resources are your tests +materials: + +- **TEST-CONFIG**: JSON configuration files that will be used by the afb-test + binding to know how to execute tests. +- **TEST-DATA**: Resources used to test your binding. It is at least your test + plan and also could be fixtures and any needed files by your tests. These files + will appear in a separate test widget. + +Here is a mapping between LABELS and directories where files will be puted in +the widget: + +- **EXECUTABLE** : \<wgtrootdir\>/bin +- **BINDING-CONFIG** : \<wgtrootdir\>/etc +- **BINDING** | **BINDINGV2** | **BINDINGV3** | **LIBRARY** : \<wgtrootdir\>/lib +- **PLUGIN** : \<wgtrootdir\>/lib/plugins +- **HTDOCS** : \<wgtrootdir\>/htdocs +- **BINDING-DATA** : \<wgtrootdir\>/var +- **DATA** : \<wgtrootdir\>/var + +And about test dedicated **LABELS**: + +- **TEST-CONFIG** : \<TESTwgtrootdir\>/etc +- **TEST-DATA** : \<TESTwgtrootdir\>/var > **TIP** you should use the prefix _afb-_ with your **BINDING* targets which > stand for **Application Framework Binding**. diff --git a/samples.d/config.cmake.sample b/samples.d/config.cmake.sample index 68f8236..b7e60c6 100644 --- a/samples.d/config.cmake.sample +++ b/samples.d/config.cmake.sample @@ -19,6 +19,7 @@ # Project Info # ------------------ set(PROJECT_NAME example) +set(API_NAME api-test) set(PROJECT_PRETTY_NAME "Example") set(PROJECT_DESCRIPTION "AGL application example") set(PROJECT_URL "https://gerrit.automotivelinux.org/gerrit/apps/app-templates") diff --git a/test-widget/launcher.sh.in b/test-widget/launcher.sh.in new file mode 100644 index 0000000..601e88a --- /dev/null +++ b/test-widget/launcher.sh.in @@ -0,0 +1,60 @@ +#!/bin/bash -x + +########################################################################### +# 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. +########################################################################### + +PORT=$1 +TOKEN=$2 + +# Research the Api name used +CFGFILE=$(find ${AFM_APP_INSTALL_DIR} -name "*json" -print0 | head -n1) +API=$(grep '\"api\"' ${CFGFILE} | cut -d'"' -f4) + +AFBCLIENTIN=$(mktemp -u) +AFBCLIENTOUT=$(mktemp -u) +mkfifo $AFBCLIENTIN +mkfifo $AFBCLIENTOUT + +declare -a testVerb + +if [[ $(jq '.testVerb|type' $CFGFILE) == "array" ]] +then + testVerbLength=$(jq '.testVerb | length') + for (( idx=0; idx<testVerbLength; idx++ )) do + testVerb[$idx]=$(jq -r ".testVerb[$idx].uid" ${CFGFILE}) + done +else + testVerb[0]=$(jq -r ".testVerb.uid" ${CFGFILE}) +fi + +tail -f $AFBCLIENTIN | afb-client-demo ws://localhost:${PORT}/api?token=${TOKEN} > $AFBCLIENTOUT 2>&1 & +CLIENTPID=$! + +testVerbLength=${#testVerb[@]} +for (( idx=0; idx<testVerbLength; idx++ )) do + echo "$API ${testVerb[$idx]}" > $AFBCLIENTIN +done + +while read -r line +do + [ "$(echo "${line}" | grep -E 'Ran [[:digit]]+ tests in')" ] && break +done < $AFBCLIENTOUT + +rm -f $AFBCLIENTIN +rm -f $AFBCLIENTOUT +kill $CLIENTPID diff --git a/test-widget/test-config.xml.in b/test-widget/test-config.xml.in new file mode 100644 index 0000000..3252c4b --- /dev/null +++ b/test-widget/test-config.xml.in @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<widget xmlns="http://www.w3.org/ns/widgets" id="@PROJECT_NAME@-test" version="@PROJECT_VERSION@"> + <name>@PROJECT_NAME@-test</name> + <icon src="@PROJECT_ICON@"/> + <content src="bin/launcher" type="application/vnd.agl.native"/> + <description>Supplementary widget used to launch tests for the project @PROJECT_NAME@</description> + <author>Romain Forlot <romain.forlot@iot.bzh></author> + <license>APL2.0</license> + + <feature name="urn:AGL:widget:required-binding"> + <param name="aft" value="auto" /> + </feature> + + <feature name="urn:AGL:widget:required-api"> + <param name="@API_NAME@" value="auto" /> + </feature> + + <feature name="urn:AGL:widget:required-permission"> + <param name="urn:AGL:permission:test" value="required" /> + </feature> + + <feature name="urn:AGL:widget:file-properties"> + <param name="bin/launcher" value="executable" /> + </feature> +</widget> |