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 to this script."
16    echo "For example: $0 client_id_test_diff_client_ids_diff_ports_master.json"
17    exit 1
18fi
19
20MASTER_JSON_FILE=$1
21CLIENT_JSON_FILE=${MASTER_JSON_FILE/master/slave}
22
23FAIL=0
24
25# Start the services
26export VSOMEIP_APPLICATION_NAME=client_id_test_service_one
27export VSOMEIP_CONFIGURATION=$1
28./client_id_test_service 1 &
29CLIENT_ID_PIDS[1]=$!
30
31export VSOMEIP_APPLICATION_NAME=client_id_test_service_two
32export VSOMEIP_CONFIGURATION=$1
33./client_id_test_service 2 &
34CLIENT_ID_PIDS[2]=$!
35
36export VSOMEIP_APPLICATION_NAME=client_id_test_service_three
37export VSOMEIP_CONFIGURATION=$1
38./client_id_test_service 3 &
39CLIENT_ID_PIDS[3]=$!
40
41sleep 1
42
43if [ ! -z "$USE_LXC_TEST" ]; then
44    echo "starting client id test on slave LXC"
45    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; ./client_id_test_slave_starter.sh $CLIENT_JSON_FILE\"" &
46elif [ ! -z "$USE_DOCKER" ]; then
47    docker exec $DOCKER_IMAGE sh -c "cd $DOCKER_TESTS && ./client_id_test_slave_starter.sh $CLIENT_JSON_FILE" &
48elif [ ! -z "$JENKINS" ]; then
49    ssh -tt -i $PRV_KEY -o StrictHostKeyChecking=no jenkins@$IP_SLAVE "bash -ci \"set -m; cd $WS_ROOT/build/test; ./client_id_test_slave_starter.sh $CLIENT_JSON_FILE\" >> $WS_ROOT/slave_test_output 2>&1" &
50
51else
52cat <<End-of-message
53*******************************************************************************
54*******************************************************************************
55** Please now run:
56** client_id_test_slave_starter.sh $CLIENT_JSON_FILE
57** from an external host to successfully complete this test.
58**
59** You probably will need to adapt the 'unicast' settings in
60** client_id_test_diff_client_ids_diff_ports_master.json and
61** client_id_test_diff_client_ids_diff_ports_slave.json to your personal setup.
62*******************************************************************************
63*******************************************************************************
64End-of-message
65fi
66
67# Wait until client and service are finished
68for client_pid in "${CLIENT_ID_PIDS[@]}"
69do
70    if [ -n "$client_pid" ]; then
71        # Fail gets incremented if either client or service exit
72        # with a non-zero exit code
73        wait "$client_pid" || ((FAIL+=1))
74    fi
75done
76
77# Check if both exited successfully 
78if [ $FAIL -eq 0 ]
79then
80    exit 0
81else
82    exit 1
83fi
84