aboutsummaryrefslogtreecommitdiff
path: root/kokoro
diff options
context:
space:
mode:
authorambrosin <ambrosin@google.com>2023-02-15 06:27:10 -0800
committerCopybara-Service <copybara-worker@google.com>2023-02-15 06:28:09 -0800
commitb6afb5e68c59a30abbad89638ab73b02c5f69cd1 (patch)
treed24fb3c5ff3d0c1b3e16c8deb620fe48efc3bf3f /kokoro
parent17a30fb85bcd6983c1b6cbfa4560f87d84c0bd62 (diff)
downloadtink-b6afb5e68c59a30abbad89638ab73b02c5f69cd1.tar.gz
Refactor Tink's comprehensive test.
* Remove duplicate code using existing testutils scripts instead * Remove macOS tests function and commented code * Use Bazelisk if available PiperOrigin-RevId: 509814947
Diffstat (limited to 'kokoro')
-rwxr-xr-xkokoro/run_tests.sh275
1 files changed, 107 insertions, 168 deletions
diff --git a/kokoro/run_tests.sh b/kokoro/run_tests.sh
index 19623596f..714b0c3bb 100755
--- a/kokoro/run_tests.sh
+++ b/kokoro/run_tests.sh
@@ -21,92 +21,89 @@ set -e
# Display commands to stderr.
set -x
-
readonly PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')"
-fail_with_debug_output() {
- ls -l
- df -h /
- exit 1
+IS_KOKORO="false"
+if [[ -n "${KOKORO_ROOT}" ]]; then
+ IS_KOKORO="true"
+fi
+readonly IS_KOKORO
+
+use_bazel() {
+ local -r bazel_version="$1"
+ if [[ "${IS_KOKORO}" == "false" ]]; then
+ # Do nothing.
+ return 0
+ fi
+ if ! command -v "bazelisk" &> /dev/null; then
+ use_bazel.sh "${bazel_version}"
+ fi
}
-run_linux_tests() {
- local workspace_dir="$1"
- shift 1
- local manual_targets=("$@")
+run_cc_tests() {
+ use_bazel "$(cat cc/.bazelversion)"
+ ./kokoro/testutils/run_bazel_tests.sh "cc"
+}
- # This is needed to handle recent Chrome distributions on macOS which have
- # paths with spaces.
- #
- # Context:
- # https://github.com/bazelbuild/bazel/issues/4327#issuecomment-627422865
- local -a BAZEL_FLAGS
- if [[ "${PLATFORM}" == 'darwin' && "${workspace_dir}" == 'javascript' ]]; then
- BAZEL_FLAGS+=( --experimental_inprocess_symlink_creation )
+run_go_tests() {
+ use_bazel "$(cat go/.bazelversion)"
+ ./kokoro/testutils/run_bazel_tests.sh "go"
+}
+
+run_py_tests() {
+ use_bazel "$(cat python/.bazelversion)"
+ ./kokoro/testutils/run_bazel_tests.sh "python"
+}
+
+run_tools_tests() {
+ use_bazel "$(cat tools/.bazelversion)"
+ local -a MANUAL_TOOLS_TARGETS
+ if [[ "${IS_KOKORO}" == "true" ]]; then
+ MANUAL_TOOLS_TARGETS+=(
+ "//testing/cc:aws_kms_aead_test"
+ "//testing/cc:gcp_kms_aead_test"
+ "//testing/cross_language:aead_envelope_test"
+ "//tinkey/src/test/java/com/google/crypto/tink/tinkey:AddKeyCommandTest"
+ "//tinkey/src/test/java/com/google/crypto/tink/tinkey:CreateKeysetCommandTest"
+ "//tinkey/src/test/java/com/google/crypto/tink/tinkey:CreatePublicKeysetCommandTest"
+ "//tinkey/src/test/java/com/google/crypto/tink/tinkey:RotateKeysetCommandTest"
+ )
fi
- readonly BAZEL_FLAGS
+ readonly MANUAL_TOOLS_TARGETS
+ ./kokoro/testutils/run_bazel_tests.sh "tools" "${MANUAL_TOOLS_TARGETS[@]}"
+}
- local -a TEST_FLAGS=( --strategy=TestRunner=standalone --test_output=all )
- if [[ "${PLATFORM}" == 'darwin' ]]; then
- TEST_FLAGS+=( --jvmopt="-Djava.net.preferIPv6Addresses=true" )
+run_java_tests() {
+ use_bazel "$(cat java_src/.bazelversion)"
+ local -a MANUAL_JAVA_TARGETS
+ if [[ "${IS_KOKORO}" == "true" ]]; then
+ MANUAL_JAVA_TARGETS+=(
+ "//src/test/java/com/google/crypto/tink/integration/gcpkms:GcpKmsIntegrationTest"
+ )
fi
- readonly TEST_FLAGS
- (
- cd "${workspace_dir}"
- time bazel build "${BAZEL_FLAGS[@]}" -- ... || fail_with_debug_output
- time bazel test "${BAZEL_FLAGS[@]}" "${TEST_FLAGS[@]}" -- ... \
- || fail_with_debug_output
- if (( ${#manual_targets[@]} > 0 )); then
- time bazel test "${TEST_FLAGS[@]}" -- "${manual_targets[@]}" \
- || fail_with_debug_output
- fi
- )
+ readonly MANUAL_JAVA_TARGETS
+ ./kokoro/testutils/run_bazel_tests.sh "java_src" "${MANUAL_JAVA_TARGETS[@]}"
}
-run_all_linux_tests() {
- # Only run these tests if exeucting a Kokoro GitHub continuous integration
- # job or if running locally (e.g. as part of release.sh).
- #
- # TODO(b/228529710): Use an easier to maintain approach to test parity.
- if [[ "${KOKORO_JOB_NAME:-}" =~ ^tink/github \
- || -z "${KOKORO_JOB_NAME+x}" ]]; then
- run_linux_tests "cc"
-
- local -a MANUAL_JAVA_TARGETS
- if [[ -n "${KOKORO_ROOT}" ]]; then
- MANUAL_JAVA_TARGETS+=(
- "//src/test/java/com/google/crypto/tink/integration/gcpkms:GcpKmsIntegrationTest"
- )
- fi
- readonly MANUAL_JAVA_TARGETS
- run_linux_tests "java_src" "${MANUAL_JAVA_TARGETS[@]}"
-
- run_linux_tests "go"
- run_linux_tests "python"
-
- local -a MANUAL_TOOLS_TARGETS
- if [[ -n "${KOKORO_ROOT}" ]]; then
- MANUAL_TOOLS_TARGETS+=(
- "//testing/cc:aws_kms_aead_test"
- "//testing/cc:gcp_kms_aead_test"
- "//testing/cross_language:aead_envelope_test"
- "//tinkey/src/test/java/com/google/crypto/tink/tinkey:AddKeyCommandTest"
- "//tinkey/src/test/java/com/google/crypto/tink/tinkey:CreateKeysetCommandTest"
- "//tinkey/src/test/java/com/google/crypto/tink/tinkey:CreatePublicKeysetCommandTest"
- "//tinkey/src/test/java/com/google/crypto/tink/tinkey:RotateKeysetCommandTest"
- )
- fi
- readonly MANUAL_TOOLS_TARGETS
- run_linux_tests "tools" "${MANUAL_TOOLS_TARGETS[@]}"
+run_java_apps_tests() {
+ use_bazel "$(cat apps/.bazelversion)"
+ ./kokoro/testutils/run_bazel_tests.sh "apps"
+}
- run_linux_tests "apps"
- fi
+run_javascript_tests() {
+ use_bazel "$(cat javascript/.bazelversion)"
+ ./kokoro/testutils/run_bazel_tests.sh "javascript"
+}
- run_linux_tests "javascript"
- run_linux_tests "cc/examples"
+run_cc_examples_tests() {
+ use_bazel "$(cat cc/examples/.bazelversion)"
+ ./kokoro/testutils/run_bazel_tests.sh "cc/examples"
+}
+run_java_examples_tests() {
+ use_bazel "$(cat java_src/examples/.bazelversion)"
local -a MANUAL_EXAMPLE_JAVA_TARGETS
- if [[ -n "${KOKORO_ROOT}" ]]; then
+ if [[ "${IS_KOKORO}" == "true" ]]; then
MANUAL_EXAMPLE_JAVA_TARGETS=(
"//gcs:gcs_envelope_aead_example_test"
"//encryptedkeyset:encrypted_keyset_example_test"
@@ -114,13 +111,23 @@ run_all_linux_tests() {
)
fi
readonly MANUAL_EXAMPLE_JAVA_TARGETS
- run_linux_tests "java_src/examples" "${MANUAL_EXAMPLE_JAVA_TARGETS[@]}"
+ ./kokoro/testutils/run_bazel_tests.sh "java_src/examples" \
+ "${MANUAL_EXAMPLE_JAVA_TARGETS[@]}"
+}
+run_py_examples_tests() {
+ use_bazel "$(cat python/examples/.bazelversion)"
## Install Tink and its dependencies via pip for the examples/python tests.
- install_tink_via_pip
+ source ./kokoro/testutils/install_tink_via_pip.sh "${PWD}/python"
+ if [[ "${IS_KOKORO}" == "true" ]]; then
+ # Install dependencies for the examples/python tests.
+ pip3 install "${PIP_FLAGS[@]}" \
+ -r python/examples/requirements.txt \
+ -c python/examples/constraints.in
+ fi
local -a MANUAL_EXAMPLE_PYTHON_TARGETS
- if [[ -n "${KOKORO_ROOT}" ]]; then
+ if [[ "${IS_KOKORO}" == "true" ]]; then
MANUAL_EXAMPLE_PYTHON_TARGETS=(
"//gcs:gcs_envelope_aead_test_package"
"//gcs:gcs_envelope_aead_test"
@@ -131,81 +138,28 @@ run_all_linux_tests() {
)
fi
readonly MANUAL_EXAMPLE_PYTHON_TARGETS
- run_linux_tests "python/examples" "${MANUAL_EXAMPLE_PYTHON_TARGETS[@]}"
-}
-
-run_macos_tests() {
- local -a BAZEL_FLAGS=(
- --compilation_mode=dbg --dynamic_mode=off --cpu=ios_x86_64
- --experimental_enable_objc_cc_deps
- --ios_sdk_version="${IOS_SDK_VERSION}"
- --xcode_version="${XCODE_VERSION}" --verbose_failures
- --test_output=all
- )
- readonly BAZEL_FLAGS
-
- (
- cd objc
-
- # Build the iOS targets.
- time bazel build "${BAZEL_FLAGS[@]}" ... || fail_with_debug_output
-
- # Run the iOS tests.
- time bazel test "${BAZEL_FLAGS[@]}" :TinkTests || fail_with_debug_output
- )
+ ./kokoro/testutils/run_bazel_tests.sh "python/examples" \
+ "${MANUAL_EXAMPLE_PYTHON_TARGETS[@]}"
}
-install_tink_via_pip() {
- if [[ -n "${KOKORO_ROOT}" ]]; then
- use_bazel.sh "$(cat python/.bazelversion)"
- fi
-
- local -a PIP_FLAGS
- if [[ "${PLATFORM}" == 'darwin' ]]; then
- PIP_FLAGS=( --user )
+run_all_tests() {
+ # Only run these tests if exeucting a Kokoro GitHub continuous integration
+ # job or if running locally (e.g. as part of release.sh).
+ #
+ # TODO(b/228529710): Use an easier to maintain approach to test parity.
+ if [[ "${KOKORO_JOB_NAME:-}" =~ ^tink/github \
+ || -z "${KOKORO_JOB_NAME+x}" ]]; then
+ run_cc_tests
+ run_java_tests
+ run_go_tests
+ run_py_tests
+ run_tools_tests
+ run_java_apps_tests
fi
- readonly PIP_FLAGS
-
- # Set path to Tink base folder
- export TINK_PYTHON_SETUPTOOLS_OVERRIDE_BASE_PATH="${PWD}"
-
- # Check if we can build Tink python package.
- pip3 install "${PIP_FLAGS[@]}" --upgrade pip
- # TODO(b/219813176): Remove once Kokoro environment is compatible.
- pip3 install "${PIP_FLAGS[@]}" --upgrade 'setuptools==60.9.0'
- pip3 install "${PIP_FLAGS[@]}" ./python
-
- # Install dependencies for the examples/python tests
- pip3 install "${PIP_FLAGS[@]}" \
- -r python/examples/requirements.txt \
- -c python/examples/constraints.in
-}
-
-install_temp_protoc() {
- ## Use protoc version X.21.9.
- local protoc_version='21.9'
- local protoc_platform
- case "${PLATFORM}" in
- 'linux')
- protoc_platform='linux-x86_64'
- ;;
- 'darwin')
- protoc_platform='osx-x86_64'
- ;;
- *)
- echo "Unsupported platform, unable to install protoc."
- exit 1
- ;;
- esac
- local protoc_zip="protoc-${protoc_version}-${protoc_platform}.zip"
- local protoc_url="https://github.com/protocolbuffers/protobuf/releases/download/v${protoc_version}/${protoc_zip}"
- local -r protoc_tmpdir=$(mktemp -dt tink-protoc.XXXXXX)
- (
- cd "${protoc_tmpdir}"
- curl -OLsS "${protoc_url}"
- unzip ${protoc_zip} bin/protoc
- )
- export PATH="${protoc_tmpdir}/bin:${PATH}"
+ run_javascript_tests
+ run_cc_examples_tests
+ run_java_examples_tests
+ run_py_examples_tests
}
#######################################
@@ -217,27 +171,21 @@ install_temp_protoc() {
# None
#######################################
test_maven_packages() {
- if [[ -n "${KOKORO_ROOT}" ]]; then
- use_bazel.sh "$(cat java_src/.bazelversion)"
- fi
# Only test in the Ubuntu environment.
if [[ "${PLATFORM}" != "linux" ]]; then
- return
+ return 0
fi
-
+ use_bazel "$(cat java_src/.bazelversion)"
./maven/publish_snapshot.sh -l
./maven/test_snapshot.sh -l
}
main() {
# Initialization for Kokoro environments.
- if [[ -n "${KOKORO_ROOT}" ]]; then
+ if [[ "${IS_KOKORO}" == "true" ]]; then
cd "${KOKORO_ARTIFACTS_DIR}"/git*/tink*
-
- use_bazel.sh "$(cat .bazelversion)"
-
- # Install protoc into a temporary directory.
- install_temp_protoc
+ # Install protoc.
+ source ./kokoro/testutils/install_protoc.sh
if [[ "${PLATFORM}" == 'linux' ]]; then
# Sourcing required to update callers environment.
@@ -283,9 +231,6 @@ main() {
exit 4
fi
- echo "using bazel binary: $(which bazel)"
- bazel version
-
echo "using java binary: $(which java)"
java -version
@@ -304,13 +249,7 @@ main() {
echo "using protoc: $(which protoc)"
protoc --version
- run_all_linux_tests
-
- if [[ "${PLATFORM}" == 'darwin' ]]; then
- # TODO(b/155060426): re-enable after ObjC WORKSPACE is added.
- # run_macos_tests
- echo "*** ObjC tests not enabled yet."
- fi
+ run_all_tests
test_maven_packages
}