1# Copyright 2017 Google Inc. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14#################################################################################### 15 16#!/bin/bash 17 18# Fail on any error. 19set -e 20 21# Display commands to stderr. 22set -x 23 24readonly PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')" 25 26IS_KOKORO="false" 27if [[ -n "${KOKORO_ROOT}" ]]; then 28 IS_KOKORO="true" 29fi 30readonly IS_KOKORO 31 32use_bazel() { 33 local -r bazel_version="$1" 34 if [[ "${IS_KOKORO}" == "false" ]]; then 35 # Do nothing. 36 return 0 37 fi 38 if ! command -v "bazelisk" &> /dev/null; then 39 use_bazel.sh "${bazel_version}" 40 fi 41} 42 43run_cc_tests() { 44 use_bazel "$(cat cc/.bazelversion)" 45 ./kokoro/testutils/run_bazel_tests.sh "cc" 46} 47 48run_go_tests() { 49 use_bazel "$(cat go/.bazelversion)" 50 ./kokoro/testutils/run_bazel_tests.sh -t --test_arg=--test.v "go" 51} 52 53run_py_tests() { 54 use_bazel "$(cat python/.bazelversion)" 55 ./kokoro/testutils/run_bazel_tests.sh "python" 56} 57 58run_tools_tests() { 59 use_bazel "$(cat tools/.bazelversion)" 60 ./kokoro/testutils/run_bazel_tests.sh "tools" 61} 62 63run_java_tests() { 64 use_bazel "$(cat java_src/.bazelversion)" 65 local -a MANUAL_JAVA_TARGETS 66 if [[ "${IS_KOKORO}" == "true" ]]; then 67 MANUAL_JAVA_TARGETS+=( 68 "//src/test/java/com/google/crypto/tink/integration/gcpkms:GcpKmsIntegrationTest" 69 ) 70 fi 71 readonly MANUAL_JAVA_TARGETS 72 ./kokoro/testutils/run_bazel_tests.sh "java_src" "${MANUAL_JAVA_TARGETS[@]}" 73} 74 75run_cc_examples_tests() { 76 use_bazel "$(cat cc/examples/.bazelversion)" 77 ./kokoro/testutils/run_bazel_tests.sh "cc/examples" 78} 79 80run_java_examples_tests() { 81 use_bazel "$(cat java_src/examples/.bazelversion)" 82 local -a MANUAL_EXAMPLE_JAVA_TARGETS 83 if [[ "${IS_KOKORO}" == "true" ]]; then 84 MANUAL_EXAMPLE_JAVA_TARGETS=( 85 "//gcs:gcs_envelope_aead_example_test" 86 "//encryptedkeyset:encrypted_keyset_example_test" 87 "//envelopeaead:envelope_aead_example_test" 88 ) 89 fi 90 readonly MANUAL_EXAMPLE_JAVA_TARGETS 91 ./kokoro/testutils/run_bazel_tests.sh "java_src/examples" \ 92 "${MANUAL_EXAMPLE_JAVA_TARGETS[@]}" 93} 94 95run_py_examples_tests() { 96 use_bazel "$(cat python/examples/.bazelversion)" 97 ## Install Tink and its dependencies via pip for the examples/python tests. 98 ./kokoro/testutils/install_tink_via_pip.sh "${PWD}/python" "${PWD}" 99 if [[ "${IS_KOKORO}" == "true" ]]; then 100 local pip_flags=( --require-hashes ) 101 if [[ "${PLATFORM}" == "darwin" ]]; then 102 pip_flags+=( --user ) 103 fi 104 readonly pip_flags 105 # Install dependencies for the examples/python tests. 106 pip3 install "${pip_flags[@]}" -r python/examples/requirements.txt 107 fi 108 109 local -a MANUAL_EXAMPLE_PYTHON_TARGETS 110 if [[ "${IS_KOKORO}" == "true" ]]; then 111 MANUAL_EXAMPLE_PYTHON_TARGETS=( 112 "//gcs:gcs_envelope_aead_test_package" 113 "//gcs:gcs_envelope_aead_test" 114 "//envelope_aead:envelope_test_package" 115 "//envelope_aead:envelope_test" 116 "//encrypted_keyset:encrypted_keyset_test_package" 117 "//encrypted_keyset:encrypted_keyset_test" 118 ) 119 fi 120 readonly MANUAL_EXAMPLE_PYTHON_TARGETS 121 ./kokoro/testutils/run_bazel_tests.sh "python/examples" \ 122 "${MANUAL_EXAMPLE_PYTHON_TARGETS[@]}" 123} 124 125run_all_tests() { 126 # Only run these tests if exeucting a Kokoro GitHub continuous integration 127 # job or if running locally (e.g. as part of release.sh). 128 # 129 # TODO(b/231610897): Use an easier to maintain approach to test parity. 130 if [[ "${KOKORO_JOB_NAME:-}" =~ ^tink/github \ 131 || -z "${KOKORO_JOB_NAME+x}" ]]; then 132 run_cc_tests 133 run_java_tests 134 run_go_tests 135 run_py_tests 136 run_tools_tests 137 fi 138 run_cc_examples_tests 139 run_java_examples_tests 140 run_py_examples_tests 141} 142 143main() { 144 # Initialization for Kokoro environments. 145 if [[ "${IS_KOKORO}" == "true" ]]; then 146 cd "${KOKORO_ARTIFACTS_DIR}"/git*/tink* 147 # Install protoc. 148 source ./kokoro/testutils/install_protoc.sh 149 150 if [[ "${PLATFORM}" == 'linux' ]]; then 151 # Sourcing required to update callers environment. 152 source ./kokoro/testutils/install_python3.sh 153 ./kokoro/testutils/upgrade_gcc.sh 154 fi 155 156 if [[ "${PLATFORM}" == 'darwin' ]]; then 157 # Default values for iOS SDK and Xcode. Can be overriden by another script. 158 : "${IOS_SDK_VERSION:=13.2}" 159 : "${XCODE_VERSION:=14.1}" 160 161 export DEVELOPER_DIR="/Applications/Xcode.app/Contents/Developer" 162 export JAVA_HOME=$(/usr/libexec/java_home -v "1.8.0_292") 163 export ANDROID_HOME="/usr/local/share/android-sdk" 164 export COURSIER_OPTS="-Djava.net.preferIPv6Addresses=true" 165 166 # TODO(b/155225382): Avoid modifying the sytem Python installation. 167 pip3 install --user protobuf 168 fi 169 170 ./kokoro/testutils/copy_credentials.sh "go/testdata" "all" 171 ./kokoro/testutils/copy_credentials.sh "java_src/examples/testdata" "gcp" 172 ./kokoro/testutils/copy_credentials.sh "java_src/testdata" "all" 173 ./kokoro/testutils/copy_credentials.sh "python/examples/testdata" "gcp" 174 ./kokoro/testutils/copy_credentials.sh "python/testdata" "all" 175 176 ./kokoro/testutils/update_android_sdk.sh 177 # Sourcing required to update callers environment. 178 source ./kokoro/testutils/install_go.sh 179 fi 180 181 # Verify required environment variables. 182 183 # Required for building Java binaries. 184 if [[ -z "${ANDROID_HOME}" ]]; then 185 echo "The ANDROID_HOME environment variable must be set." 186 exit 4 187 fi 188 189 if [[ -z "${TMP}" ]]; then 190 echo "The TMP environment variable must be set." 191 exit 4 192 fi 193 194 echo "using java binary: $(which java)" 195 java -version 196 197 echo "Using go binary from $(which go): $(go version)" 198 199 echo "using python: $(which python)" 200 python --version 201 202 echo "using python3: $(which python3)" 203 python3 --version 204 205 echo "using pip3: $(which pip3)" 206 pip3 --version 207 pip3 list 208 209 echo "using protoc: $(which protoc)" 210 protoc --version 211 212 run_all_tests 213} 214 215main "$@" 216