xref: /aosp_15_r20/external/grpc-grpc/src/objective-c/tests/run_one_test.sh (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1#!/bin/bash
2# Copyright 2019 gRPC authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# Don't run this script standalone. Instead, run from the repository root:
17# ./tools/run_tests/run_tests.py -l objc
18
19set -ex
20
21cd $(dirname $0)
22
23BAZEL=../../../tools/bazel
24
25INTEROP=../../../bazel-bin/test/cpp/interop/interop_server
26
27[ -d Tests.xcworkspace ] || {
28    ./build_tests.sh
29}
30
31[ -f $INTEROP ] || {
32    $BAZEL build //test/cpp/interop:interop_server
33}
34
35[ -z "$(ps aux |egrep 'port_server\.py.*-p\s32766')" ] && {
36    echo >&2 "Can't find the port server. Start port server with tools/run_tests/start_port_server.py."
37    exit 1
38}
39
40PLAIN_PORT=$(curl localhost:32766/get)
41TLS_PORT=$(curl localhost:32766/get)
42
43# start interop_server for plaintext and interop_server for TLS on random ports obtained
44# from the port server.
45$INTEROP --port=$PLAIN_PORT --max_send_message_size=8388608 &
46$INTEROP --port=$TLS_PORT --max_send_message_size=8388608 --use_tls &
47
48function finish {
49    kill -9 `jobs -p`
50    echo "EXIT TIME:  $(date)"
51}
52trap finish EXIT
53
54set -o pipefail  # preserve xcodebuild exit code when piping output
55
56if [ -z $PLATFORM ]; then
57DESTINATION='platform=iOS Simulator,name=iPhone 11'
58elif [ $PLATFORM == ios ]; then
59DESTINATION='platform=iOS Simulator,name=iPhone 11'
60elif [ $PLATFORM == macos ]; then
61DESTINATION='platform=macOS'
62elif [ $PLATFORM == tvos ]; then
63DESTINATION='platform=tvOS Simulator,name=Apple TV'
64fi
65
66XCODEBUILD_FLAGS="
67  IPHONEOS_DEPLOYMENT_TARGET=10
68"
69
70XCODEBUILD_FILTER_OUTPUT_SCRIPT="./xcodebuild_filter_output.sh"
71
72TEST_DEFS="HOST_PORT_LOCAL=localhost:$PLAIN_PORT \
73HOST_PORT_LOCALSSL=localhost:$TLS_PORT \
74HOST_PORT_REMOTE=grpc-test.sandbox.googleapis.com \
75GCC_OPTIMIZATION_LEVEL=s"
76
77time xcodebuild \
78    -workspace Tests.xcworkspace \
79    -scheme $SCHEME \
80    -destination "${DESTINATION}" \
81    GCC_PREPROCESSOR_DEFINITIONS='$GCC_PREPROCESSOR_DEFINITIONS'" $TEST_DEFS" \
82    test \
83    "${XCODEBUILD_FLAGS}" \
84    | "${XCODEBUILD_FILTER_OUTPUT_SCRIPT}"
85