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
13if [ $# -lt 1 ]
14then
15    echo "Please pass a json file and event reliability type to this script."
16    echo "For example: $0 UDP subscribe_notify_test_diff_client_ids_diff_ports_master.json"
17    echo "To use the same service id but different instances on the node pass SAME_SERVICE_ID as third parameter"
18    exit 1
19fi
20
21# replace master with slave to be able display the correct json file to be used
22# with the slave script
23RELIABILITY_TYPE=$1
24MASTER_JSON_FILE=$2
25SAME_SERVICE_ID=$3
26CLIENT_JSON_FILE=${MASTER_JSON_FILE/master/slave}
27
28FAIL=0
29
30# Start the services
31export VSOMEIP_APPLICATION_NAME=subscribe_notify_test_service_one
32export VSOMEIP_CONFIGURATION=$MASTER_JSON_FILE
33./subscribe_notify_test_service 1 $RELIABILITY_TYPE $3 &
34
35export VSOMEIP_APPLICATION_NAME=subscribe_notify_test_service_two
36export VSOMEIP_CONFIGURATION=$MASTER_JSON_FILE
37./subscribe_notify_test_service 2 $RELIABILITY_TYPE $3 &
38
39export VSOMEIP_APPLICATION_NAME=subscribe_notify_test_service_three
40export VSOMEIP_CONFIGURATION=$MASTER_JSON_FILE
41./subscribe_notify_test_service 3 $RELIABILITY_TYPE $3 &
42
43sleep 3
44
45if [ ! -z "$USE_LXC_TEST" ]; then
46    echo "starting subscribe_notify_test_slave_starter.sh on slave LXC with parameters $CLIENT_JSON_FILE $2"
47    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; ./subscribe_notify_test_slave_starter.sh $RELIABILITY_TYPE $CLIENT_JSON_FILE $3\"" &
48    echo "remote ssh job id: $!"
49elif [ ! -z "$USE_DOCKER" ]; then
50    docker exec $DOCKER_IMAGE sh -c "cd $DOCKER_TESTS && ./subscribe_notify_test_slave_starter.sh $RELIABILITY_TYPE $CLIENT_JSON_FILE $3" &
51elif [ ! -z "$JENKINS" ]; then
52    ssh -tt -i $PRV_KEY -o StrictHostKeyChecking=no jenkins@$IP_SLAVE "bash -ci \"set -m; cd $WS_ROOT/build/test; ./subscribe_notify_test_slave_starter.sh $RELIABILITY_TYPE $CLIENT_JSON_FILE $3\" >> $WS_ROOT/slave_test_output 2>&1" &
53
54else
55    cat <<End-of-message
56*******************************************************************************
57*******************************************************************************
58** Please now run:
59** subscribe_notify_test_slave_starter.sh $RELIABILITY_TYPE $CLIENT_JSON_FILE $3
60** from an external host to successfully complete this test.
61**
62** You probably will need to adapt the 'unicast' settings in
63** subscribe_notify_test_diff_client_ids_diff_ports_master.json and
64** subscribe_notify_test_diff_client_ids_diff_ports_slave.json to your personal setup.
65*******************************************************************************
66*******************************************************************************
67End-of-message
68fi
69
70if [ ! -z "$USE_DOCKER" ]; then
71  FAIL=0
72fi
73
74# Wait until client and service are finished
75for job in $(jobs -p)
76do
77    # Fail gets incremented if either client or service exit
78    # with a non-zero exit code
79    wait $job || ((FAIL+=1))
80done
81
82# Check if both exited successfully 
83if [ $FAIL -eq 0 ]
84then
85    exit 0
86else
87    exit 1
88fi
89