forked from tink-crypto/tink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.sh
executable file
·237 lines (197 loc) · 6.36 KB
/
run_tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
####################################################################################
#!/bin/bash
# Fail on any error.
set -e
# Display commands to stderr.
set -x
./kokoro/copy_credentials.sh
readonly PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')"
fail_with_debug_output() {
ls -l
df -h /
exit 1
}
run_linux_tests() {
local workspace_dir="$1"
shift 1
local manual_targets=("$@")
local -a TEST_FLAGS=( --strategy=TestRunner=standalone --test_output=all )
readonly TEST_FLAGS
(
cd "${workspace_dir}"
time bazel build -- ... || fail_with_debug_output
time bazel test "${TEST_FLAGS[@]}" -- ... || fail_with_debug_output
if (( ${#manual_targets[@]} > 0 )); then
time bazel test "${TEST_FLAGS[@]}" -- "${manual_targets[@]}" \
|| fail_with_debug_output
fi
)
}
run_all_linux_tests() {
run_linux_tests "cc"
run_linux_tests "java_src"
run_linux_tests "go"
run_linux_tests "python"
run_linux_tests "javascript"
run_linux_tests "tools"
run_linux_tests "apps"
run_linux_tests "examples/cc"
local -a MANUAL_EXAMPLE_JAVA_TARGETS
if [[ -n "${KOKORO_ROOT}" ]]; then
MANUAL_EXAMPLE_JAVA_TARGETS=(
"//gcs:gcs_envelope_aead_example_test"
"//encryptedkeyset:encrypted_keyset_example_test"
"//envelopeaead:envelope_aead_example_test"
)
fi
readonly MANUAL_EXAMPLE_JAVA_TARGETS
run_linux_tests "examples/java_src" "${MANUAL_EXAMPLE_JAVA_TARGETS[@]}"
## Install Tink and its dependencies via pip for the examples/python tests.
install_tink_via_pip
local -a MANUAL_EXAMPLE_PYTHON_TARGETS
if [[ -n "${KOKORO_ROOT}" ]]; then
MANUAL_EXAMPLE_PYTHON_TARGETS=(
"//gcs:gcs_envelope_aead_test_package"
"//gcs:gcs_envelope_aead_test"
"//envelope_aead:envelope_test_package"
"//envelope_aead:envelope_test"
"//encrypted_keyset:encrypted_keyset_test_package"
"//encrypted_keyset:encrypted_keyset_test"
)
fi
readonly MANUAL_EXAMPLE_PYTHON_TARGETS
run_linux_tests "examples/python" "${MANUAL_EXAMPLE_PYTHON_TARGETS[@]}"
}
run_macos_tests() {
# Default values for iOS SDK and Xcode. Can be overriden by another script.
: "${IOS_SDK_VERSION:=13.2}"
: "${XCODE_VERSION:=11.3}"
local -a BAZEL_FLAGS=(
--compilation_mode=dbg --dynamic_mode=off --cpu=ios_x86_64
--ios_cpu=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
)
}
install_tink_via_pip() {
local -a PIP_FLAGS
if [[ "${PLATFORM}" == 'darwin' ]]; then
PIP_FLAGS=( --user )
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
pip3 install "${PIP_FLAGS[@]}" --upgrade setuptools
pip3 install "${PIP_FLAGS[@]}" ./python
# Install dependencies for the examples/python tests
pip3 install "${PIP_FLAGS[@]}" google-cloud-storage
}
install_temp_protoc() {
local protoc_version='3.14.0'
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 -OL "${protoc_url}"
unzip ${protoc_zip} bin/protoc
)
export PATH="${protoc_tmpdir}/bin:${PATH}"
}
main() {
# Initialization for Kokoro environments.
if [[ -n "${KOKORO_ROOT}" ]]; then
use_bazel.sh $(cat .bazelversion)
# Install protoc into a temporary directory.
install_temp_protoc
if [[ "${PLATFORM}" == 'linux' ]]; then
# Install a more recent Python.
: "${PYTHON_VERSION:=3.7.1}"
(
# Update the Python version list.
cd /home/kbuilder/.pyenv/plugins/python-build/../..
git pull
# TODO(b/187879867): Remove once pyenv issue is resolved.
git checkout 783870759566a77d09b426e0305bc0993a522765
)
eval "$(pyenv init -)"
pyenv install -v "${PYTHON_VERSION}"
pyenv global "${PYTHON_VERSION}"
fi
if [[ "${PLATFORM}" == 'darwin' ]]; then
export DEVELOPER_DIR="/Applications/Xcode_${XCODE_VERSION}.app/Contents/Developer"
export ANDROID_HOME="/Users/kbuilder/Library/Android/sdk"
# TODO(b/155225382): Avoid modifying the sytem Python installation.
pip3 install --user protobuf
fi
fi
# Verify required environment variables.
# Required for building Java binaries.
if [[ -z "${ANDROID_HOME}" ]]; then
echo "The ANDROID_HOME environment variable must be set."
exit 4
fi
if [[ -z "${TMP}" ]]; then
echo "The TMP environment variable must be set."
exit 4
fi
echo "using bazel binary: $(which bazel)"
bazel version
echo "using java binary: $(which java)"
java -version
echo "using go: $(which go)"
go version
echo "using python: $(which python)"
python --version
echo "using python3: $(which python3)"
python3 --version
echo "using pip3: $(which pip3)"
pip3 --version
pip3 list
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
}
main "$@"