summaryrefslogtreecommitdiff
path: root/test/offer_tests
diff options
context:
space:
mode:
Diffstat (limited to 'test/offer_tests')
-rwxr-xr-xtest/offer_tests/conf/offer_test_big_sd_msg_master_starter.sh.in4
-rwxr-xr-xtest/offer_tests/conf/offer_test_external_master_starter.sh.in34
-rw-r--r--test/offer_tests/offer_test_external_sd_msg_sender.cpp24
-rwxr-xr-xtest/offer_tests/offer_test_external_slave_sd_starter.sh38
-rw-r--r--test/offer_tests/offer_test_service_availability_checker.cpp118
5 files changed, 200 insertions, 18 deletions
diff --git a/test/offer_tests/conf/offer_test_big_sd_msg_master_starter.sh.in b/test/offer_tests/conf/offer_test_big_sd_msg_master_starter.sh.in
index 07d4079..53f6a2c 100755
--- a/test/offer_tests/conf/offer_test_big_sd_msg_master_starter.sh.in
+++ b/test/offer_tests/conf/offer_test_big_sd_msg_master_starter.sh.in
@@ -33,6 +33,10 @@ elif [ ! -z "$USE_DOCKER" ]; then
echo "Waiting for 5s"
sleep 5
docker exec $DOCKER_IMAGE sh -c "cd $DOCKER_TESTS && sleep 10; ./offer_test_big_sd_msg_slave_starter.sh" &
+elif [ ! -z "$JENKINS" ]; then
+ echo "Waiting for 5s"
+ sleep 5
+ ssh -tt -i $PRV_KEY -o StrictHostKeyChecking=no jenkins@$IP_SLAVE "bash -ci \"set -m; cd $WS_ROOT/build/test; ./offer_test_big_sd_msg_slave_starter.sh\" >> $WS_ROOT/slave_test_output 2>&1" &
else
cat <<End-of-message
*******************************************************************************
diff --git a/test/offer_tests/conf/offer_test_external_master_starter.sh.in b/test/offer_tests/conf/offer_test_external_master_starter.sh.in
index 272689a..2a27a3f 100755
--- a/test/offer_tests/conf/offer_test_external_master_starter.sh.in
+++ b/test/offer_tests/conf/offer_test_external_master_starter.sh.in
@@ -34,18 +34,20 @@ echo "SERVICE_TWO pid $PID_SERVICE_TWO"
CLIENT_PIDS+=($!)
echo "client pid ${CLIENT_PIDS[0]}"
-sleep 1
+# Wait until all clients are finished
+for job in ${CLIENT_PIDS[*]}
+do
+ # Fail gets incremented if a client exits with a non-zero exit code
+ wait $job || FAIL=$(($FAIL+1))
+done
if [ ! -z "$USE_LXC_TEST" ]; then
- echo "Waiting for 5s"
- sleep 5
echo "starting offer test on slave LXC offer_test_external_slave_starter.sh"
ssh -tt -i $SANDBOX_ROOT_DIR/commonapi_main/lxc-config/.ssh/mgc_lxc/rsa_key_file.pub -o StrictHostKeyChecking=no root@$LXC_TEST_SLAVE_IP "bash -ci \"set -m; cd \\\$SANDBOX_TARGET_DIR/vsomeip_lib/test; ./offer_test_external_slave_starter.sh\"" &
- echo "remote ssh pid: $!"
elif [ ! -z "$USE_DOCKER" ]; then
- echo "Waiting for 5s"
- sleep 5
- docker exec $DOCKER_IMAGE sh -c "cd $DOCKER_TESTS && sleep 10; ./offer_test_external_slave_starter.sh" &
+ docker exec $DOCKER_IMAGE sh -c "cd $DOCKER_TESTS; ./offer_test_external_slave_starter.sh" &
+elif [ ! -z "$JENKINS" ]; then
+ ssh -tt -i $PRV_KEY -o StrictHostKeyChecking=no jenkins@$IP_SLAVE "bash -ci \"set -m; cd $WS_ROOT/build/test ; ./offer_test_external_slave_starter.sh\" >> $WS_ROOT/slave_test_output 2>&1" &
else
cat <<End-of-message
*******************************************************************************
@@ -101,19 +103,22 @@ PID_SERVICE_TWO=$!
./offer_test_client SUBSCRIBE &
CLIENT_PIDS+=($!)
echo "client pid ${CLIENT_PIDS[0]}"
+# Wait until all clients and services are finished
+for job in ${CLIENT_PIDS[*]}
+do
+ # Fail gets incremented if a client exits with a non-zero exit code
+ wait $job || FAIL=$(($FAIL+1))
+done
-sleep 1
if [ ! -z "$USE_LXC_TEST" ]; then
- echo "Waiting for 5s"
- sleep 5
echo "starting offer test on slave LXC offer_test_external_sd_msg_sender"
- ssh -tt -i $SANDBOX_ROOT_DIR/commonapi_main/lxc-config/.ssh/mgc_lxc/rsa_key_file.pub -o StrictHostKeyChecking=no root@$LXC_TEST_SLAVE_IP "bash -ci \"set -m; cd \\\$SANDBOX_TARGET_DIR/vsomeip_lib/test; ./offer_test_external_sd_msg_sender $LXC_TEST_MASTER_IP\"" &
+ ssh -tt -i $SANDBOX_ROOT_DIR/commonapi_main/lxc-config/.ssh/mgc_lxc/rsa_key_file.pub -o StrictHostKeyChecking=no root@$LXC_TEST_SLAVE_IP "bash -ci \"set -m; cd \\\$SANDBOX_TARGET_DIR/vsomeip_lib/test; ./offer_test_external_slave_sd_starter.sh $LXC_TEST_MASTER_IP\"" &
echo "remote ssh job id: $!"
elif [ ! -z "$USE_DOCKER" ]; then
- echo "Waiting for 5s"
- sleep 5
- docker exec $DOCKER_IMAGE sh -c "cd $DOCKER_TESTS && sleep 10; ./offer_test_external_sd_msg_sender $DOCKER_IP" &
+ docker exec $DOCKER_IMAGE sh -c "cd $DOCKER_TESTS; ./offer_test_external_slave_sd_starter.sh $DOCKER_IP" &
+elif [ ! -z "$JENKINS" ]; then
+ ssh -tt -i $PRV_KEY -o StrictHostKeyChecking=no jenkins@$IP_SLAVE "bash -ci \"set -m; cd $WS_ROOT/build/test; ./offer_test_external_slave_sd_starter.sh @TEST_IP_MASTER@ \" >> $WS_ROOT/slave_test_output 2>&1" &
else
cat <<End-of-message
*******************************************************************************
@@ -138,7 +143,6 @@ done
# kill the services
kill $PID_VSOMEIPD
-sleep 1
# wait for slave to finish
for job in $(jobs -p)
diff --git a/test/offer_tests/offer_test_external_sd_msg_sender.cpp b/test/offer_tests/offer_test_external_sd_msg_sender.cpp
index 6849b95..cc75b8d 100644
--- a/test/offer_tests/offer_test_external_sd_msg_sender.cpp
+++ b/test/offer_tests/offer_test_external_sd_msg_sender.cpp
@@ -15,11 +15,26 @@ TEST(someip_offer_test, send_offer_service_sd_message)
{
try {
boost::asio::io_service io;
+ boost::system::error_code ec;
boost::asio::ip::udp::socket::endpoint_type target_sd(
boost::asio::ip::address::from_string(std::string(passed_address)),
30490);
- boost::asio::ip::udp::socket udp_socket(io,
- boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 30490));
+
+ boost::asio::ip::udp::socket udp_socket(io);
+
+ boost::asio::ip::udp::endpoint rx_endpoint_(boost::asio::ip::udp::v4(), 30490);
+ udp_socket.open(rx_endpoint_.protocol(), ec);
+
+ if(ec)
+ std::cout <<" udp_socket open create error "<<std::endl;
+
+ boost::asio::socket_base::reuse_address optionReuseAddress(true);
+ udp_socket.set_option(optionReuseAddress, ec);
+ udp_socket.bind(boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 30490), ec);
+ if(ec)
+ std::cout <<" udp_socket BIND error "<<std::endl;
+
+ boost::asio::detail::throw_error(ec);
std::uint8_t its_offer_service_message[] = {
0xff, 0xff, 0x81, 0x00,
0x00, 0x00, 0x00, 0x3c,
@@ -39,6 +54,7 @@ TEST(someip_offer_test, send_offer_service_sd_message)
0x0a, 0x00, 0x03, 0x7D, // slave address
0x00, 0x11, 0x75, 0x31
};
+
for (int var = 0; var < 15; ++var) {
udp_socket.send_to(boost::asio::buffer(its_offer_service_message), target_sd);
++its_offer_service_message[11];
@@ -53,8 +69,10 @@ TEST(someip_offer_test, send_offer_service_sd_message)
boost::asio::ip::udp::socket::endpoint_type target_service(
boost::asio::ip::address::from_string(std::string(passed_address)),
30001);
+
udp_socket.send_to(boost::asio::buffer(shutdown_call), target_service);
- } catch (...) {
+ } catch (const std::exception& e) {
+ std::cout << e.what() << std::endl;
ASSERT_FALSE(true);
}
}
diff --git a/test/offer_tests/offer_test_external_slave_sd_starter.sh b/test/offer_tests/offer_test_external_slave_sd_starter.sh
new file mode 100755
index 0000000..8e30086
--- /dev/null
+++ b/test/offer_tests/offer_test_external_slave_sd_starter.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+# Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+FAIL=0
+# Rejecting offer for which there is already a remote offer:
+# * start daemon
+# * start application which offers service
+# * start daemon remotely
+# * start same application which offers the same service again remotely
+# -> should be rejected as there is already a service instance
+# running in the network
+
+export VSOMEIP_CONFIGURATION=offer_test_external_slave.json
+# start daemon
+../examples/routingmanagerd/./routingmanagerd &
+PID_VSOMEIPD=$!
+
+echo "calling availabiliy checker"
+
+./offer_test_service_availability_checker &
+
+PID_AVAILABILITY_CHECKER=$!
+
+echo "waiting for offer_test_service_availability_checker"
+
+# wait until the services on the remote node were started as well
+wait $PID_AVAILABILITY_CHECKER
+
+# kill the routing manager services
+kill $PID_VSOMEIPD
+
+./offer_test_external_sd_msg_sender $1 &
+
+
+
diff --git a/test/offer_tests/offer_test_service_availability_checker.cpp b/test/offer_tests/offer_test_service_availability_checker.cpp
new file mode 100644
index 0000000..3cef64f
--- /dev/null
+++ b/test/offer_tests/offer_test_service_availability_checker.cpp
@@ -0,0 +1,118 @@
+// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <chrono>
+#include <condition_variable>
+#include <iomanip>
+#include <iostream>
+#include <sstream>
+#include <thread>
+#include <map>
+#include <algorithm>
+
+#include <gtest/gtest.h>
+
+#include <vsomeip/vsomeip.hpp>
+#include <vsomeip/internal/logger.hpp>
+
+#include "offer_test_globals.hpp"
+
+
+class offer_test_service_availability_checker {
+public:
+ offer_test_service_availability_checker(struct offer_test::service_info _service_info) :
+ service_info_(_service_info),
+ app_(vsomeip::runtime::get()->create_application()),
+ wait_until_registered_(true),
+ wait_for_stop_(true),
+ stop_thread_(std::bind(&offer_test_service_availability_checker::wait_for_stop, this)) {
+ if (!app_->init()) {
+ ADD_FAILURE() << "Couldn't initialize application";
+ return;
+ }
+ app_->register_state_handler(
+ std::bind(&offer_test_service_availability_checker::on_state, this,
+ std::placeholders::_1));
+
+ // register availability for all other services and request their event.
+ app_->register_availability_handler(service_info_.service_id,
+ service_info_.instance_id,
+ std::bind(&offer_test_service_availability_checker::on_availability, this,
+ std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3));
+ app_->request_service(service_info_.service_id,
+ service_info_.instance_id);
+
+ app_->start();
+ }
+
+ ~offer_test_service_availability_checker() {
+ stop_thread_.join();
+ }
+
+ void on_state(vsomeip::state_type_e _state) {
+ VSOMEIP_INFO << "MY Application " << app_->get_name() << " is "
+ << (_state == vsomeip::state_type_e::ST_REGISTERED ?
+ "registered." : "deregistered.");
+
+ if (_state == vsomeip::state_type_e::ST_REGISTERED) {
+ std::lock_guard<std::mutex> its_lock(mutex_);
+ wait_until_registered_ = false;
+ condition_.notify_one();
+ }
+ }
+
+ void on_availability(vsomeip::service_t _service,
+ vsomeip::instance_t _instance, bool _is_available) {
+ VSOMEIP_INFO << "MY Service [" << std::setw(4)
+ << std::setfill('0') << std::hex << _service << "." << _instance
+ << "] is " << (_is_available ? "available":"not available") << ".";
+ std::lock_guard<std::mutex> its_lock(mutex_);
+ if(_is_available) {
+ wait_for_stop_ = false;
+ stop_condition_.notify_one();
+ }
+ }
+
+ void wait_for_stop() {
+ VSOMEIP_INFO << " MY offer_test_service_availability_check wait_for_stop() ";
+ std::unique_lock<std::mutex> its_lock(stop_mutex_);
+ while (wait_for_stop_) {
+ stop_condition_.wait(its_lock);
+ }
+ //VSOMEIP_INFO << "[" << std::setw(4) << std::setfill('0') << std::hex
+ // << client_number_ << "] all services are available. Going down";
+ VSOMEIP_INFO << " MY offer_test_service_availability_check is going down ";
+ app_->clear_all_handler();
+ app_->stop();
+ }
+
+private:
+ struct offer_test::service_info service_info_;
+ std::shared_ptr<vsomeip::application> app_;
+
+ bool wait_until_registered_;
+ std::mutex mutex_;
+ std::condition_variable condition_;
+
+ bool wait_for_stop_;
+ std::mutex stop_mutex_;
+ std::condition_variable stop_condition_;
+ std::thread stop_thread_;
+};
+
+TEST(someip_offer_test_external, wait_for_availability_and_exit)
+{
+ offer_test_service_availability_checker its_sample(
+ offer_test::service);
+}
+
+#ifndef _WIN32
+int main(int argc, char** argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+#endif