• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3# Copyright 2019 The Abseil Authors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#    https://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# This script that can be invoked to test abseil-cpp in a hermetic environment
18# using a Docker image on Linux. You must have Docker installed to use this
19# script.
20
21set -euox pipefail
22
23if [ -z ${ABSEIL_ROOT:-} ]; then
24  ABSEIL_ROOT="$(realpath $(dirname ${0})/..)"
25fi
26
27if [ -z ${STD:-} ]; then
28  STD="c++11 c++14 c++17"
29fi
30
31if [ -z ${COMPILATION_MODE:-} ]; then
32  COMPILATION_MODE="fastbuild opt"
33fi
34
35if [ -z ${EXCEPTIONS_MODE:-} ]; then
36  EXCEPTIONS_MODE="-fno-exceptions -fexceptions"
37fi
38
39readonly DOCKER_CONTAINER="gcr.io/google.com/absl-177019/linux_clang-latest:20200102"
40
41# USE_BAZEL_CACHE=1 only works on Kokoro.
42# Without access to the credentials this won't work.
43if [ ${USE_BAZEL_CACHE:-0} -ne 0 ]; then
44  DOCKER_EXTRA_ARGS="--volume=${KOKORO_KEYSTORE_DIR}:/keystore:ro ${DOCKER_EXTRA_ARGS:-}"
45  # Bazel doesn't track changes to tools outside of the workspace
46  # (e.g. /usr/bin/gcc), so by appending the docker container to the
47  # remote_http_cache url, we make changes to the container part of
48  # the cache key. Hashing the key is to make it shorter and url-safe.
49  container_key=$(echo ${DOCKER_CONTAINER} | sha256sum | head -c 16)
50  BAZEL_EXTRA_ARGS="--remote_http_cache=https://storage.googleapis.com/absl-bazel-remote-cache/${container_key} --google_credentials=/keystore/73103_absl-bazel-remote-cache ${BAZEL_EXTRA_ARGS:-}"
51fi
52
53for std in ${STD}; do
54  for compilation_mode in ${COMPILATION_MODE}; do
55    for exceptions_mode in ${EXCEPTIONS_MODE}; do
56      echo "--------------------------------------------------------------------"
57      time docker run \
58        --volume="${ABSEIL_ROOT}:/abseil-cpp:ro" \
59        --workdir=/abseil-cpp \
60        --cap-add=SYS_PTRACE \
61        --rm \
62        -e CC="/opt/llvm/clang/bin/clang" \
63        -e BAZEL_COMPILER="llvm" \
64        -e BAZEL_CXXOPTS="-std=${std}:-nostdinc++" \
65        -e BAZEL_LINKOPTS="-L/opt/llvm/libcxx/lib:-lc++:-lc++abi:-lm:-Wl,-rpath=/opt/llvm/libcxx/lib" \
66        -e CPLUS_INCLUDE_PATH="/opt/llvm/libcxx/include/c++/v1" \
67        ${DOCKER_EXTRA_ARGS:-} \
68        ${DOCKER_CONTAINER} \
69        /usr/local/bin/bazel test ... \
70          --compilation_mode="${compilation_mode}" \
71          --copt="${exceptions_mode}" \
72          --copt="-DDYNAMIC_ANNOTATIONS_ENABLED=1" \
73          --copt="-DADDRESS_SANITIZER" \
74          --copt="-DUNDEFINED_BEHAVIOR_SANITIZER" \
75          --copt="-fsanitize=address" \
76          --copt="-fsanitize=float-divide-by-zero" \
77          --copt="-fsanitize=nullability" \
78          --copt="-fsanitize=undefined" \
79          --copt="-fno-sanitize-blacklist" \
80          --copt=-Werror \
81          --keep_going \
82          --linkopt="-fsanitize=address" \
83          --linkopt="-fsanitize-link-c++-runtime" \
84          --show_timestamps \
85          --test_env="ASAN_SYMBOLIZER_PATH=/opt/llvm/clang/bin/llvm-symbolizer" \
86          --test_env="TZDIR=/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo" \
87          --test_env="UBSAN_OPTIONS=print_stacktrace=1" \
88          --test_env="UBSAN_SYMBOLIZER_PATH=/opt/llvm/clang/bin/llvm-symbolizer" \
89          --test_output=errors \
90          --test_tag_filters="-benchmark,-noasan" \
91          ${BAZEL_EXTRA_ARGS:-}
92    done
93  done
94done
95