1#!/bin/bash 2# Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) 3# This Source Code Form is subject to the terms of the Mozilla Public 4# License, v. 2.0. If a copy of the MPL was not distributed with this 5# file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 7# Purpose: This script is needed to start the services with 8# one command. This is necessary as ctest - which is used to run the 9# tests - isn't able to start multiple binaries for one testcase. Therefore 10# the testcase simply executes this script. This script then runs the services 11# and checks that all exit successfully. 12 13FAIL=0 14# Rejecting offer for which there is already a remote offer: 15# * start daemon 16# * start application which offers service 17# * start daemon remotely 18# * start same application which offers the same service again remotely 19# -> should be rejected as there is already a service instance 20# running in the network 21 22# Array for client pids 23CLIENT_PIDS=() 24export VSOMEIP_CONFIGURATION=offer_test_external_master.json 25# start daemon 26../examples/routingmanagerd/./routingmanagerd & 27PID_VSOMEIPD=$! 28# Start the services 29./offer_test_service 2 & 30PID_SERVICE_TWO=$! 31echo "SERVICE_TWO pid $PID_SERVICE_TWO" 32 33./offer_test_client SUBSCRIBE & 34CLIENT_PIDS+=($!) 35echo "client pid ${CLIENT_PIDS[0]}" 36 37# Wait until all clients are finished 38for job in ${CLIENT_PIDS[*]} 39do 40 # Fail gets incremented if a client exits with a non-zero exit code 41 wait $job || FAIL=$(($FAIL+1)) 42done 43 44if [ ! -z "$USE_LXC_TEST" ]; then 45 echo "starting offer test on slave LXC offer_test_external_slave_starter.sh" 46 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\"" & 47elif [ ! -z "$USE_DOCKER" ]; then 48 docker exec $DOCKER_IMAGE sh -c "cd $DOCKER_TESTS; ./offer_test_external_slave_starter.sh" & 49elif [ ! -z "$JENKINS" ]; then 50 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" & 51else 52cat <<End-of-message 53******************************************************************************* 54******************************************************************************* 55** Please now run: 56** offer_test_external_slave_starter.sh 57** from an external host to successfully complete this test. 58** 59** You probably will need to adapt the 'unicast' settings in 60** offer_test_external_master.json and 61** offer_test_external_slave.json to your personal setup. 62******************************************************************************* 63******************************************************************************* 64End-of-message 65fi 66 67# Wait until all clients and services are finished 68for job in ${CLIENT_PIDS[*]} $PID_SERVICE_TWO 69do 70 # Fail gets incremented if a client exits with a non-zero exit code 71 echo "waiting for $job" 72 wait $job || FAIL=$(($FAIL+1)) 73done 74 75# kill the services 76kill $PID_VSOMEIPD 77sleep 1 78 79# wait for slave to finish 80for job in $(jobs -p) 81do 82 # Fail gets incremented if either client or service exit 83 # with a non-zero exit code 84 echo "[Master] waiting for job $job" 85 wait $job || ((FAIL+=1)) 86done 87 88# Rejecting remote offer for which there is already a local offer 89# * start application which offers service 90# * send sd message trying to offer the same service instance as already 91# offered locally from a remote host 92 93# Array for client pids 94CLIENT_PIDS=() 95export VSOMEIP_CONFIGURATION=offer_test_external_master.json 96# start daemon 97../examples/routingmanagerd/./routingmanagerd & 98PID_VSOMEIPD=$! 99# Start the services 100./offer_test_service 2 & 101PID_SERVICE_TWO=$! 102 103./offer_test_client SUBSCRIBE & 104CLIENT_PIDS+=($!) 105echo "client pid ${CLIENT_PIDS[0]}" 106# Wait until all clients and services are finished 107for job in ${CLIENT_PIDS[*]} 108do 109 # Fail gets incremented if a client exits with a non-zero exit code 110 wait $job || FAIL=$(($FAIL+1)) 111done 112 113 114if [ ! -z "$USE_LXC_TEST" ]; then 115 echo "starting offer test on slave LXC offer_test_external_sd_msg_sender" 116 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\"" & 117 echo "remote ssh job id: $!" 118elif [ ! -z "$USE_DOCKER" ]; then 119 docker exec $DOCKER_IMAGE sh -c "cd $DOCKER_TESTS; ./offer_test_external_slave_sd_starter.sh $DOCKER_IP" & 120elif [ ! -z "$JENKINS" ]; then 121 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" & 122else 123cat <<End-of-message 124******************************************************************************* 125******************************************************************************* 126** Please now run: 127** offer_test_external_sd_msg_sender @TEST_IP_MASTER@ 128** (pass the correct ip address of your test master) 129** from an external host to successfully complete this test. 130** 131******************************************************************************* 132******************************************************************************* 133End-of-message 134fi 135 136# Wait until all clients and services are finished 137for job in ${CLIENT_PIDS[*]} $PID_SERVICE_TWO 138do 139 # Fail gets incremented if a client exits with a non-zero exit code 140 echo "waiting for $job" 141 wait $job || FAIL=$(($FAIL+1)) 142done 143 144# kill the services 145kill $PID_VSOMEIPD 146 147# wait for slave to finish 148for job in $(jobs -p) 149do 150 # Fail gets incremented if either client or service exit 151 # with a non-zero exit code 152 echo "[Master] waiting for job $job" 153 wait $job || ((FAIL+=1)) 154done 155 156# Check if everything went well 157if [ $FAIL -eq 0 ] 158then 159 exit 0 160else 161 exit 1 162fi 163