From 329d8ba3fb46b8afc803ad4a9b286cd26141f2f8 Mon Sep 17 00:00:00 2001 From: Leonid Lazarev Date: Thu, 9 Jul 2020 16:59:44 +0300 Subject: Add tests for cloudproxy service Test cases for basic functionality verification have been added. Build of the application has been adapted for Cmake templates usage. Bug-AGL: SPEC-3485 Change-Id: Iaa4a5e393ac9971be4176e90fa5aee10a4673cd3 Signed-off-by: Leonid Lazarev --- CMakeLists.txt | 18 +- TEST-README.md | 23 +++ conf.d/cmake/config.cmake | 165 +++++++++++++++++ conf.d/wgt/config.xml.in | 26 +++ conf.d/wgt/icon.svg | 283 ++++++++++++++++++++++++++++++ etc/config.ini | 3 + package/root/config.xml | 23 --- package/root/icon.svg | 283 ------------------------------ src/CMakeLists.txt | 67 ++----- src/config_sample.ini | 3 - test/CMakeLists.txt | 28 +++ test/afb-test/CMakeLists.txt | 21 +++ test/afb-test/etc/CMakeLists.txt | 35 ++++ test/afb-test/etc/aft-agl-cloudproxy.json | 22 +++ test/afb-test/tests/CMakeLists.txt | 34 ++++ test/afb-test/tests/cloudproxy.lua | 26 +++ 16 files changed, 688 insertions(+), 372 deletions(-) create mode 100644 TEST-README.md create mode 100644 conf.d/cmake/config.cmake create mode 100644 conf.d/wgt/config.xml.in create mode 100755 conf.d/wgt/icon.svg create mode 100644 etc/config.ini delete mode 100755 package/root/config.xml delete mode 100755 package/root/icon.svg delete mode 100644 src/config_sample.ini create mode 100644 test/CMakeLists.txt create mode 100644 test/afb-test/CMakeLists.txt create mode 100644 test/afb-test/etc/CMakeLists.txt create mode 100644 test/afb-test/etc/aft-agl-cloudproxy.json create mode 100644 test/afb-test/tests/CMakeLists.txt create mode 100644 test/afb-test/tests/cloudproxy.lua diff --git a/CMakeLists.txt b/CMakeLists.txt index a7f89ba..23a915f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,20 +14,10 @@ # limitations under the License. ########################################################################### -project(CloudProxyService C CXX) +CMAKE_MINIMUM_REQUIRED(VERSION 3.3) -cmake_minimum_required(VERSION 3.0) +project(CloudProxyService) -set(PROJECT_NAME "CloudProxy Service") -set(PROJECT_VERSION "1.0") -set(PROJECT_DESCRIPTION "CloudProxy Service") -set(PROJECT_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}) -set(PROJECT_LIBDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) -set(binding_install_dir ${PREFIX}/lib/cloudproxy) -set(PROJECT_BINDINGDIR ${binding_install_dir}) +include(${CMAKE_CURRENT_SOURCE_DIR}/conf.d/cmake/config.cmake) -# get pkgconfig -INCLUDE(FindPkgConfig) -link_libraries(-Wl,--as-needed -Wl,--gc-sections -Wl,--no-undefined) - -add_subdirectory(src) +install(DIRECTORY etc DESTINATION ./) diff --git a/TEST-README.md b/TEST-README.md new file mode 100644 index 0000000..f81d558 --- /dev/null +++ b/TEST-README.md @@ -0,0 +1,23 @@ +## Building the test widgets +1. Source the SDK environment script +2. Create a build directory +3. Configure and build the project + +``` +mkdir build +cd build +cmake .. -DBUILD_TEST_WGT=TRUE +make +make widget +``` +Note: If you omit the -DBUILD_TEST_WGT=TRUE parameter for cmake, you'll have to type `make test_widget` to compile the test widget. + +This should produce two _.wgt_ files - one with the service and one with the tests within the build directory. + +Run the tests: +``` +scp *.wgt root@:~ +ssh root@ +afm-test $(ls *test.wgt) + +``` diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake new file mode 100644 index 0000000..d6e9516 --- /dev/null +++ b/conf.d/cmake/config.cmake @@ -0,0 +1,165 @@ +########################################################################### +# Copyright 2015, 2016, 2017 IoT.bzh +# +# author: Fulup Ar Foll +# +# Copyright (C) 2020 MERA +# Leonid Lazarev +# +# 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. +########################################################################### + +# Project Info +# ------------------ +set(PROJECT_NAME agl-service-cloudproxy) +set(API_NAME "cloudproxy") +set(PROJECT_PRETTY_NAME "CloudProxy Service") +set(PROJECT_DESCRIPTION "Service providing connection towards clouds") +set(PROJECT_URL "https://gerrit.automotivelinux.org/gerrit/apps/agl-service-cloudproxy") +set(PROJECT_ICON "icon.svg") +set(PROJECT_AUTHOR "MERA") +set(PROJECT_AUTHOR_EMAIL "") +set(PROJECT_VERSION "0.1") +set(PROJECT_LICENSE "APL2.0") +set(PROJECT_LANGUAGES,"CXX") + +# Where are stored the project configuration files +# relative to the root project directory +set(PROJECT_CMAKE_CONF_DIR "conf.d") + +# Where are stored your external libraries for your project. This is 3rd party library that you don't maintain +# but used and must be built and linked. +# set(PROJECT_LIBDIR "libs") + +# Where are stored data for your application. Pictures, static resources must be placed in that folder. +# set(PROJECT_RESOURCES "data") + +# Which directories inspect to find CMakeLists.txt target files +# set(PROJECT_SRC_DIR_PATTERN "*") + +# Compilation Mode (DEBUG, RELEASE) +# ---------------------------------- +set(BUILD_TYPE "RELEASE") + +# Kernel selection if needed. You can choose between a +# mandatory version to impose a minimal version. +# Or check Kernel minimal version and just print a Warning +# about missing features and define a preprocessor variable +# to be used as preprocessor condition in code to disable +# incompatibles features. Preprocessor define is named +# KERNEL_MINIMAL_VERSION_OK. +# +# NOTE*** FOR NOW IT CHECKS KERNEL Yocto environment and +# Yocto SDK Kernel version. +# ----------------------------------------------- +#set(kernel_mandatory_version 4.8) + +# Compiler selection if needed. Impose a minimal version. +# ----------------------------------------------- +set (gcc_minimal_version 4.9) + +# PKG_CONFIG required packages +# ----------------------------- +set (PKG_REQUIRED_LIST + json-c + libsystemd>=222 + afb-daemon + glib-2.0 +) + +# Static constante definition +# ----------------------------- + +add_compile_options($<$:-pthread>) + +# Customize link option +# ----------------------------- +list (APPEND link_libraries -pthread -Wl,--as-needed -Wl,--gc-sections -Wl,--no-undefined) + +# (BUG!!!) as PKG_CONFIG_PATH does not work [should be an env variable] +# --------------------------------------------------------------------- + +set(INSTALL_PREFIX $ENV{HOME}/opt) +set(CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX}/lib64/pkgconfig ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) +set(LD_LIBRARY_PATH ${CMAKE_INSTALL_PREFIX}/lib64 ${CMAKE_INSTALL_PREFIX}/lib) + +# Optional location for config.xml.in +# ----------------------------------- +set(WIDGET_CONFIG_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/conf.d/wgt/config.xml.in) + +# Mandatory widget Mimetype specification of the main unit +# -------------------------------------------------------------------------- +# Choose between : +#- text/html : HTML application, +# content.src designates the home page of the application +# +#- application/vnd.agl.native : AGL compatible native, +# content.src designates the relative path of the binary. +# +# - application/vnd.agl.service: AGL service, content.src is not used. +# +#- ***application/x-executable***: Native application, +# content.src designates the relative path of the binary. +# For such application, only security setup is made. +# +set(WIDGET_TYPE application/vnd.agl.service) + +# Mandatory Widget entry point file of the main unit +# -------------------------------------------------------------- +# This is the file that will be executed, loaded, +# at launch time by the application framework. +# +set(WIDGET_ENTRY_POINT lib/libcloudproxy-binding.so) + +# Print a helper message when every thing is finished +# ---------------------------------------------------- +set(CLOSING_MESSAGE "Test with: afb-daemon --rootdir=\$\$(pwd)/package --binding=\$\$(pwd)/package/${WIDGET_ENTRY_POINT} --port=1234 --tracereq=common --token=\"1\" --verbose") +set(PACKAGE_MESSAGE "Install widget file using in the target : afm-util install ${PROJECT_NAME}.wgt") + +# Optional dependencies order +# --------------------------- +#set(EXTRA_DEPENDENCIES_ORDER) + +# Optional Extra global include path +# ----------------------------------- +#set(EXTRA_INCLUDE_DIRS) + +# Optional extra libraries +# ------------------------- +#set(EXTRA_LINK_LIBRARIES) + +# Optional force binding installation +# ------------------------------------ +# set(BINDINGS_INSTALL_PREFIX PrefixPath ) + +# Optional force binding Linking flag +# ------------------------------------ +# set(BINDINGS_LINK_FLAG LinkOptions ) + +# Optional force package prefix generation, like widget +# ----------------------------------------------------- +# set(PKG_PREFIX DestinationPath) + +# Optional Application Framework security token +# and port use for remote debugging. +#------------------------------------------------------------ +#set(AFB_TOKEN "" CACHE PATH "Default AFB_TOKEN") +#set(AFB_REMPORT "1234" CACHE PATH "Default AFB_TOKEN") + +# This include is mandatory and MUST happens at the end +# of this file, else you expose you to unexpected behavior +# +# This CMake module could be found at the following url: +# https://gerrit.automotivelinux.org/gerrit/#/admin/projects/src/cmake-apps-module +# ----------------------------------------------------------- +include(CMakeAfbTemplates) diff --git a/conf.d/wgt/config.xml.in b/conf.d/wgt/config.xml.in new file mode 100644 index 0000000..ae0ebd2 --- /dev/null +++ b/conf.d/wgt/config.xml.in @@ -0,0 +1,26 @@ + + + @PROJECT_NAME@ + + + @PROJECT_DESCRIPTION@ + @PROJECT_AUTHOR@ <@PROJECT_AUTHOR_MAIL@> + @PROJECT_LICENSE@ + + + + + + + + + + + + + + + + + + diff --git a/conf.d/wgt/icon.svg b/conf.d/wgt/icon.svg new file mode 100755 index 0000000..6628784 --- /dev/null +++ b/conf.d/wgt/icon.svg @@ -0,0 +1,283 @@ + + + +image/svg+xmlSETTINGS + \ No newline at end of file diff --git a/etc/config.ini b/etc/config.ini new file mode 100644 index 0000000..fa97cd7 --- /dev/null +++ b/etc/config.ini @@ -0,0 +1,3 @@ +[AzureCloudConnection] +DeviceConnectionString=My=Azure=Device=Connection=String + diff --git a/package/root/config.xml b/package/root/config.xml deleted file mode 100755 index acfdc1e..0000000 --- a/package/root/config.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - cloudproxy-service - - - CloudProxy service - MERA - APL 2.0 - - - - - - - - - - - - - - - diff --git a/package/root/icon.svg b/package/root/icon.svg deleted file mode 100755 index 6628784..0000000 --- a/package/root/icon.svg +++ /dev/null @@ -1,283 +0,0 @@ - - - -image/svg+xmlSETTINGS - \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fc397f1..fde17a5 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,64 +14,33 @@ # limitations under the License. ########################################################################### -cmake_minimum_required(VERSION 2.8) +PROJECT_TARGET_ADD(cloudproxy-binding) -set(TARGETS_ARBINDER cloudproxy-service) +add_definitions(-DAFB_BINDING_VERSION=3) -INCLUDE(FindThreads) -FIND_PACKAGE(Threads) - -pkg_check_modules(cp_binding_depends afb-daemon glib-2.0 gio-2.0 gio-unix-2.0 json-c) -set(binding_cp_sources - cloudproxy-bindings.cpp - utils.h - hmi-debug.h - ClientManager.h - ClientManager.cpp +set(BINDING_SOURCES + cloudproxy-bindings.cpp + utils.h + hmi-debug.h + ClientManager.h + ClientManager.cpp ) -link_libraries(-Wl,--as-needed -Wl,--gc-sections -Wl,--no-undefined) - set(AZURE_DEP_LIBS iothub_client) -add_library(${TARGETS_ARBINDER} MODULE ${binding_cp_sources}) - include_directories(${CMAKE_SYSROOT}/usr/include/azureiot) -target_compile_options(${TARGETS_ARBINDER} PRIVATE ${cp_binding_depends_CFLAGS}) -if(DEFINED DEBUGMODE) - target_compile_options(${TARGETS_ARBINDER} PRIVATE -g -O0) -else(DEFINED DEBUGMODE) - target_compile_options(${TARGETS_ARBINDER} PRIVATE -g -O2) -endif(DEFINED DEBUGMODE) - -target_link_libraries(${TARGETS_ARBINDER} ${CMAKE_THREAD_LIBS_INIT} ${link_libraries} ${cp_binding_depends_LIBRARIES} ${AZURE_DEP_LIBS}) - +add_library(${TARGET_NAME} MODULE ${BINDING_SOURCES}) -set_target_properties(${TARGETS_ARBINDER} PROPERTIES - PREFIX "" - LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/export.map" - ) +TARGET_LINK_LIBRARIES(${TARGET_NAME} ${link_libraries} ${AZURE_DEP_LIBS}) -target_compile_definitions(${TARGETS_ARBINDER} - PRIVATE - AFB_BINDING_VERSION=3 - _GNU_SOURCE) - - -if(NOT EXISTS ${PROJECT_BINARY_DIR}/package) - add_custom_command(TARGET ${TARGETS_ARBINDER} POST_BUILD - COMMAND cp -rf ${PROJECT_SOURCE_DIR}/package ${PROJECT_BINARY_DIR} - ) -endif() - -add_custom_command(TARGET ${TARGETS_ARBINDER} POST_BUILD - COMMAND mkdir -p ${PROJECT_BINARY_DIR}/package/root/lib - COMMAND cp -rf ${PROJECT_BINARY_DIR}/src/${TARGETS_ARBINDER}.so ${PROJECT_BINARY_DIR}/package/root/lib - COMMAND mkdir -p ${PROJECT_BINARY_DIR}/package/root/etc - COMMAND cp -f ${PROJECT_SOURCE_DIR}/src/config_sample.ini ${PROJECT_BINARY_DIR}/package/root/etc/config.ini -) +SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES + LABELS "BINDING" + PREFIX "lib" + LINK_FLAGS "${BINDINGS_LINK_FLAG}" + OUTPUT_NAME "${TARGET_NAME}" + ) -add_custom_target(widget DEPENDS ${PROJECT_BINARY_DIR}/package/root - COMMAND wgtpkg-pack -f -o ${PROJECT_BINARY_DIR}/${TARGETS_ARBINDER}.wgt ${PROJECT_BINARY_DIR}/package/root +add_custom_command(TARGET ${TARGET_NAME} PRE_BUILD + COMMAND cp -rv ${PROJECT_SOURCE_DIR}/etc ${PROJECT_BINARY_DIR}/package/ ) diff --git a/src/config_sample.ini b/src/config_sample.ini deleted file mode 100644 index fa97cd7..0000000 --- a/src/config_sample.ini +++ /dev/null @@ -1,3 +0,0 @@ -[AzureCloudConnection] -DeviceConnectionString=My=Azure=Device=Connection=String - diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..becb900 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,28 @@ +########################################################################### +# Copyright 2019 Konsulko Group +# +# author:Stoyan Bogdanov +# +# 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. +########################################################################### + + +# Include any directory not starting with _ +# ----------------------------------------------------- +PROJECT_SUBDIRS_ADD(${PROJECT_SRC_DIR_PATTERN}) + +ADD_TEST(NAME AGL_SERVICE_CLOUDPROXY_TESTS + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND afm-test ${CMAKE_BINARY_DIR}/package ${CMAKE_BINARY_DIR}/package-test + ) + diff --git a/test/afb-test/CMakeLists.txt b/test/afb-test/CMakeLists.txt new file mode 100644 index 0000000..81ddf88 --- /dev/null +++ b/test/afb-test/CMakeLists.txt @@ -0,0 +1,21 @@ +########################################################################### +# Copyright 2019 Konsulko Group +# +# author:Stoyan Bogdanov +# +# 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. +########################################################################### + +# Include any directory not starting with _ +# ----------------------------------------------------- +PROJECT_SUBDIRS_ADD(${PROJECT_SRC_DIR_PATTERN}) diff --git a/test/afb-test/etc/CMakeLists.txt b/test/afb-test/etc/CMakeLists.txt new file mode 100644 index 0000000..228764c --- /dev/null +++ b/test/afb-test/etc/CMakeLists.txt @@ -0,0 +1,35 @@ +########################################################################### +# Copyright 2019 Konsulko Group +# +# author:Stoyan Bogdanov +# +# Copyright 2020 MERA +# author:Leonid Lazarev (leonid.lazarev@orioninc.com) +# +# 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. +########################################################################### + +################################################## +# cloudproxy test configuration files +################################################## +PROJECT_TARGET_ADD(afb-test-config) + + file(GLOB CONF_FILES "*.json") + + add_input_files("${CONF_FILES}") + + SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES + LABELS "TEST-CONFIG" + OUTPUT_NAME ${TARGET_NAME} + ) + diff --git a/test/afb-test/etc/aft-agl-cloudproxy.json b/test/afb-test/etc/aft-agl-cloudproxy.json new file mode 100644 index 0000000..be92ed7 --- /dev/null +++ b/test/afb-test/etc/aft-agl-cloudproxy.json @@ -0,0 +1,22 @@ +{ + "id": "http://iot.bzh/download/public/schema/json/ctl-schema.json#", + "$schema": "http://iot.bzh/download/public/schema/json/ctl-schema.json#", + "metadata": { + "uid": "Test", + "version": "1.0", + "api": "aft-cloudproxy", + "info": "AFB-test binding configuration file to test cloudproxy api.", + "require": [ + "cloudproxy" + ] + }, + "testVerb": { + "uid": "launch_all_tests", + "info": "Launch all the tests", + "action": "lua://AFT#_launch_test", + "args": { + "trace": "cloudproxy", + "files": ["cloudproxy.lua"] + } + } +} diff --git a/test/afb-test/tests/CMakeLists.txt b/test/afb-test/tests/CMakeLists.txt new file mode 100644 index 0000000..45dbdef --- /dev/null +++ b/test/afb-test/tests/CMakeLists.txt @@ -0,0 +1,34 @@ +########################################################################### +# Copyright 2019 Konsulko Group +# +# author:Stoyan Bogdanov +# +# Copyright 2020 MERA +# author:Leonid Lazarev +# +# 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. +########################################################################### + +################################################## +# cloudproxy Lua Scripts +################################################## +PROJECT_TARGET_ADD(test-files) + + file(GLOB LUA_FILES "*.lua" "*.sh") + add_input_files("${LUA_FILES}") + + SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES + LABELS "TEST-DATA" + OUTPUT_NAME ${TARGET_NAME} + ) + diff --git a/test/afb-test/tests/cloudproxy.lua b/test/afb-test/tests/cloudproxy.lua new file mode 100644 index 0000000..7832cef --- /dev/null +++ b/test/afb-test/tests/cloudproxy.lua @@ -0,0 +1,26 @@ +--[[ + Copyright 2020 MERA + + author:Leonid Lazarev + + 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. +--]] + +_AFT.testVerbStatusSuccess('testSendMessageSuccess','cloudproxy','ping', {}) +_AFT.testVerbStatusSuccess('testSubscribeToMsgConfirmation','cloudproxy','subscribe', {event="sendMessageConfirmation"}) +_AFT.testVerbStatusSuccess('testSubscribeToReceivedMsg','cloudproxy','subscribe', {event="receivedMessage"}) +_AFT.testVerbStatusSuccess('testUnsubscribeToUnkownMsg','cloudproxy','unsubscribe', {event="UnknownMsg"}) -- NOTE: Implementation detail - unknown msg are ignored. +_AFT.testVerbStatusError('testSubscribeToUnkownMsg','cloudproxy','subscribe', {event="UnknownMsg"}) +_AFT.testVerbStatusSuccess('testUnsubscribeToMsgConfirmation','cloudproxy','unsubscribe', {event="sendMessageConfirmation"}) +_AFT.testVerbStatusSuccess('testUnsubscribeToReceivedMsg','cloudproxy','unsubscribe', {event="receivedMessage"}) + -- cgit 1.2.3-korg