• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_vs2022_bazel7/..."
67  "-//third_party/toolchains:rbe_windows_default_toolchain_suite"
68
69  # Exclude bazelified tests as they contain some bazel hackery
70  "-//tools/bazelify_tests/..."
71)
72
73FAILED_TESTS=""
74
75export OVERRIDE_BAZEL_VERSION="$VERSION"
76# when running under bazel docker image, the workspace is read only.
77export OVERRIDE_BAZEL_WRAPPER_DOWNLOAD_DIR=/tmp
78
79ACTION_ENV_FLAG="--action_env=bazel_cache_invalidate=version_${VERSION}"
80
81for TEST_SHARD in "${TEST_SHARDS[@]}"
82do
83  SHARD_RAN=""
84  if [ "${TEST_SHARD}" == "buildtest" ] ; then
85    tools/bazel version | grep "$VERSION" || { echo "Detected bazel version did not match expected value of $VERSION" >/dev/stderr; exit 1; }
86    tools/bazel build "${ACTION_ENV_FLAG}" --build_tag_filters='-experiment_variation' -- //... "${EXCLUDED_TARGETS[@]}" || FAILED_TESTS="${FAILED_TESTS}buildtest "
87    tools/bazel build "${ACTION_ENV_FLAG}" --config fuzztest --build_tag_filters='-experiment_variation' -- //fuzztest/... || FAILED_TESTS="${FAILED_TESTS}fuzztest_buildtest "
88    SHARD_RAN="true"
89  fi
90
91  for TEST_DIRECTORY in "${TEST_DIRECTORIES[@]}"
92  do
93    pushd "test/distrib/bazel/${TEST_DIRECTORY}/"
94    if [ "${TEST_SHARD}" == "distribtest_${TEST_DIRECTORY}" ] ; then
95      tools/bazel version | grep "$VERSION" || { echo "Detected bazel version did not match expected value of $VERSION" >/dev/stderr; exit 1; }
96      tools/bazel test "${ACTION_ENV_FLAG}" --test_output=all //:all || FAILED_TESTS="${FAILED_TESTS}distribtest_${TEST_DIRECTORY} "
97      SHARD_RAN="true"
98    fi
99    popd
100  done
101
102  if [ "${SHARD_RAN}" == "" ]; then
103    echo "Unknown shard '${TEST_SHARD}'"
104    exit 1
105  fi
106done
107
108if [ "$FAILED_TESTS" != "" ]
109then
110  echo "Failed tests at version ${VERSION}: ${FAILED_TESTS}"
111  exit 1
112fi
113