Skip to content

Commit

Permalink
Merge pull request #23 from fledge-iot/2.2.0RC
Browse files Browse the repository at this point in the history
2.2.0RC
  • Loading branch information
dianomicbot authored Oct 20, 2023
2 parents 64e91a1 + c2af10e commit 27e5202
Show file tree
Hide file tree
Showing 10 changed files with 326 additions and 4 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

# build and packages
build
tests/build
tests/cmake_install.cmake
tests/CMakeCache.txt
tests/CMakeFiles
tests/*.xml

# IDE
*.idea
*.idea

61 changes: 61 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
timestamps {
node("ubuntu18-agent") {
catchError {
checkout scm
dir_exists = sh (
script: "test -d 'tests' && echo 'Y' || echo 'N' ",
returnStdout: true
).trim()

if (dir_exists == 'N'){
currentBuild.result= 'FAILURE'
echo "No tests directory found! Exiting."
return
}
try {
stage("Prerequisites"){
// Change to corresponding CORE_BRANCH as required
// e.g. FOGL-xxxx, main etc.
sh '''
CORE_BRANCH='2.2.0RC'
${HOME}/buildFledge ${CORE_BRANCH} ${WORKSPACE}
'''
}
} catch (e) {
currentBuild.result = 'FAILURE'
echo "Failed to build Fledge; required to run the tests!"
return
}

try {
stage("Run Tests"){
echo "Executing tests..."
sh '''
export FLEDGE_ROOT=$HOME/fledge
cd tests && cmake . && make && ./RunTests --gtest_output=xml:test_output.xml
'''
echo "Done."
}
} catch (e) {
result = "TESTS FAILED"
currentBuild.result = 'FAILURE'
echo "Tests failed!"
}

try {
stage("Publish Test Report"){
junit "tests/test_output.xml"
}
} catch (e) {
result = "TEST REPORT GENERATION FAILED"
currentBuild.result = 'FAILURE'
echo "Failed to generate test reports!"
}
}

stage ("Cleanup"){
// Add here if any cleanup is required
echo "Done."
}
}
}
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.0
2.2.0
2 changes: 1 addition & 1 deletion fledge.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fledge_version>=2.1
fledge_version>=2.2
10 changes: 9 additions & 1 deletion plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,15 @@ void plugin_ingest(PLUGIN_HANDLE *handle,
{
elem->addDatapoint(new Datapoint(*it));
}
AssetTracker::getAssetTracker()->addAssetTrackingTuple(info->configCatName, elem->getAssetName(), string("Filter"));
//AssetTracker::getAssetTracker()->addAssetTrackingTuple(info->configCatName, elem->getAssetName(), string("Filter"));
AssetTracker *instance = nullptr;
instance = AssetTracker::getAssetTracker();
if (instance != nullptr)
{
instance->addAssetTrackingTuple(info->configCatName, elem->getAssetName(), string("Filter"));
}


}

filter->m_func(filter->m_data, origReadingSet);
Expand Down
90 changes: 90 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
cmake_minimum_required(VERSION 2.6.0)

project(RunTests)

# Supported options:
# -DFLEDGE_INCLUDE
# -DFLEDGE_LIB
# -DFLEDGE_SRC
# -DFLEDGE_INSTALL
#
# If no -D options are given and FLEDGE_ROOT environment variable is set
# then Fledge libraries and header files are pulled from FLEDGE_ROOT path.

set(CMAKE_CXX_FLAGS "-std=c++11 -O3")

# Generation version header file
set_source_files_properties(version.h PROPERTIES GENERATED TRUE)
add_custom_command(
OUTPUT version.h
DEPENDS ${CMAKE_SOURCE_DIR}/../VERSION
COMMAND ${CMAKE_SOURCE_DIR}/../mkversion ${CMAKE_SOURCE_DIR}/..
COMMENT "Generating version header"
VERBATIM
)
include_directories(${CMAKE_BINARY_DIR})

# Add here all needed Fledge libraries as list
set(NEEDED_FLEDGE_LIBS common-lib services-common-lib filters-common-lib)

set(BOOST_COMPONENTS system thread)

find_package(Boost 1.53.0 COMPONENTS ${BOOST_COMPONENTS} REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIR})

# Find source files
file(GLOB SOURCES ../*.cpp)
file(GLOB unittests "*.cpp")

# Find Fledge includes and libs, by including FindFledge.cmak file
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/..)
find_package(Fledge)
# If errors: make clean and remove Makefile
if (NOT FLEDGE_FOUND)
if (EXISTS "${CMAKE_BINARY_DIR}/Makefile")
execute_process(COMMAND make clean WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
file(REMOVE "${CMAKE_BINARY_DIR}/Makefile")
endif()
# Stop the build process
message(FATAL_ERROR "Fledge plugin '${PROJECT_NAME}' build error.")
endif()
# On success, FLEDGE_INCLUDE_DIRS and FLEDGE_LIB_DIRS variables are set

# Locate GTest
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

# Add ../include
include_directories(../include)
# Add Fledge include dir(s)
include_directories(${FLEDGE_INCLUDE_DIRS})

# Add other include paths
if (FLEDGE_SRC)
message(STATUS "Using third-party includes " ${FLEDGE_SRC}/C/thirdparty)
include_directories(${FLEDGE_SRC}/C/thirdparty/rapidjson/include)
include_directories(${FLEDGE_SRC}/C/thirdparty/Simple-Web-Server)
endif()

# Add Fledge lib path
link_directories(${FLEDGE_LIB_DIRS})

# Link runTests with what we want to test and the GTest and pthread library
add_executable(RunTests ${unittests} ${SOURCES} version.h)

# Add additional libraries

# Add additional link directories

set(FLEDGE_INSTALL "" CACHE INTERNAL "")
# Install library
if (FLEDGE_INSTALL)
message(STATUS "Installing ${PROJECT_NAME} in ${FLEDGE_INSTALL}/plugins/${PLUGIN_TYPE}/${PROJECT_NAME}")
install(TARGETS ${PROJECT_NAME} DESTINATION ${FLEDGE_INSTALL}/plugins/${PLUGIN_TYPE}/${PROJECT_NAME})
endif()


target_link_libraries(RunTests ${GTEST_LIBRARIES} pthread)
target_link_libraries(RunTests ${NEEDED_FLEDGE_LIBS})
target_link_libraries(RunTests ${Boost_LIBRARIES})
target_link_libraries(RunTests -lpthread -ldl)
14 changes: 14 additions & 0 deletions tests/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
=====================================================
Build and Run test cases
=====================================================

To build Fledge "metadata" C++ filter plugin unit test cases:

.. code-block:: console
$ mkdir build
$ cd build
$ cmake ..
$ make
$ ./RunTests
17 changes: 17 additions & 0 deletions tests/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <gtest/gtest.h>
#include <resultset.h>
#include <string.h>
#include <string>

using namespace std;

int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);

testing::GTEST_FLAG(repeat) = 200;
testing::GTEST_FLAG(shuffle) = true;
testing::GTEST_FLAG(death_test_style) = "threadsafe";

return RUN_ALL_TESTS();
}
30 changes: 30 additions & 0 deletions tests/test_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <gtest/gtest.h>
#include <plugin_api.h>
#include <string.h>
#include <string>
#include <rapidjson/document.h>

using namespace std;
using namespace rapidjson;

extern "C"
{
PLUGIN_INFORMATION *plugin_info();
};

TEST(METADATA_INFO, PluginInfo)
{
PLUGIN_INFORMATION *info = plugin_info();
ASSERT_STREQ(info->name, "metadata");
ASSERT_EQ(info->type, PLUGIN_TYPE_FILTER);
}

TEST(METADATA_INFO, PluginInfoConfigParse)
{
PLUGIN_INFORMATION *info = plugin_info();
Document doc;
doc.Parse(info->config);
ASSERT_EQ(doc.HasParseError(), false);
ASSERT_EQ(doc.IsObject(), true);
ASSERT_EQ(doc.HasMember("plugin"), true);
}
96 changes: 96 additions & 0 deletions tests/test_metadata.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#include <gtest/gtest.h>
#include <plugin_api.h>
#include <config_category.h>
#include <filter_plugin.h>
#include <filter.h>
#include <string.h>
#include <string>
#include <rapidjson/document.h>
#include <reading.h>
#include <reading_set.h>
#include <logger.h>

using namespace std;
using namespace rapidjson;

extern "C"
{
PLUGIN_INFORMATION *plugin_info();
void plugin_ingest(void *handle,
READINGSET *readingSet);
PLUGIN_HANDLE plugin_init(ConfigCategory *config,
OUTPUT_HANDLE *outHandle,
OUTPUT_STREAM output);
int called = 0;

void Handler(void *handle, READINGSET *readings)
{
called++;
*(READINGSET **)handle = readings;
}
};

TEST(METADATA, MetadataDisabled)
{
PLUGIN_INFORMATION *info = plugin_info();
ConfigCategory *config = new ConfigCategory("metadata", info->config);
ASSERT_NE(config, (ConfigCategory *)NULL);
config->setItemsValueFromDefault();
ASSERT_EQ(config->itemExists("config"), true);
ASSERT_EQ(config->itemExists("enable"), true);
config->setValue("config", "{ \"Source\" : \"Camera\"}");
config->setValue("enable", "false");
ReadingSet *outReadings;
void *handle = plugin_init(config, &outReadings, Handler);
vector<Reading *> *readings = new vector<Reading *>;

long testValue = 2;
DatapointValue dpv(testValue);
Datapoint *value = new Datapoint("test", dpv);
Reading *in = new Reading("test", value);
readings->push_back(in);

ReadingSet *readingSet = new ReadingSet(readings);
plugin_ingest(handle, (READINGSET *)readingSet);

vector<Reading *> results = outReadings->getAllReadings();
ASSERT_EQ(results.size(), 1);
Reading *out = results[0];
ASSERT_EQ(out->getDatapointCount(), 1);

vector<Datapoint *> points = out->getReadingData();
ASSERT_EQ(points.size(), 1);
}

TEST(METADATA, MetadataAddDataPoints)
{
PLUGIN_INFORMATION *info = plugin_info();
ConfigCategory *config = new ConfigCategory("replace", info->config);
ASSERT_NE(config, (ConfigCategory *)NULL);
config->setItemsValueFromDefault();
ASSERT_EQ(config->itemExists("config"), true);
ASSERT_EQ(config->itemExists("enable"), true);
config->setValue("config", "{ \"Source\":\"Camera\"}");
config->setValue("enable", "true");
ReadingSet *outReadings;
void *handle = plugin_init(config, &outReadings, Handler);
vector<Reading *> *readings = new vector<Reading *>;

long testValue = 2;
DatapointValue dpv(testValue);
Datapoint *value = new Datapoint("test", dpv);
Reading *in = new Reading("test", value);
readings->push_back(in);

ReadingSet *readingSet = new ReadingSet(readings);
plugin_ingest(handle, (READINGSET *)readingSet);

vector<Reading *> results = outReadings->getAllReadings();
ASSERT_EQ(results.size(), 1);
Reading *out = results[0];
ASSERT_EQ(out->getDatapointCount(), 2);

vector<Datapoint *> points = out->getReadingData();
ASSERT_EQ(points.size(), 2);
}

0 comments on commit 27e5202

Please sign in to comment.