1#!/bin/bash
2# Copyright (C) 2015-2019 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 routing manager daemon and the
8# services with one command. This is necessary as ctest - which is used to run
9# the tests - isn't able to start multiple binaries for one testcase. Therefore
10# the testcase simply executes this script. This script then runs the routing
11# manager daemon and the services and checks if all of them exit successfully.
12
13FAIL=0
14
15if [ $# -lt 2 ]; then
16    echo "Error: Please pass a protocol and communication mode to this script."
17    echo "Valid protocols are [UDP,TCP]."
18    echo "Valid communication modes are [sync, async]."
19    echo "For example $> $0 UDP sync"
20    exit 1;
21fi
22
23start_services(){
24    export VSOMEIP_CONFIGURATION=npdu_test_service_npdu.json
25
26    # Start the routing manager daemon
27    export VSOMEIP_APPLICATION_NAME=npdu_test_routing_manager_daemon_service_side
28    ./npdu_test_rmd_service_side &
29
30    # sleep 1 second to let the RMD startup.
31    sleep 1
32
33    # Start service 1
34    export VSOMEIP_APPLICATION_NAME=npdu_test_service_one
35    ./npdu_test_service_1 $* &
36
37    # Start service 2
38    export VSOMEIP_APPLICATION_NAME=npdu_test_service_two
39    ./npdu_test_service_2 $* &
40
41    # Start service 3
42    export VSOMEIP_APPLICATION_NAME=npdu_test_service_three
43    ./npdu_test_service_3 $* &
44
45    # Start service 4
46    export VSOMEIP_APPLICATION_NAME=npdu_test_service_four
47    ./npdu_test_service_4 $* &
48}
49
50wait_for_bg_processes(){
51    # Wait until client and service are finished
52    for job in $(jobs -p)
53    do
54        # Fail gets incremented if one of the jobs exit
55        # with a non-zero exit code
56        wait $job || ((FAIL+=1))
57    done
58
59    # Check if everything exited successfully
60    if [ $FAIL -eq 0 ]
61    then
62        echo "All services exited successfully"
63    else
64        echo "Something went wrong"
65        exit 1
66    fi
67}
68
69
70start_services
71
72if [ ! -z "$USE_LXC_TEST" ]; then
73    echo "starting magic cookies test on slave LXC"
74    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; ./npdu_test_client_npdu_start.sh $*\"" &
75elif [ ! -z "$USE_DOCKER" ]; then
76    docker exec $DOCKER_IMAGE sh -c "cd $DOCKER_TESTS && ./npdu_test_client_npdu_start.sh $*" &
77elif [ ! -z "$JENKINS" ]; then
78    echo "starting npdu_test on slave Docker"
79    ssh -tt -i $PRV_KEY -o StrictHostKeyChecking=no jenkins@$IP_SLAVE "bash -ci \"set -m; cd $WS_ROOT/build/test; ./npdu_test_client_npdu_start.sh $*\" >> $WS_ROOT/slave_test_output 2>&1" &
80
81else
82sleep 1
83cat <<End-of-message
84*******************************************************************************
85*******************************************************************************
86** Please now run:
87** npdu_test_client_npdu_start.sh $*
88** from an external host to successfully complete this test.
89**
90** You probably will need to adapt the 'unicast' settings in
91** npdu_test_client_npdu.json and
92** npdu_test_service_npdu.json to your personal setup.
93*******************************************************************************
94*******************************************************************************
95End-of-message
96fi
97
98wait_for_bg_processes
99
100exit 0
101