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