linux_clang-latest_libcxx_tsan_bazel.sh 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. # This script that can be invoked to test abseil-cpp in a hermetic environment
  17. # using a Docker image on Linux. You must have Docker installed to use this
  18. # script.
  19. set -euox pipefail
  20. if [[ -z ${ABSEIL_ROOT:-} ]]; then
  21. ABSEIL_ROOT="$(realpath $(dirname ${0})/..)"
  22. fi
  23. if [[ -z ${STD:-} ]]; then
  24. STD="c++14 c++17 c++20"
  25. fi
  26. if [[ -z ${COMPILATION_MODE:-} ]]; then
  27. COMPILATION_MODE="fastbuild opt"
  28. fi
  29. if [[ -z ${EXCEPTIONS_MODE:-} ]]; then
  30. EXCEPTIONS_MODE="-fno-exceptions -fexceptions"
  31. fi
  32. source "${ABSEIL_ROOT}/ci/linux_docker_containers.sh"
  33. readonly DOCKER_CONTAINER=${LINUX_CLANG_LATEST_CONTAINER}
  34. # USE_BAZEL_CACHE=1 only works on Kokoro.
  35. # Without access to the credentials this won't work.
  36. if [[ ${USE_BAZEL_CACHE:-0} -ne 0 ]]; then
  37. DOCKER_EXTRA_ARGS="--mount type=bind,source=${KOKORO_KEYSTORE_DIR},target=/keystore,readonly ${DOCKER_EXTRA_ARGS:-}"
  38. # Bazel doesn't track changes to tools outside of the workspace
  39. # (e.g. /usr/bin/gcc), so by appending the docker container to the
  40. # remote_http_cache url, we make changes to the container part of
  41. # the cache key. Hashing the key is to make it shorter and url-safe.
  42. container_key=$(echo ${DOCKER_CONTAINER} | sha256sum | head -c 16)
  43. 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:-}"
  44. fi
  45. # Avoid depending on external sites like GitHub by checking --distdir for
  46. # external dependencies first.
  47. # https://docs.bazel.build/versions/master/guide.html#distdir
  48. if [[ ${KOKORO_GFILE_DIR:-} ]] && [[ -d "${KOKORO_GFILE_DIR}/distdir" ]]; then
  49. DOCKER_EXTRA_ARGS="--mount type=bind,source=${KOKORO_GFILE_DIR}/distdir,target=/distdir,readonly ${DOCKER_EXTRA_ARGS:-}"
  50. BAZEL_EXTRA_ARGS="--distdir=/distdir ${BAZEL_EXTRA_ARGS:-}"
  51. fi
  52. for std in ${STD}; do
  53. for compilation_mode in ${COMPILATION_MODE}; do
  54. for exceptions_mode in ${EXCEPTIONS_MODE}; do
  55. echo "--------------------------------------------------------------------"
  56. time docker run \
  57. --mount type=bind,source="${ABSEIL_ROOT}",target=/abseil-cpp,readonly \
  58. --workdir=/abseil-cpp \
  59. --cap-add=SYS_PTRACE \
  60. --rm \
  61. -e CC="/opt/llvm/clang/bin/clang" \
  62. -e BAZEL_CXXOPTS="-std=${std}:-nostdinc++" \
  63. -e BAZEL_LINKOPTS="-L/opt/llvm/libcxx-tsan/lib/x86_64-unknown-linux-gnu:-lc++:-lc++abi:-lm:-Wl,-rpath=/opt/llvm/libcxx-tsan/lib/x86_64-unknown-linux-gnu" \
  64. -e CPLUS_INCLUDE_PATH="/opt/llvm/libcxx-tsan/include/x86_64-unknown-linux-gnu/c++/v1:/opt/llvm/libcxx-tsan/include/c++/v1" \
  65. ${DOCKER_EXTRA_ARGS:-} \
  66. ${DOCKER_CONTAINER} \
  67. /usr/local/bin/bazel test ... \
  68. --build_tag_filters="-notsan" \
  69. --compilation_mode="${compilation_mode}" \
  70. --copt="${exceptions_mode}" \
  71. --copt="-DGTEST_REMOVE_LEGACY_TEST_CASEAPI_=1" \
  72. --copt="-fsanitize=thread" \
  73. --copt="-fno-sanitize-blacklist" \
  74. --copt=-Werror \
  75. --distdir="/bazel-distdir" \
  76. --features=external_include_paths \
  77. --keep_going \
  78. --linkopt="-fsanitize=thread" \
  79. --show_timestamps \
  80. --test_env="TSAN_OPTIONS=report_atomic_races=0" \
  81. --test_env="TSAN_SYMBOLIZER_PATH=/opt/llvm/clang/bin/llvm-symbolizer" \
  82. --test_env="TZDIR=/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo" \
  83. --test_output=errors \
  84. --test_tag_filters="-benchmark,-notsan" \
  85. ${BAZEL_EXTRA_ARGS:-}
  86. done
  87. done
  88. done