• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2# Copyright 2022 The 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
16set -ex
17
18# avoid slow finalization after the script has exited.
19source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc
20
21# change to grpc repo root
22cd $(dirname $0)/../../..
23
24source tools/internal_ci/helper_scripts/prepare_build_macos_rc
25
26# Make sure actions run by bazel can find python3.
27# Without this the build will fail with "env: python3: No such file or directory".
28# When on kokoro MacOS Mojave image.
29sudo ln -s $(which python3) /usr/bin/python3 || true
30
31# make sure bazel is available
32tools/bazel version
33
34# for kokoro mac workers, exact image version is store in a well-known location on disk
35KOKORO_IMAGE_VERSION="$(cat /VERSION)"
36
37BAZEL_REMOTE_CACHE_ARGS=(
38  # Enable uploading to remote cache. Requires the "roles/remotebuildexecution.actionCacheWriter" permission.
39  --remote_upload_local_results=true
40  # allow invalidating the old cache by setting to a new random key
41  --remote_default_exec_properties="grpc_cache_silo_key1=83d8e488-1ca9-40fd-929e-d37d13529c99"
42  # make sure we only get cache hits from binaries built on exact same macos image
43  --remote_default_exec_properties="grpc_cache_silo_key2=${KOKORO_IMAGE_VERSION}"
44)
45
46EXAMPLE_TARGETS=(
47  # TODO(jtattermusch): ideally we'd say "//src/objective-c/examples/..." but not all the targets currently build
48  //src/objective-c/examples:Sample
49  //src/objective-c/examples:tvOS-sample
50)
51
52TEST_TARGETS=(
53  # TODO(jtattermusch): ideally we'd say "//src/objective-c/tests/..." but not all the targets currently build
54  //src/objective-c/tests:InteropTestsLocalCleartext
55  //src/objective-c/tests:InteropTestsLocalSSL
56  //src/objective-c/tests:InteropTestsRemote
57  //src/objective-c/tests:MacTests
58  //src/objective-c/tests:UnitTests
59  # TODO: Enable this again once @CronetFramework is working
60  #//src/objective-c/tests:CppCronetTests
61  #//src/objective-c/tests:CronetTests
62  #//src/objective-c/tests:PerfTests
63  //src/objective-c/tests:CFStreamTests
64  # Needs oracle engine, which doesn't work with GRPC_IOS_EVENT_ENGINE_CLIENT=1
65  //src/objective-c/tests:EventEngineClientTests
66  //src/objective-c/tests:tvtests_build_test
67  # codegen plugin tests
68  //src/objective-c/tests:objc_codegen_plugin_test
69  //src/objective-c/tests:objc_codegen_plugin_option_test
70)
71
72# === BEGIN SECTION: run interop_server on the background ====
73# Before testing objC at all, build the interop server since many of the ObjC test rely on it.
74# Use remote cache to build the interop_server binary as quickly as possible (interop_server
75# is not what we want to test actually, we just use it as a backend for ObjC test).
76# TODO(jtattermusch): can we make ObjC test not depend on running a local interop_server?
77python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path build_interop_server
78build_interop_server/bazel_wrapper \
79  --bazelrc=tools/remote_build/mac.bazelrc \
80  build \
81  --google_credentials="${KOKORO_GFILE_DIR}/GrpcTesting-d0eeee2db331.json" \
82  "${BAZEL_REMOTE_CACHE_ARGS[@]}" \
83  -- \
84  //test/cpp/interop:interop_server
85
86# Start port server and allocate ports to run interop_server
87python3 tools/run_tests/start_port_server.py
88
89PLAIN_PORT=$(curl localhost:32766/get)
90TLS_PORT=$(curl localhost:32766/get)
91
92INTEROP_SERVER_BINARY=bazel-bin/test/cpp/interop/interop_server
93# run the interop server on the background. The port numbers must match TestConfigs in BUILD.
94# TODO(jtattermusch): can we make the ports configurable (but avoid breaking bazel build cache at the same time?)
95"${INTEROP_SERVER_BINARY}" --port=$PLAIN_PORT --max_send_message_size=8388608 &
96"${INTEROP_SERVER_BINARY}" --port=$TLS_PORT --max_send_message_size=8388608 --use_tls &
97# make sure the interop_server processes we started on the background are killed upon exit.
98trap 'echo "KILLING interop_server binaries running on the background"; kill -9 $(jobs -p)' EXIT
99# === END SECTION: run interop_server on the background ====
100
101# Environment variables that will be visible to objc tests.
102OBJC_TEST_ENV_ARGS=(
103  --test_env=HOST_PORT_LOCAL=localhost:$PLAIN_PORT
104  --test_env=HOST_PORT_LOCALSSL=localhost:$TLS_PORT
105)
106
107python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path objc_bazel_tests
108
109# NOTE: When using bazel to run the tests, test env variables like GRPC_VERBOSITY or GRPC_TRACE
110# seem to be correctly applied to the test environment even when running tests on a simulator.
111# The below configuration runs all the tests with --test_env=GRPC_VERBOSITY=debug, which makes
112# the test logs much more useful.
113objc_bazel_tests/bazel_wrapper \
114  --bazelrc=tools/remote_build/include/test_locally_with_resultstore_results.bazelrc \
115  test \
116  --google_credentials="${KOKORO_GFILE_DIR}/GrpcTesting-d0eeee2db331.json" \
117  "${BAZEL_REMOTE_CACHE_ARGS[@]}" \
118  $BAZEL_FLAGS \
119  "${OBJC_TEST_ENV_ARGS[@]}" \
120  -- \
121  "${EXAMPLE_TARGETS[@]}" \
122  "${TEST_TARGETS[@]}"
123
124
125# Enable event engine and run tests again.
126EVENT_ENGINE_TEST_TARGETS=(
127  //src/objective-c/tests:InteropTestsLocalCleartext
128  //src/objective-c/tests:InteropTestsLocalSSL
129  //src/objective-c/tests:InteropTestsRemote
130  //src/objective-c/tests:MacTests
131  //src/objective-c/tests:UnitTests
132  //src/objective-c/tests:EventEngineUnitTests
133  //src/objective-c/tests:tvtests_build_test
134)
135
136python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path objc_event_engine_bazel_tests
137
138objc_event_engine_bazel_tests/bazel_wrapper \
139  --bazelrc=tools/remote_build/include/test_locally_with_resultstore_results.bazelrc \
140  test \
141  --google_credentials="${KOKORO_GFILE_DIR}/GrpcTesting-d0eeee2db331.json" \
142  "${BAZEL_REMOTE_CACHE_ARGS[@]}" \
143  $BAZEL_FLAGS \
144  --cxxopt=-DGRPC_IOS_EVENT_ENGINE_CLIENT=1 \
145  --test_env=GRPC_EXPERIMENTS=event_engine_client \
146  --test_env=GRPC_VERBOSITY=debug --test_env=GRPC_TRACE=event_engine,api \
147  "${OBJC_TEST_ENV_ARGS[@]}" \
148  -- \
149  "${EXAMPLE_TARGETS[@]}" \
150  "${EVENT_ENGINE_TEST_TARGETS[@]}"
151