• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 client and service with
8# one command. This is necessary as ctest - which is used to run the
9# tests - isn't able to start two binaries for one testcase. Therefore
10# the testcase simply executes this script. This script then runs client
11# and service and checks that both exit sucessfully.
12
13FAIL=0
14
15# Parameter 1: the pid to check
16check_tcp_udp_sockets_are_closed ()
17{
18    # Check that the service does not listen on any TCP/UDP socket
19    # or has any active connection via a TCP/UDP socket
20    # awk is used to avoid the case when a inode number is the same as a PID. The awk
21    # program filters the netstat output down to the protocol (1st field) and
22    # the PID/Program name (last field) fields.
23    SERVICE_SOCKETS_LISTENING=$(netstat -tulpen 2> /dev/null | awk '{print $1 "\t"  $NF}' | grep $1 | wc -l)
24    if [ $SERVICE_SOCKETS_LISTENING -ne 0 ]
25    then
26        ((FAIL+=1))
27    fi
28
29    SERVICE_SOCKETS_CONNECTED=$(netstat -tupen 2> /dev/null | awk '{print $1 "\t"  $NF}' | grep $1 | wc -l)
30    if [ $SERVICE_SOCKETS_CONNECTED -ne 0 ]
31    then
32        ((FAIL+=1))
33    fi
34}
35
36# Start the service
37export VSOMEIP_APPLICATION_NAME=local_routing_test_service
38if [ "$VSOMEIP_CONFIGURATION_SERVICE" != "" ]
39then
40    export VSOMEIP_CONFIGURATION=$VSOMEIP_CONFIGURATION_SERVICE
41else
42    export VSOMEIP_CONFIGURATION=local_routing_test_service.json
43fi
44./local_routing_test_service &
45SERIVCE_PID=$!
46sleep 1;
47
48check_tcp_udp_sockets_are_closed  $SERIVCE_PID
49
50# Start the client
51export VSOMEIP_APPLICATION_NAME=local_routing_test_client
52if [ "$VSOMEIP_CONFIGURATION_CLIENT" != "" ]
53then
54    export VSOMEIP_CONFIGURATION=$VSOMEIP_CONFIGURATION_CLIENT
55else
56    export VSOMEIP_CONFIGURATION=local_routing_test_client.json
57fi
58./local_routing_test_client &
59CLIENT_PID=$!
60
61check_tcp_udp_sockets_are_closed  $SERIVCE_PID
62check_tcp_udp_sockets_are_closed  $CLIENT_PID
63
64# Wait until client and service are finished
65for job in $(jobs -p)
66do
67    # Fail gets incremented if either client or service exit
68    # with a non-zero exit code
69    wait $job || ((FAIL+=1))
70done
71
72# Check if client and server both exited successfully and the service didnt't
73# have any open
74if [ $FAIL -eq 0 ]
75then
76    exit 0
77else
78    exit 1
79fi
80