• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2# Copyright 2021 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 -eo pipefail
17
18# Constants
19readonly GITHUB_REPOSITORY_NAME="grpc"
20readonly TEST_DRIVER_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/${TEST_DRIVER_REPO_OWNER:-grpc}/psm-interop/${TEST_DRIVER_BRANCH:-main}/.kokoro/psm_interop_kokoro_lib.sh"
21## xDS test server/client Docker images
22readonly SERVER_LANGS="cpp go java"
23readonly CLIENT_LANGS="cpp go java"
24readonly MAIN_BRANCH="${MAIN_BRANCH:-master}"
25
26#######################################
27# Main function: provision software necessary to execute tests, and run them
28# Globals:
29#   KOKORO_ARTIFACTS_DIR
30#   GITHUB_REPOSITORY_NAME
31#   SRC_DIR: Populated with absolute path to the source repo
32#   TEST_DRIVER_REPO_DIR: Populated with the path to the repo containing
33#                         the test driver
34#   TEST_DRIVER_FULL_DIR: Populated with the path to the test driver source code
35#   TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile
36#   TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report
37#   GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build
38#   GIT_COMMIT: Populated with the SHA-1 of git commit being built
39#   GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built
40#   KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access
41# Arguments:
42#   None
43# Outputs:
44#   Writes the output of test execution to stdout, stderr
45#######################################
46main() {
47  local script_dir
48  script_dir="${PWD}/$(dirname "$0")"
49
50  # Source the test driver from the master branch.
51  echo "Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}"
52  source /dev/stdin <<< "$(curl -s "${TEST_DRIVER_INSTALL_SCRIPT_URL}")"
53
54  activate_gke_cluster GKE_CLUSTER_PSM_SECURITY
55
56  set -x
57  if [[ -n "${KOKORO_ARTIFACTS_DIR}" ]]; then
58    kokoro_setup_test_driver "${GITHUB_REPOSITORY_NAME}"
59    if [ "${TESTING_VERSION}" != "master" ]; then
60      echo "Skipping cross lang testing for non-master branch ${TESTING_VERSION}"
61      exit 0
62    fi
63    cd "${TEST_DRIVER_FULL_DIR}"
64  else
65    local_setup_test_driver "${script_dir}"
66    cd "${SRC_DIR}/${TEST_DRIVER_PATH}"
67  fi
68
69  source "${script_dir}/grpc_xds_k8s_run_xtest.sh"
70
71  local failed_tests=0
72  local successful_string
73  local failed_string
74  LATEST_BRANCH=$(find_latest_branch "${LATEST_BRANCH}")
75  OLDEST_BRANCH=$(find_oldest_branch "${OLDEST_BRANCH}" "${LATEST_BRANCH}")
76  # Run cross lang tests: for given cross lang versions
77  XLANG_VERSIONS="${MAIN_BRANCH} ${LATEST_BRANCH} ${OLDEST_BRANCH}"
78  declare -A FIXED_VERSION_NAMES=( ["${MAIN_BRANCH}"]="${MAIN_BRANCH}" ["${LATEST_BRANCH}"]="latest" ["${OLDEST_BRANCH}"]="oldest")
79  for VERSION in ${XLANG_VERSIONS}
80  do
81    for CLIENT_LANG in ${CLIENT_LANGS}
82    do
83    for SERVER_LANG in ${SERVER_LANGS}
84    do
85      if [ "${CLIENT_LANG}" != "${SERVER_LANG}" ]; then
86        FIXED="${FIXED_VERSION_NAMES[${VERSION}]}"
87        if run_test "${CLIENT_LANG}" "${VERSION}" "${SERVER_LANG}" "${VERSION}" "${FIXED}" "${FIXED}"; then
88          successful_string="${successful_string} ${VERSION}/${CLIENT_LANG}-${SERVER_LANG}"
89        else
90          failed_tests=$((failed_tests+1))
91          failed_string="${failed_string} ${VERSION}/${CLIENT_LANG}-${SERVER_LANG}"
92        fi
93      fi
94    done
95    echo "Failed test suites: ${failed_tests}"
96    done
97  done
98  set +x
99  echo "Failed test suites list: ${failed_string}"
100  echo "Successful test suites list: ${successful_string}"
101}
102
103main "$@"
104