| 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 |
|
| 16 |
set -ex |
| 17 |
|
| 18 |
# avoid slow finalization after the script has exited. |
| 19 |
source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc |
| 20 |
|
| 21 |
# change to grpc repo root |
| 22 |
cd $(dirname $0)/../../.. |
| 23 |
|
| 24 |
source 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. |
| 29 |
sudo ln -s $(which python3) /usr/bin/python3 || true |
| 30 |
|
| 31 |
# make sure bazel is available |
| 32 |
tools/bazel version |
| 33 |
|
| 34 |
# for kokoro mac workers, exact image version is store in a well-known location on disk |
| 35 |
KOKORO_IMAGE_VERSION="$(cat /VERSION)" |
| 36 |
|
| 37 |
BAZEL_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 |
|
| 46 |
EXAMPLE_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 |
|
| 52 |
TEST_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 |
//src/objective-c/tests:CronetTests |
| 60 |
//src/objective-c/tests:PerfTests |
| 61 |
//src/objective-c/tests:tvtests_build_test |
| 62 |
# codegen plugin tests |
| 63 |
//src/objective-c/tests:objc_codegen_plugin_test |
| 64 |
//src/objective-c/tests:objc_codegen_plugin_option_test |
| 65 |
) |
| 66 |
|
| 67 |
# === BEGIN SECTION: run interop_server on the background ==== |
| 68 |
# Before testing objC at all, build the interop server since many of the ObjC test rely on it. |
| 69 |
# Use remote cache to build the interop_server binary as quickly as possible (interop_server |
| 70 |
# is not what we want to test actually, we just use it as a backend for ObjC test). |
| 71 |
# TODO(jtattermusch): can we make ObjC test not depend on running a local interop_server? |
| 72 |
python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path build_interop_server |
| 73 |
build_interop_server/bazel_wrapper \ |
| 74 |
--bazelrc=tools/remote_build/mac.bazelrc \ |
| 75 |
build \ |
| 76 |
--google_credentials="${KOKORO_GFILE_DIR}/GrpcTesting-d0eeee2db331.json" \ |
| 77 |
"${BAZEL_REMOTE_CACHE_ARGS[@]}" \ |
| 78 |
-- \ |
| 79 |
//test/cpp/interop:interop_server |
| 80 |
|
| 81 |
# Start port server and allocate ports to run interop_server |
| 82 |
python3 tools/run_tests/start_port_server.py |
| 83 |
|
| 84 |
PLAIN_PORT=$(curl localhost:32766/get) |
| 85 |
TLS_PORT=$(curl localhost:32766/get) |
| 86 |
|
| 87 |
INTEROP_SERVER_BINARY=bazel-bin/test/cpp/interop/interop_server |
| 88 |
# run the interop server on the background. The port numbers must match TestConfigs in BUILD. |
| 89 |
# TODO(jtattermusch): can we make the ports configurable (but avoid breaking bazel build cache at the same time?) |
| 90 |
"${INTEROP_SERVER_BINARY}" --port=$PLAIN_PORT --max_send_message_size=8388608 & |
| 91 |
"${INTEROP_SERVER_BINARY}" --port=$TLS_PORT --max_send_message_size=8388608 --use_tls & |
| 92 |
# make sure the interop_server processes we started on the background are killed upon exit. |
| 93 |
trap 'echo "KILLING interop_server binaries running on the background"; kill -9 $(jobs -p)' EXIT |
| 94 |
# === END SECTION: run interop_server on the background ==== |
| 95 |
|
| 96 |
# Environment variables that will be visible to objc tests. |
| 97 |
OBJC_TEST_ENV_ARGS=( |
| 98 |
--test_env=HOST_PORT_LOCAL=localhost:$PLAIN_PORT |
| 99 |
--test_env=HOST_PORT_LOCALSSL=localhost:$TLS_PORT |
| 100 |
) |
| 101 |
|
| 102 |
python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path objc_bazel_tests |
| 103 |
|
| 104 |
# NOTE: When using bazel to run the tests, test env variables like GRPC_VERBOSITY or GRPC_TRACE |
| 105 |
# seem to be correctly applied to the test environment even when running tests on a simulator. |
| 106 |
# The below configuration runs all the tests with --test_env=GRPC_VERBOSITY=debug, which makes |
| 107 |
# the test logs much more useful. |
| 108 |
objc_bazel_tests/bazel_wrapper \ |
| 109 |
--bazelrc=tools/remote_build/include/test_locally_with_resultstore_results.bazelrc \ |
| 110 |
test \ |
| 111 |
--google_credentials="${KOKORO_GFILE_DIR}/GrpcTesting-d0eeee2db331.json" \ |
| 112 |
"${BAZEL_REMOTE_CACHE_ARGS[@]}" \ |
| 113 |
$BAZEL_FLAGS \ |
| 114 |
"${OBJC_TEST_ENV_ARGS[@]}" \ |
| 115 |
-- \ |
| 116 |
"${EXAMPLE_TARGETS[@]}" \ |
| 117 |
"${TEST_TARGETS[@]}" |