summaryrefslogtreecommitdiff
path: root/test/initial_event_tests/initial_event_test_client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/initial_event_tests/initial_event_test_client.cpp')
-rw-r--r--test/initial_event_tests/initial_event_test_client.cpp161
1 files changed, 136 insertions, 25 deletions
diff --git a/test/initial_event_tests/initial_event_test_client.cpp b/test/initial_event_tests/initial_event_test_client.cpp
index bc9d46a..ef215f1 100644
--- a/test/initial_event_tests/initial_event_test_client.cpp
+++ b/test/initial_event_tests/initial_event_test_client.cpp
@@ -36,13 +36,15 @@ public:
bool _subscribe_on_available, std::uint32_t _events_to_subscribe,
bool _initial_event_strict_checking,
bool _dont_exit, bool _subscribe_only_one,
- vsomeip::reliability_type_e _reliability_type) :
+ vsomeip::reliability_type_e _reliability_type,
+ bool _client_subscribes_twice) :
client_number_(_client_number),
service_infos_(_service_infos),
service_offered_tcp_and_udp_(_service_offered_tcp_and_udp),
app_(vsomeip::runtime::get()->create_application()),
wait_until_registered_(true),
wait_for_stop_(true),
+ is_first(true),
subscribe_on_available_(_subscribe_on_available),
events_to_subscribe_(_events_to_subscribe),
initial_event_strict_checking_(_initial_event_strict_checking),
@@ -50,9 +52,11 @@ public:
subscribe_only_one_(_subscribe_only_one),
stop_thread_(&initial_event_test_client::wait_for_stop, this),
wait_for_signal_handler_registration_(true),
- reliability_type_(_reliability_type)
+ reliability_type_(_reliability_type),
+ client_subscribes_twice_(_client_subscribes_twice)
{
if (!app_->init()) {
+ stop_thread_.detach();
ADD_FAILURE() << "Couldn't initialize application";
return;
}
@@ -92,6 +96,8 @@ public:
if (events_to_subscribe_ == 1) {
app_->subscribe(i.service_id, i.instance_id, i.eventgroup_id,
vsomeip::DEFAULT_MAJOR);
+
+ std::lock_guard<std::mutex> its_lock(received_notifications_mutex_);
other_services_received_notification_[std::make_pair(i.service_id, i.event_id)] = 0;
} else if (events_to_subscribe_ > 1) {
if (!subscribe_only_one_) {
@@ -99,6 +105,7 @@ public:
app_->subscribe(i.service_id, i.instance_id, i.eventgroup_id,
vsomeip::DEFAULT_MAJOR,
static_cast<vsomeip::event_t>(i.event_id + j));
+ std::lock_guard<std::mutex> its_lock(received_notifications_mutex_);
other_services_received_notification_[std::make_pair(i.service_id, i.event_id + j)] = 0;
}
} else {
@@ -134,8 +141,12 @@ public:
}
~initial_event_test_client() {
- stop_thread_.join();
- signal_thread_.join();
+ if (stop_thread_.joinable()) {
+ stop_thread_.join();
+ }
+ if (signal_thread_.joinable()) {
+ signal_thread_.join();
+ }
}
void on_state(vsomeip::state_type_e _state) {
@@ -196,33 +207,79 @@ public:
void on_message(const std::shared_ptr<vsomeip::message> &_message) {
if(_message->get_message_type() == vsomeip::message_type_e::MT_NOTIFICATION) {
- other_services_received_notification_[std::make_pair(_message->get_service(),
- _message->get_method())]++;
-
- VSOMEIP_DEBUG << "[" << std::setw(4) << std::setfill('0') << std::hex
- << client_number_ << "] "
- << "Received a notification with Client/Session [" << std::setw(4)
- << std::setfill('0') << std::hex << _message->get_client() << "/"
- << std::setw(4) << std::setfill('0') << std::hex
- << _message->get_session() << "] from Service/Method ["
- << std::setw(4) << std::setfill('0') << std::hex
- << _message->get_service() << "/" << std::setw(4) << std::setfill('0')
- << std::hex << _message->get_method() <<"] (now have: "
- << std::dec << other_services_received_notification_[std::make_pair(_message->get_service(),
- _message->get_method())] << ")";
+ {
+ std::lock_guard<std::mutex> its_lock(received_notifications_mutex_);
+ other_services_received_notification_[std::make_pair(_message->get_service(),
+ _message->get_method())]++;
+ VSOMEIP_DEBUG << "[" << std::setw(4) << std::setfill('0') << std::hex
+ << client_number_ << "] "
+ << "Received a notification with Client/Session [" << std::setw(4)
+ << std::setfill('0') << std::hex << _message->get_client() << "/"
+ << std::setw(4) << std::setfill('0') << std::hex
+ << _message->get_session() << "] from Service/Method ["
+ << std::setw(4) << std::setfill('0') << std::hex
+ << _message->get_service() << "/" << std::setw(4) << std::setfill('0')
+ << std::hex << _message->get_method() <<"] (now have: "
+ << std::dec << other_services_received_notification_[std::make_pair(_message->get_service(),
+ _message->get_method())] << ")";
+ }
std::shared_ptr<vsomeip::payload> its_payload(_message->get_payload());
EXPECT_EQ(2u, its_payload->get_length());
EXPECT_EQ((_message->get_service() & 0xFF00 ) >> 8, its_payload->get_data()[0]);
EXPECT_EQ((_message->get_service() & 0xFF), its_payload->get_data()[1]);
bool notify(false);
- if (!service_offered_tcp_and_udp_) {
- if (all_notifications_received()) {
- notify = true;
+ if (client_subscribes_twice_) {
+ // only relevant for testcase:
+ // initial_event_test_diff_client_ids_same_ports_udp_client_subscribes_twice
+ // check that a second subscribe triggers another initial event
+ // expect notifications_to_send_after_double_subscribe == 2;
+ if (is_first) {
+ std::this_thread::sleep_for(std::chrono::milliseconds(2000));
+ for(const auto& i : service_infos_) {
+ // subscribe again and expect initial events cached at rm::proxy to be received
+ // as configured routing manager only fires the event once after first susbcribe.
+ if (i.service_id == 0xFFFF && i.instance_id == 0xFFFF) {
+ continue;
+ }
+ if (!subscribe_on_available_) {
+ if (events_to_subscribe_ == 1) {
+ app_->subscribe(i.service_id, i.instance_id, i.eventgroup_id,
+ vsomeip::DEFAULT_MAJOR);
+ } else if (events_to_subscribe_ > 1) {
+ if (!subscribe_only_one_) {
+ for (std::uint32_t j = 0; j < events_to_subscribe_; j++ ) {
+ app_->subscribe(i.service_id, i.instance_id, i.eventgroup_id,
+ vsomeip::DEFAULT_MAJOR,
+ static_cast<vsomeip::event_t>(i.event_id + j));
+ }
+ } else {
+ app_->subscribe(i.service_id, i.instance_id, i.eventgroup_id,
+ vsomeip::DEFAULT_MAJOR,
+ static_cast<vsomeip::event_t>(i.event_id));
+ }
+ }
+ }
+ }
+ is_first = false;
+ } else {
+ bool received_initial_event_twice(false);
+ std::lock_guard<std::mutex> its_lock(received_notifications_mutex_);
+ received_initial_event_twice = all_notifications_received_twice();
+ if (received_initial_event_twice) {
+ notify = true;
+ }
}
} else {
- if (all_notifications_received_tcp_and_udp()) {
- notify = true;
+ if (!service_offered_tcp_and_udp_) {
+ std::lock_guard<std::mutex> its_lock(received_notifications_mutex_);
+ if (all_notifications_received()) {
+ notify = true;
+ }
+ } else {
+ if (all_notifications_received_tcp_and_udp()) {
+ notify = true;
+ }
}
}
@@ -277,7 +334,50 @@ public:
);
}
+ bool all_notifications_received_twice() {
+ return std::all_of(
+ other_services_received_notification_.cbegin(),
+ other_services_received_notification_.cend(),
+ [&](const std::map<std::pair<vsomeip::service_t,
+ vsomeip::method_t>, std::uint32_t>::value_type& v)
+ {
+ bool result;
+ if (v.second == initial_event_test::notifications_to_send * 2) {
+ result = true;
+ } else {
+ if (v.second >= initial_event_test::notifications_to_send * 2) {
+ VSOMEIP_WARNING
+ << __func__ << "[" << std::setw(4) << std::setfill('0') << std::hex
+ << client_number_ << "] "
+ << " Received multiple initial events from service/instance: "
+ << std::setw(4) << std::setfill('0') << std::hex << v.first.first
+ << "."
+ << std::setw(4) << std::setfill('0') << std::hex << v.first.second
+ << " number of received events: " << v.second
+ << ". This is caused by StopSubscribe/Subscribe messages and/or"
+ << " service offered via UDP and TCP";
+ if (initial_event_strict_checking_) {
+ ADD_FAILURE() << __func__ << "[" << std::setw(4) << std::setfill('0') << std::hex
+ << client_number_ << "] "
+ << " Received multiple initial events from service/instance: "
+ << std::setw(4) << std::setfill('0') << std::hex << v.first.first
+ << "."
+ << std::setw(4) << std::setfill('0') << std::hex << v.first.second
+ << " number of received events: " << v.second;
+ }
+ result = initial_event_strict_checking_ ? false : true;
+
+ } else {
+ result = false;
+ }
+ }
+ return result;
+ }
+ );
+ }
+
bool all_notifications_received_tcp_and_udp() {
+ std::lock_guard<std::mutex> its_lock(received_notifications_mutex_);
std::uint32_t received_twice(0);
std::uint32_t received_normal(0);
for(const auto &v : other_services_received_notification_) {
@@ -402,6 +502,7 @@ private:
bool service_offered_tcp_and_udp_;
std::shared_ptr<vsomeip::application> app_;
std::map<std::pair<vsomeip::service_t, vsomeip::instance_t>, bool> other_services_available_;
+ std::mutex received_notifications_mutex_;
std::map<std::pair<vsomeip::service_t, vsomeip::method_t>, std::uint32_t> other_services_received_notification_;
bool wait_until_registered_;
@@ -409,6 +510,7 @@ private:
std::condition_variable condition_;
std::atomic<bool> wait_for_stop_;
+ std::atomic<bool> is_first;
bool subscribe_on_available_;
std::uint32_t events_to_subscribe_;
@@ -424,6 +526,7 @@ private:
std::condition_variable signal_condition_;
std::thread signal_thread_;
vsomeip::reliability_type_e reliability_type_;
+ bool client_subscribes_twice_;
};
static int client_number;
@@ -434,6 +537,8 @@ static std::uint32_t subscribe_multiple_events;
static bool initial_event_strict_checking;
static bool dont_exit;
static bool subscribe_only_one;
+static bool client_subscribes_twice;
+
vsomeip::reliability_type_e reliability_type = vsomeip::reliability_type_e::RT_UNKNOWN;
@@ -450,13 +555,15 @@ TEST(someip_initial_event_test, wait_for_initial_events_of_all_services)
subscribe_on_available, subscribe_multiple_events,
initial_event_strict_checking, dont_exit,
subscribe_only_one,
- reliability_type);
+ reliability_type,
+ client_subscribes_twice);
} else {
initial_event_test_client its_sample(client_number, service_offered_tcp_and_udp,
initial_event_test::service_infos, subscribe_on_available,
subscribe_multiple_events, initial_event_strict_checking, dont_exit,
subscribe_only_one,
- reliability_type);
+ reliability_type,
+ client_subscribes_twice);
}
}
@@ -492,6 +599,7 @@ int main(int argc, char** argv)
subscribe_multiple_events = 1;
dont_exit = false;
subscribe_only_one = false;
+ client_subscribes_twice = false;
if (argc > 2) {
for (int i = 2; i < argc; i++) {
if (std::string("SUBSCRIBE_ON_AVAILABILITY") == std::string(argv[i])) {
@@ -518,6 +626,9 @@ int main(int argc, char** argv)
} else if (std::string("TCP_AND_UDP")== std::string(argv[i])) {
reliability_type = vsomeip::reliability_type_e::RT_BOTH;
std::cout << "Using reliability type RT_BOTH" << std::endl;
+ } else if (std::string("CLIENT_SUBSCRIBES_TWICE")== std::string(argv[i])) {
+ client_subscribes_twice = true;
+ std::cout << "Testing for initial event after a second subscribe from same client CLIENT_SUBSCRIBES_TWICE" << std::endl;
}
}
}