xref: /aosp_15_r20/external/grpc-grpc/test/distrib/bazel/test_single_bazel_version.sh (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1#!/usr/bin/env bash
2# Copyright 2021 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
18if [ "$#" == "0" ] ; then
19    echo "Must supply bazel version to be tested." >/dev/stderr
20    exit 1
21fi
22
23VERSION="$1"
24shift 1
25
26# directories under test/distrib/bazel/ to test.
27TEST_DIRECTORIES=(
28  "cpp"
29  "python"
30)
31# construct list of all supported test shards
32ALL_TEST_SHARDS=("buildtest")
33for TEST_DIRECTORY in "${TEST_DIRECTORIES[@]}"
34do
35  ALL_TEST_SHARDS+=("distribtest_${TEST_DIRECTORY}")
36done
37
38# Read list of shards to run from the commandline args.
39# If ther are no args, run all the shards.
40if [ "$#" != "0" ]
41then
42  # Use remaining commandline args as test shard names.
43  TEST_SHARDS=("$@")
44else
45  # Run all supported shards.
46  TEST_SHARDS=("${ALL_TEST_SHARDS[@]}")
47fi
48
49cd "$(dirname "$0")"/../../..
50
51EXCLUDED_TARGETS=(
52  # iOS platform fails the analysis phase since there is no toolchain available
53  # for it.
54  "-//src/objective-c/..."
55  "-//third_party/objective_c/..."
56
57  # Targets here need C++17 to build via a different configuration, so this is
58  # done separately
59  "-//fuzztest/..."
60
61  # This could be a legitmate failure due to bitrot.
62  "-//src/proto/grpc/testing:test_gen_proto"
63
64  # Analyzing windows toolchains when running on linux results in an error.
65  # Since bazel distribtests are run on linux, we exclude the windows RBE toolchains.
66  "-//third_party/toolchains/rbe_windows_bazel_6.3.2_vs2019/..."
67  "-//third_party/toolchains:rbe_windows_default_toolchain_suite"
68
69  # TODO(jtattermusch): add back once fixed
70  "-//examples/android/binder/..."
71
72  # Exclude bazelified tests as they contain some bazel hackery
73  "-//tools/bazelify_tests/..."
74)
75
76FAILED_TESTS=""
77
78export OVERRIDE_BAZEL_VERSION="$VERSION"
79# when running under bazel docker image, the workspace is read only.
80export OVERRIDE_BAZEL_WRAPPER_DOWNLOAD_DIR=/tmp
81
82ACTION_ENV_FLAG="--action_env=bazel_cache_invalidate=version_${VERSION}"
83
84for TEST_SHARD in "${TEST_SHARDS[@]}"
85do
86  SHARD_RAN=""
87  if [ "${TEST_SHARD}" == "buildtest" ] ; then
88    tools/bazel version | grep "$VERSION" || { echo "Detected bazel version did not match expected value of $VERSION" >/dev/stderr; exit 1; }
89    tools/bazel build "${ACTION_ENV_FLAG}" --build_tag_filters='-experiment_variation' -- //... "${EXCLUDED_TARGETS[@]}" || FAILED_TESTS="${FAILED_TESTS}buildtest "
90    tools/bazel build "${ACTION_ENV_FLAG}" --config fuzztest --build_tag_filters='-experiment_variation' -- //fuzztest/... || FAILED_TESTS="${FAILED_TESTS}fuzztest_buildtest "
91    SHARD_RAN="true"
92  fi
93
94  for TEST_DIRECTORY in "${TEST_DIRECTORIES[@]}"
95  do
96    pushd "test/distrib/bazel/${TEST_DIRECTORY}/"
97    if [ "${TEST_SHARD}" == "distribtest_${TEST_DIRECTORY}" ] ; then
98      tools/bazel version | grep "$VERSION" || { echo "Detected bazel version did not match expected value of $VERSION" >/dev/stderr; exit 1; }
99      tools/bazel test "${ACTION_ENV_FLAG}" --test_output=all //:all || FAILED_TESTS="${FAILED_TESTS}distribtest_${TEST_DIRECTORY} "
100      SHARD_RAN="true"
101    fi
102    popd
103  done
104
105  if [ "${SHARD_RAN}" == "" ]; then
106    echo "Unknown shard '${TEST_SHARD}'"
107    exit 1
108  fi
109done
110
111if [ "$FAILED_TESTS" != "" ]
112then
113  echo "Failed tests at version ${VERSION}: ${FAILED_TESTS}"
114  exit 1
115fi
116