Commit 061db562 authored by Florian Raeth's avatar Florian Raeth

updated test to expected output

parent 75e2790c
Pipeline #186134 passed with stages
in 1 minute and 47 seconds
......@@ -2,142 +2,152 @@
#include "SomeIPAdapter_tests_a_compA.h"
SomeIPAdapter_tests_a_compA::SomeIPAdapter_tests_a_compA() : public IAdapter_tests_a_compA {
//choose random ids
in1_service_id = 11;
in1_instance_id = 12;
in1_method_id = 13;
in1_event_id = 14;
in1_eventgroup_id = 15;
in2_service_id = 21;
in2_instance_id = 22;
in2_method_id = 23;
in2_event_id = 24;
in2_eventgroup_id = 25;
out1_service_id = 111;
out1_instance_id = 112;
out1_method_id = 113;
out1_event_id = 114;
out1_eventgroup_id = 115;
out2_service_id = 121;
out2_instance_id = 122;
out2_method_id = 123;
out2_event_id = 124;
out2_eventgroup_id = 125;
}
void SomeIPAdapter_tests_a_compA::init(tests_a_compA *comp) {
// Initialize component
this->component = comp;
// Intitialize subscriber for in1
in1_Subscriber = vsomeip::runtime::get()->create_application("Subscriber");
in1_Subscriber->init();
in1_Subscriber->request_service(in1_service_id, in1_instance_id);
in1_Subscriber->register_message_handler(in1_service_id, in1_instance_id, in1_method_id, std::bind(&SomeIPAdapter_tests_a_compA::on_message_in1, this, std::placeholders::_1));
// Subscribe
std::set<vsomeip::eventgroup_t> in1_event_group;
in1_event_group.insert(in1_eventgroup_id);
in1_Subscriber->request_event(in1_service_id, in1_instance_id, in1_event_id, in1_event_group, true);
in1_Subscriber->subscribe(in1_service_id, in1_instance_id, in1_eventgroup_id);
in1_Subscriber->start();
// Intitialize subscriber for in2
in2_Subscriber = vsomeip::runtime::get()->create_application("Subscriber");
in2_Subscriber->init();
in2_Subscriber->request_service(in2_service_id, in2_instance_id);
in2_Subscriber->register_message_handler(in2_service_id, in2_instance_id, in2_method_id, std::bind(&SomeIPAdapter_tests_a_compA::on_message_in2, this, std::placeholders::_1));
// Subscribe
std::set<vsomeip::eventgroup_t> in2_event_group;
in2_event_group.insert(in2_eventgroup_id);
in2_Subscriber->request_event(in2_service_id, in2_instance_id, in2_event_id, in2_event_group, true);
in2_Subscriber->subscribe(in2_service_id, in2_instance_id, in2_eventgroup_id);
in2_Subscriber->start();
// Intitialize Publisher for out1
out1_Publisher = vsomeip::runtime::get()->create_application("Publisher");
out1_Publisher->init();
out1_Publisher->offer_service(out1_service_id, out1_instance_id);
out1_Publisher->start();
// Intitialize Publisher for out2
out2_Publisher = vsomeip::runtime::get()->create_application("Publisher");
out2_Publisher->init();
out2_Publisher->offer_service(out2_service_id, out2_instance_id);
out2_Publisher->start();
// Intitialize Subscriber
in1_Subscriber = vsomeip::runtime::get()->create_application("Subscriber in1");
if (!in1_Subscriber->init()) {
std::cerr << "Couldn't initialize Subscriber in1" << std::endl;
}
in1_Subscriber->register_availability_handler(11, 12, std::bind(&SomeIPAdapter_tests_a_compA::on_availability_in1, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
in1_Subscriber->request_service(11, 12);
in1_Subscriber->register_message_handler(11, 12, 0, std::bind(&SomeIPAdapter_tests_a_compA::on_message_in1, this, std::placeholders::_1));
std::thread sender_in1(std::bind(&SomeIPAdapter_tests_a_compA::run_in1, this));
in1_Subscriber->start();
in2_Subscriber = vsomeip::runtime::get()->create_application("Subscriber in2");
if (!in2_Subscriber->init()) {
std::cerr << "Couldn't initialize Subscriber in2" << std::endl;
}
in2_Subscriber->register_availability_handler(21, 22, std::bind(&SomeIPAdapter_tests_a_compA::on_availability_in2, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
in2_Subscriber->request_service(21, 22);
in2_Subscriber->register_message_handler(21, 22, 0, std::bind(&SomeIPAdapter_tests_a_compA::on_message_in2, this, std::placeholders::_1));
std::thread sender_in2(std::bind(&SomeIPAdapter_tests_a_compA::run_in2, this));
in2_Subscriber->start();
// Intitialize Publisher
out1_Publisher = vsomeip::runtime::get()->create_application("Publisher out1");
if (!out1_Publisher->init()) {
std::cerr << "Couldn't initialize Publisher out1" << std::endl;
}
out1_Publisher->offer_service(111, 112);
out1_Publisher->start();
out2_Publisher = vsomeip::runtime::get()->create_application("Publisher out2");
if (!out2_Publisher->init()) {
std::cerr << "Couldn't initialize Publisher out2" << std::endl;
}
out2_Publisher->offer_service(121, 122);
out2_Publisher->start();
}
void SomeIPAdapter_tests_a_compA::run_in1() {
std::unique_lock<std::mutex> its_lock(mutex_in1);
condition_in1.wait(its_lock);
std::set<vsomeip::eventgroup_t> event_group;
event_group.insert(13);
in1_Subscriber->request_event(11, 12, 0, event_group, true);
in1_Subscriber->subscribe(11, 12, 13);
}
void SomeIPAdapter_tests_a_compA::on_message_in1(const std::shared_ptr<vsomeip::message> &_request) {
void SomeIPAdapter_tests_a_compA::on_message_in1(const std::shared_ptr<vsomeip::message> &_message) {
//read received message
std::shared_ptr<vsomeip::payload> its_payload = _request->get_payload();
std::shared_ptr<vsomeip::payload> its_payload = _message->get_payload();
vsomeip::length_t l = its_payload->get_length();
double dataFromMessage = *((double*)its_payload->get_data());
component->in1 = dataFromMessage;
//print data to std out
std::cout << "SERVICE: Received message from ["
<< std::setw(4) << std::setfill('0') << std::hex << _request->get_client() << "/"
<< std::setw(4) << std::setfill('0') << std::hex << _request->get_session() << "]: "
<< dataFromMessage << std::endl;
std::cout << "SERVICE in1: Received message from ["
<< std::setw(4) << std::setfill('0') << std::hex << _message->get_client() << "/"
<< std::setw(4) << std::setfill('0') << std::hex << _message->get_session() << "]: "
<< dataFromMessage << std::endl;
}
void SomeIPAdapter_tests_a_compA::on_availability_in1(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available) {
std::cout << "Service ["
<< std::setw(4) << std::setfill('0') << std::hex << _service << "." << _instance
<< "] is "
<< (_is_available ? "available." : "NOT available.")
<< std::endl;
condition_in1.notify_one();
}
void SomeIPAdapter_tests_a_compA::run_in2() {
std::unique_lock<std::mutex> its_lock(mutex_in2);
condition_in2.wait(its_lock);
std::set<vsomeip::eventgroup_t> event_group;
event_group.insert(23);
in2_Subscriber->request_event(21, 22, 0, event_group, true);
in2_Subscriber->subscribe(21, 22, 23);
}
void SomeIPAdapter_tests_a_compA::on_message_in2(const std::shared_ptr<vsomeip::message> &_request) {
void SomeIPAdapter_tests_a_compA::on_message_in2(const std::shared_ptr<vsomeip::message> &_message) {
//read received message
std::shared_ptr<vsomeip::payload> its_payload = _request->get_payload();
std::shared_ptr<vsomeip::payload> its_payload = _message->get_payload();
vsomeip::length_t l = its_payload->get_length();
double dataFromMessage = *((double*)its_payload->get_data());
component->in2 = dataFromMessage;
//print data to std out
std::cout << "SERVICE: Received message from ["
<< std::setw(4) << std::setfill('0') << std::hex << _request->get_client() << "/"
<< std::setw(4) << std::setfill('0') << std::hex << _request->get_session() << "]: "
<< dataFromMessage << std::endl;
std::cout << "SERVICE in2: Received message from ["
<< std::setw(4) << std::setfill('0') << std::hex << _message->get_client() << "/"
<< std::setw(4) << std::setfill('0') << std::hex << _message->get_session() << "]: "
<< dataFromMessage << std::endl;
}
void SomeIPAdapter_tests_a_compA::on_availability_in2(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available) {
std::cout << "Service ["
<< std::setw(4) << std::setfill('0') << std::hex << _service << "." << _instance
<< "] is "
<< (_is_available ? "available." : "NOT available.")
<< std::endl;
condition_in2.notify_one();
}
void SomeIPAdapter_tests_a_compA::publishout1_Publisher()
{
//Read data from component
double d = component->out1;
//Create message
uint8_t *byteArray = (uint8_t*)&d;
vsomeip::byte_t *p;
p = byteArray;
std::shared_ptr< vsomeip::payload > payload = vsomeip::runtime::get()->create_payload(p,8);
const vsomeip::byte_t its_data[] = { (uint8_t) d };
std::shared_ptr<vsomeip::payload> payload = vsomeip::runtime::get()->create_payload();
payload->set_data(its_data, sizeof(its_data));
//Publish
std::set<vsomeip::eventgroup_t> out1_event_group;
out1_event_group.insert(out1_eventgroup_id);
out1_Publisher->offer_event(out1_service_id, out1_instance_id, out1_event_id, out1_event_group, true);
out1_Publisher->notify(out1_service_id, out1_instance_id, out1_event_id, payload);
std::set<vsomeip::eventgroup_t> event_group;
event_group.insert(113);
out1_Publisher->offer_event(111, 112, 0, event_group, true);
out1_Publisher->notify(111, 112, 0, payload);
}
void SomeIPAdapter_tests_a_compA::publishout2_Publisher()
{
//Read data from component
//Read data from component
double d = component->out2;
//Create message
uint8_t *byteArray = (uint8_t*)&d;
vsomeip::byte_t *p;
p = byteArray;
std::shared_ptr< vsomeip::payload > payload = vsomeip::runtime::get()->create_payload(p,8);
const vsomeip::byte_t its_data[] = { (uint8_t) d };
std::shared_ptr<vsomeip::payload> payload = vsomeip::runtime::get()->create_payload();
payload->set_data(its_data, sizeof(its_data));
//Publish
std::set<vsomeip::eventgroup_t> out2_event_group;
out2_event_group.insert(out2_eventgroup_id);
out2_Publisher->offer_event(out2_service_id, out2_instance_id, out2_event_id, out2_event_group, true);
out2_Publisher->notify(out2_service_id, out2_instance_id, out2_event_id, payload);
std::set<vsomeip::eventgroup_t> event_group;
event_group.insert(123);
out2_Publisher->offer_event(121, 122, 0, event_group, true);
out2_Publisher->notify(121, 122, 0, payload);
}
void SomeIPAdapter_tests_a_compA::tick()
{
publishout1_Publisher();
publishout2_Publisher();
publishout1_Publisher();
publishout2_Publisher();
}
......@@ -21,14 +21,6 @@ public:
void init(tests_a_compA *comp);
void on_message_in1(const std::shared_ptr<vsomeip::message> &_request);
void on_message_in2(const std::shared_ptr<vsomeip::message> &_request);
void publishout1_Publisher();
void publishout2_Publisher();
void tick();
......@@ -36,35 +28,25 @@ private:
tests_a_compA* component = nullptr;
std::shared_ptr<vsomeip::application> in1_Subscriber;
std::shared_ptr<vsomeip::application> in2_Subscriber;
std::shared_ptr<vsomeip::application> out1_Publisher;
std::shared_ptr<vsomeip::application> in1_Subscriber;
std::mutex mutex_in1;
std::condition_variable condition_in1;
std::shared_ptr<vsomeip::application> out2_Publisher;
void run_in1();
void on_message_in1(const std::shared_ptr<vsomeip::message> &_message);
void on_availability_in1(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available);
std::shared_ptr<vsomeip::application> in2_Subscriber;
std::mutex mutex_in2;
std::condition_variable condition_in2;
int in1_service_id;
int in1_instance_id;
int in1_method_id;
int in1_event_id;
int in1_eventgroup_id;
void run_in2();
void on_message_in2(const std::shared_ptr<vsomeip::message> &_message);
void on_availability_in2(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available);
int in2_service_id;
int in2_instance_id;
int in2_method_id;
int in2_event_id;
int in2_eventgroup_id;
std::shared_ptr<vsomeip::application> out1_Publisher;
int out1_service_id;
int out1_instance_id;
int out1_method_id;
int out1_event_id;
int out1_eventgroup_id;
void publishout1_Publisher();
std::shared_ptr<vsomeip::application> out2_Publisher;
int out2_service_id;
int out2_instance_id;
int out2_method_id;
int out2_event_id;
int out2_eventgroup_id;
void publishout2_Publisher();
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment