Skip to content
Snippets Groups Projects
Commit d9c1bf77 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[test][docker_execution] Add test for setup in cxx algorithm

This test ensures that the setup feature works properly.
parent bcfa1ca4
No related branches found
No related tags found
1 merge request!124Add test for setup in cxx algorithm
Pipeline #41345 passed
Showing
with 364 additions and 0 deletions
{
"schema_version": 2,
"language": "cxx",
"api_version": 2,
"type": "sequential",
"splittable": true,
"groups": [
{
"name": "main",
"inputs": {
"in_data": {
"type": "user/single_integer/1"
}
},
"outputs": {
"out_data": {
"type": "user/single_integer/1"
}
}
}
],
"parameters": {
"offset": {
"default": 0,
"type": "int8",
"description": "Offset to apply"
}
}
}
cmake_minimum_required(VERSION 3.0)
project(BEAT_CORE_CXX_INTEGERS_ECHO_SEQUENTIAL)
set(BEAT_BACKEND_CXX_DIR "/usr/local/beat")
# CMake setup
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Retrieve the dependencies
find_package(Boost REQUIRED)
# Setup the search paths
include_directories(
"${BEAT_BACKEND_CXX_DIR}/include"
"${Boost_INCLUDE_DIRS}"
)
link_directories(
"${BEAT_BACKEND_CXX_DIR}/bin"
)
# List the source files
set(HEADERS "algorithm.h"
"beat_setup.h"
"user_single_integer_1.h"
)
set(SRCS "algorithm.cpp"
"beat_setup.cpp"
"user_single_integer_1.cpp"
)
# Create and link the library
add_library(cxx_integers_echo_sequential SHARED ${SRCS} ${HEADERS})
target_link_libraries(cxx_integers_echo_sequential beat_backend_cxx)
set_target_properties(cxx_integers_echo_sequential PROPERTIES
COMPILE_FLAGS "-fPIC"
OUTPUT_NAME "1"
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${BEAT_CORE_CXX_INTEGERS_ECHO_SEQUENTIAL_SOURCE_DIR}"
)
// NOTE: This file implements the algorithm declared in the file
// 'user/cxx_integers_echo/1.json'
#include "algorithm.h"
#include "beat.backend.cxx/input.h"
#include "beat.backend.cxx/inputlist.h"
#include "beat.backend.cxx/outputlist.h"
#include "beat.backend.cxx/dataloader.h"
#include "user_single_integer_1.h"
using namespace beat::backend::cxx;
Algorithm::Algorithm():
_offset(0)
{
}
//---------------------------------------------------------
Algorithm::~Algorithm()
{
}
//---------------------------------------------------------
bool Algorithm::setup(const json& parameters)
{
_offset = parameters["offset"];
return true;
}
//---------------------------------------------------------
bool Algorithm::prepare(const DataLoaderList& data_load_list)
{
return true;
}
//---------------------------------------------------------
bool Algorithm::process(const InputList& inputs,
const DataLoaderList& data_load_list,
const OutputList& outputs)
{
auto data = inputs["in_data"]->data<dataformats::user::single_integer_1>();
data->value += _offset;
outputs["out_data"]->write(data);
return true;
}
//---------------------------------------------------------
IAlgorithm* create_algorithm()
{
return new Algorithm();
}
// NOTE: This file implements the algorithm declared in the file
// 'user/cxx_integers_echo/1.json'
#ifndef _BEAT_GENERATED_ALGORITHM_H_
#define _BEAT_GENERATED_ALGORITHM_H_
#include <beat.backend.cxx/algorithm.h>
class Algorithm: public beat::backend::cxx::IAlgorithmSequential
{
public:
Algorithm();
virtual ~Algorithm();
bool setup(const json& parameters) override;
bool prepare(const beat::backend::cxx::DataLoaderList& data_load_list) override;
bool process(const beat::backend::cxx::InputList& inputs,
const beat::backend::cxx::DataLoaderList& data_load_list,
const beat::backend::cxx::OutputList& outputs) override;
private:
int _offset;
};
extern "C" {
beat::backend::cxx::IAlgorithm* create_algorithm();
}
#endif
// NOTE: This file was automatically generated from the algorithm declaration file
// 'user/cxx_integers_echo/1.json'
#include <beat.backend.cxx/dataformatfactory.h>
#include "beat_setup.h"
#include "user_single_integer_1.h"
using namespace beat::backend::cxx;
void setup_beat_cxx_module()
{
DataFormatFactory* factory = DataFormatFactory::getInstance();
factory->registerDataFormat<dataformats::user::single_integer_1>();
}
// NOTE: This file was automatically generated from the algorithm declaration file
// 'user/cxx_integers_echo/1.json'
#ifndef _BEAT_SETUP_H_
#define _BEAT_SETUP_H_
extern "C" {
void setup_beat_cxx_module();
}
#endif
// NOTE: This file was automatically generated from the dataformat declaration file
// 'user/single_integer/1.json'
#include "user_single_integer_1.h"
#include <beat.backend.cxx/dataformatfactory.h>
using namespace beat::backend::cxx;
dataformats::user::single_integer_1::single_integer_1()
{
}
//---------------------------------------------------------
size_t dataformats::user::single_integer_1::fixed_size()
{
return sizeof(int32_t);
}
//---------------------------------------------------------
size_t dataformats::user::single_integer_1::size() const
{
return dataformats::user::single_integer_1::fixed_size();
}
//---------------------------------------------------------
void dataformats::user::single_integer_1::pack(uint8_t** buffer) const
{
beat::backend::cxx::pack(value, buffer);
}
//---------------------------------------------------------
void dataformats::user::single_integer_1::unpack(uint8_t** buffer)
{
value = beat::backend::cxx::unpack_scalar<int32_t>(buffer);
}
//---------------------------------------------------------
Data* dataformats::user::single_integer_1::create()
{
return new user::single_integer_1();
}
//---------------------------------------------------------
const char *dataformats::user::single_integer_1::getNameStatic()
{
return "user/single_integer/1";
}
//---------------------------------------------------------
std::string dataformats::user::single_integer_1::toJson() const
{
return "{"
"\"field\":\"int32_t\""
"}";
}
// NOTE: This file was automatically generated from the dataformat declaration file
// 'user/single_integer/1.json'
#ifndef _BEAT_GENERATED_user_single_integer_1_H_
#define _BEAT_GENERATED_user_single_integer_1_H_
#include <beat.backend.cxx/data.h>
namespace dataformats {
namespace user {
class single_integer_1: public beat::backend::cxx::DataImpl<single_integer_1>
{
public:
single_integer_1();
static size_t fixed_size();
size_t size() const override;
void pack(uint8_t** buffer) const override;
void unpack(uint8_t** buffer) override;
static Data* create();
static const char *getNameStatic();
std::string toJson() const override;
public:
int32_t value;
};
} // user
} // dataformats
#endif
{
"analyzers": {
"analysis": {
"algorithm": "v1/integers_echo_analyzer/1",
"inputs": {
"in_data": "in"
}
}
},
"blocks": {
"echo1": {
"algorithm": "user/cxx_integers_offsetter_sequential/1",
"inputs": {
"in_data": "in"
},
"outputs": {
"out_data": "out"
},
"parameters": {
"offset": 15
},
"environment": {
"name": "C++",
"version": "2.0.0"
}
},
"echo2": {
"algorithm": "user/cxx_integers_offsetter_sequential/1",
"inputs": {
"in_data": "in"
},
"outputs": {
"out_data": "out"
},
"parameters": {
"offset": 20
},
"environment": {
"name": "C++",
"version": "2.0.0"
}
}
},
"datasets": {
"set": {
"database": "simple/1",
"protocol": "protocol",
"set": "set"
}
},
"globals": {
"queue": "queue",
"environment": {
"name": "Python for tests",
"version": "1.3.0"
},
"user/cxx_integers_offsetter_sequential/1": {
"offset": 0
}
}
}
......@@ -199,6 +199,19 @@ class TestDockerExecution(BaseExecutionMixIn):
)
)
@slow
def test_cxx_double_offsetting_sequential(self):
datasets_uid = os.getuid()
self.build_algorithm("prefix/algorithms/user/cxx_integers_offsetter_sequential")
nose.tools.assert_is_none(
self.execute(
"user/user/double/1/cxx_offsetting_sequential",
[{"out_data": 77}],
datasets_uid=datasets_uid,
)
)
@slow
def test_cxx_double_autonomous(self):
datasets_uid = os.getuid()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment