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 36export VSOMEIP_CONFIGURATION=local_routing_test_service.json 37# start daemon 38../examples/routingmanagerd/./routingmanagerd & 39PID_VSOMEIPD=$! 40 41WAIT_PIDS=() 42# Start the service 43export VSOMEIP_APPLICATION_NAME=local_routing_test_service 44./local_routing_test_service & 45SERIVCE_PID=$! 46WAIT_PIDS+=($!) 47sleep 1; 48 49check_tcp_udp_sockets_are_closed $SERIVCE_PID 50 51# Start the client 52export VSOMEIP_APPLICATION_NAME=local_routing_test_client 53export VSOMEIP_CONFIGURATION=local_routing_test_client.json 54./local_routing_test_client & 55CLIENT_PID=$! 56WAIT_PIDS+=($!) 57 58check_tcp_udp_sockets_are_closed $SERIVCE_PID 59check_tcp_udp_sockets_are_closed $CLIENT_PID 60 61# Wait until client and service are finished 62for job in ${WAIT_PIDS[*]} 63do 64 # Fail gets incremented if either client or service exit 65 # with a non-zero exit code 66 wait $job || ((FAIL+=1)) 67done 68 69kill $PID_VSOMEIPD 70sleep 1 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