From 4808f3130c97cea3f0168005b9df029282060539 Mon Sep 17 00:00:00 2001 From: Juergen Gehring Date: Thu, 25 Jan 2018 00:40:10 -0800 Subject: [PATCH] vsomeip 2.10.10 --- CHANGES | 3 ++ CMakeLists.txt | 2 +- .../routing/src/routing_manager_impl.cpp | 5 +- .../offered_services_info_test_client.cpp | 48 +++++++++++-------- .../offered_services_info_test_local.json | 2 +- .../offered_services_info_test_service.cpp | 26 ++++++---- 6 files changed, 52 insertions(+), 34 deletions(-) diff --git a/CHANGES b/CHANGES index 65d6d86c8..26f14457e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,8 @@ Changes ======= +v2.10.10 +- Fix concurrency issue leading to a crash + v2.10.9 - Improve handling of service discovery messages with entries referencing too many options. diff --git a/CMakeLists.txt b/CMakeLists.txt index a9d9f4c1d..39d64aff8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ project (vsomeip) set (VSOMEIP_MAJOR_VERSION 2) set (VSOMEIP_MINOR_VERSION 10) -set (VSOMEIP_PATCH_VERSION 9) +set (VSOMEIP_PATCH_VERSION 10) set (VSOMEIP_VERSION ${VSOMEIP_MAJOR_VERSION}.${VSOMEIP_MINOR_VERSION}.${VSOMEIP_PATCH_VERSION}) set (PACKAGE_VERSION ${VSOMEIP_VERSION}) # Used in documentatin/doxygen.in set (CMAKE_VERBOSE_MAKEFILE off) diff --git a/implementation/routing/src/routing_manager_impl.cpp b/implementation/routing/src/routing_manager_impl.cpp index 544213464..e317e6d39 100644 --- a/implementation/routing/src/routing_manager_impl.cpp +++ b/implementation/routing/src/routing_manager_impl.cpp @@ -1953,7 +1953,10 @@ std::shared_ptr routing_manager_impl::create_remote_client( } if (its_endpoint) { - used_client_ports_[_reliable].insert(its_local_port); + { + std::lock_guard its_lock(used_client_ports_mutex_); + used_client_ports_[_reliable].insert(its_local_port); + } service_instances_[_service][its_endpoint.get()] = _instance; remote_services_[_service][_instance][_client][_reliable] = its_endpoint; if (_client == VSOMEIP_ROUTING_CLIENT) { diff --git a/test/offered_services_info_test/offered_services_info_test_client.cpp b/test/offered_services_info_test/offered_services_info_test_client.cpp index 13adc58fe..1aa080216 100644 --- a/test/offered_services_info_test/offered_services_info_test_client.cpp +++ b/test/offered_services_info_test/offered_services_info_test_client.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -76,13 +77,17 @@ class offered_services_info_test_client { std::bind(&offered_services_info_test_client::on_message, this, std::placeholders::_1)); - app_->register_availability_handler(service_info_.service_id, - service_info_.instance_id, + app_->register_availability_handler(vsomeip::ANY_SERVICE, + vsomeip::ANY_INSTANCE, std::bind(&offered_services_info_test_client::on_availability, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - app_->request_service(service_info_.service_id, - service_info_.instance_id); + // request all services + app_->request_service(service_info_.service_id, service_info_.instance_id); + app_->request_service(service_info_.service_id, vsomeip::instance_t(service_info_.instance_id + 1)); + app_->request_service(remote_service_info_.service_id, remote_service_info_.instance_id); + app_->request_service(vsomeip::service_t(remote_service_info_.service_id + 1), vsomeip::instance_t(remote_service_info_.instance_id + 1)); + app_->request_service(vsomeip::service_t(remote_service_info_.service_id + 2), vsomeip::instance_t(remote_service_info_.instance_id + 2)); app_->start(); } @@ -109,10 +114,14 @@ class offered_services_info_test_client { VSOMEIP_INFO << "Service [" << std::setw(4) << std::setfill('0') << std::hex << _service << "." << _instance << "] is " << (_is_available ? "available":"not available") << "."; + static int services_available =0; std::lock_guard its_lock(mutex_); if(_is_available) { - wait_until_service_available_ = false; - condition_.notify_one(); + services_available++; + if (services_available == 5) { + wait_until_service_available_ = false; + condition_.notify_one(); + } } else { wait_until_service_available_ = true; condition_.notify_one(); @@ -165,28 +174,16 @@ class offered_services_info_test_client { VSOMEIP_INFO << "TEST LOCAL SERVICES"; app_->get_offered_services_async(vsomeip::offer_type_e::OT_LOCAL, std::bind(&offered_services_info_test_client::on_offered_services_local, this, std::placeholders::_1)); - VSOMEIP_INFO << "TEST REMOTE SERVICES"; - app_->get_offered_services_async(vsomeip::offer_type_e::OT_REMOTE, std::bind(&offered_services_info_test_client::on_offered_services_remote, this, std::placeholders::_1)); - - VSOMEIP_INFO << "TEST ALL SERVICES"; - app_->get_offered_services_async(vsomeip::offer_type_e::OT_ALL, std::bind(&offered_services_info_test_client::on_offered_services_all, this, std::placeholders::_1)); - - // send shutdown command to service - bool send(false); - { - std::lock_guard its_lock(mutex_); - send = !wait_until_service_available_; - } - if (send) { + if (std::future_status::timeout == all_callbacks_received_.get_future().wait_for(std::chrono::seconds(15))) { + ADD_FAILURE() << "Didn't receive all callbacks within time"; + } else { std::shared_ptr its_req = vsomeip::runtime::get()->create_request(); its_req->set_service(service_info_.service_id); its_req->set_instance(service_info_.instance_id); its_req->set_method(service_info_.shutdown_method_id); app_->send(its_req); std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } else { - std::this_thread::sleep_for(std::chrono::milliseconds(50)); } @@ -201,6 +198,7 @@ class offered_services_info_test_client { void on_offered_services_local( const std::vector> &_services) { std::cout << "ON OFFERED SERVICES LOCAL CALLBACK START" << std::endl; + EXPECT_EQ(2u, _services.size()); bool local_service_test_failed(true); for (auto its_pair : _services) { local_service_test_failed = true; @@ -215,10 +213,13 @@ class offered_services_info_test_client { EXPECT_FALSE(local_service_test_failed); } std::cout << "ON OFFERED SERVICES LOCAL CALLBACK END" << std::endl; + VSOMEIP_INFO << "TEST REMOTE SERVICES"; + app_->get_offered_services_async(vsomeip::offer_type_e::OT_REMOTE, std::bind(&offered_services_info_test_client::on_offered_services_remote, this, std::placeholders::_1)); } void on_offered_services_remote( const std::vector> &_services) { std::cout << "ON OFFERED SERVICES REMOTE CALLBACK START" << std::endl; + EXPECT_EQ(3u, _services.size()); bool remote_service_test_failed(true); for (auto its_pair : _services) { remote_service_test_failed = true; @@ -233,10 +234,13 @@ class offered_services_info_test_client { EXPECT_FALSE(remote_service_test_failed); } std::cout << "ON OFFERED SERVICES REMOTE CALLBACK END" << std::endl; + VSOMEIP_INFO << "TEST ALL SERVICES"; + app_->get_offered_services_async(vsomeip::offer_type_e::OT_ALL, std::bind(&offered_services_info_test_client::on_offered_services_all, this, std::placeholders::_1)); } void on_offered_services_all( const std::vector> &_services) { std::cout << "ON OFFERED SERVICES ALL CALLBACK START" << std::endl; + EXPECT_EQ(5u, _services.size()); bool all_service_test_failed(true); for (auto its_pair : _services) { all_service_test_failed = true; @@ -251,6 +255,7 @@ class offered_services_info_test_client { EXPECT_FALSE(all_service_test_failed); } std::cout << "ON OFFERED SERVICES ALL CALLBACK END" << std::endl; + all_callbacks_received_.set_value(); } void wait_for_stop() { @@ -282,6 +287,7 @@ class offered_services_info_test_client { std::uint32_t last_received_counter_; std::chrono::steady_clock::time_point last_received_response_; std::atomic number_received_responses_; + std::promise all_callbacks_received_; std::thread stop_thread_; std::thread test_offered_services_thread_; }; diff --git a/test/offered_services_info_test/offered_services_info_test_local.json b/test/offered_services_info_test/offered_services_info_test_local.json index 768a7cac1..cb7db9256 100644 --- a/test/offered_services_info_test/offered_services_info_test_local.json +++ b/test/offered_services_info_test/offered_services_info_test_local.json @@ -3,7 +3,7 @@ "diagnosis":"0x12", "logging" : { - "level" : "debug", + "level" : "warning", "console" : "true", "file" : { diff --git a/test/offered_services_info_test/offered_services_info_test_service.cpp b/test/offered_services_info_test/offered_services_info_test_service.cpp index 0476f300f..d9a7ae4a6 100644 --- a/test/offered_services_info_test/offered_services_info_test_service.cpp +++ b/test/offered_services_info_test/offered_services_info_test_service.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -138,14 +139,9 @@ class offer_test_service { VSOMEIP_INFO << "TEST LOCAL SERVICES"; app_->get_offered_services_async(vsomeip::offer_type_e::OT_LOCAL, std::bind(&offer_test_service::on_offered_services_local, this, std::placeholders::_1)); - VSOMEIP_INFO << "TEST REMOTE SERVICES"; - app_->get_offered_services_async(vsomeip::offer_type_e::OT_REMOTE, std::bind(&offer_test_service::on_offered_services_remote, this, std::placeholders::_1)); - - VSOMEIP_INFO << "TEST ALL SERVICES"; - app_->get_offered_services_async(vsomeip::offer_type_e::OT_ALL, std::bind(&offer_test_service::on_offered_services_all, this, std::placeholders::_1)); - - VSOMEIP_DEBUG << "[" << std::setw(4) << std::setfill('0') << std::hex - << service_info_.service_id << "] Notifying"; + if (std::future_status::timeout == all_callbacks_received_.get_future().wait_for(std::chrono::seconds(15))) { + ADD_FAILURE() << "Didn't receive all callbacks within time"; + } while(!shutdown_method_called_) { std::this_thread::sleep_for(std::chrono::milliseconds(10)); @@ -155,6 +151,7 @@ class offer_test_service { void on_offered_services_local( const std::vector> &_services) { std::cout << "ON OFFERED SERVICES LOCAL CALLBACK START" << std::endl; + EXPECT_EQ(2u, _services.size()); bool local_service_test_failed(true); uint16_t i=0; for (auto its_pair : _services) { @@ -173,11 +170,15 @@ class offer_test_service { EXPECT_EQ(offer_test::num_local_offered_services, i); std::cout << "ON OFFERED SERVICES LOCAL CALLBACK END" << std::endl; + + VSOMEIP_INFO << "TEST REMOTE SERVICES"; + app_->get_offered_services_async(vsomeip::offer_type_e::OT_REMOTE, std::bind(&offer_test_service::on_offered_services_remote, this, std::placeholders::_1)); } void on_offered_services_remote( const std::vector> &_services) { std::cout << "ON OFFERED SERVICES REMOTE CALLBACK START" << std::endl; + EXPECT_EQ(3u, _services.size()); bool remote_service_test_failed(true); uint16_t i=0; for (auto its_pair : _services) { @@ -196,12 +197,15 @@ class offer_test_service { EXPECT_EQ(offer_test::num_remote_offered_services, i); std::cout << "ON OFFERED SERVICES REMOTE CALLBACK END" << std::endl; + + VSOMEIP_INFO << "TEST ALL SERVICES"; + app_->get_offered_services_async(vsomeip::offer_type_e::OT_ALL, std::bind(&offer_test_service::on_offered_services_all, this, std::placeholders::_1)); } void on_offered_services_all( const std::vector> &_services) { - std::cout << "ON OFFERED SERVICES ALL CALLBACK START" << std::endl; + EXPECT_EQ(5u, _services.size()); bool all_service_test_failed(true); uint16_t i=0; for (auto its_pair : _services) { @@ -219,6 +223,7 @@ class offer_test_service { } EXPECT_EQ(offer_test::num_all_offered_services, i); std::cout << "ON OFFERED SERVICES ALL CALLBACK END" << std::endl; + all_callbacks_received_.set_value(); } private: @@ -231,10 +236,11 @@ class offer_test_service { std::mutex mutex_; std::condition_variable condition_; std::atomic shutdown_method_called_; + std::promise all_callbacks_received_; std::thread offer_thread_; }; -TEST(someip_offer_test, notify_increasing_counter) +TEST(someip_offered_services_info_test, check_offered_services_as_rm_impl) { offer_test_service its_sample(offer_test::service, offer_test::remote_service); }