1#!/bin/bash 2# 3# Copyright 2020, Google Inc. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: 9# 10# * Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# * Redistributions in binary form must reproduce the above 13# copyright notice, this list of conditions and the following disclaimer 14# in the documentation and/or other materials provided with the 15# distribution. 16# * Neither the name of Google Inc. nor the names of its 17# contributors may be used to endorse or promote products derived from 18# this software without specific prior written permission. 19# 20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 32set -euox pipefail 33 34readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20240523" 35readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20230120" 36 37if [[ -z ${GTEST_ROOT:-} ]]; then 38 GTEST_ROOT="$(realpath $(dirname ${0})/..)" 39fi 40 41if [[ -z ${STD:-} ]]; then 42 STD="c++14 c++17 c++20" 43fi 44 45# Test the CMake build 46for cc in /usr/local/bin/gcc /opt/llvm/clang/bin/clang; do 47 for cmake_off_on in OFF ON; do 48 time docker run \ 49 --volume="${GTEST_ROOT}:/src:ro" \ 50 --tmpfs="/build:exec" \ 51 --workdir="/build" \ 52 --rm \ 53 --env="CC=${cc}" \ 54 --env=CXXFLAGS="-Werror -Wdeprecated" \ 55 ${LINUX_LATEST_CONTAINER} \ 56 /bin/bash -c " 57 cmake /src \ 58 -DCMAKE_CXX_STANDARD=14 \ 59 -Dgtest_build_samples=ON \ 60 -Dgtest_build_tests=ON \ 61 -Dgmock_build_tests=ON \ 62 -Dcxx_no_exception=${cmake_off_on} \ 63 -Dcxx_no_rtti=${cmake_off_on} && \ 64 make -j$(nproc) && \ 65 ctest -j$(nproc) --output-on-failure" 66 done 67done 68 69# Do one test with an older version of GCC 70# TODO(googletest-team): This currently uses Bazel 5. When upgrading to a 71# version of Bazel that supports Bzlmod, add --enable_bzlmod=false to keep test 72# coverage for the old WORKSPACE dependency management. 73time docker run \ 74 --volume="${GTEST_ROOT}:/src:ro" \ 75 --workdir="/src" \ 76 --rm \ 77 --env="CC=/usr/local/bin/gcc" \ 78 --env="BAZEL_CXXOPTS=-std=c++14" \ 79 ${LINUX_GCC_FLOOR_CONTAINER} \ 80 /usr/local/bin/bazel test ... \ 81 --copt="-Wall" \ 82 --copt="-Werror" \ 83 --copt="-Wuninitialized" \ 84 --copt="-Wundef" \ 85 --copt="-Wno-error=pragmas" \ 86 --features=external_include_paths \ 87 --keep_going \ 88 --show_timestamps \ 89 --test_output=errors 90 91# Test GCC 92for std in ${STD}; do 93 for absl in 0 1; do 94 time docker run \ 95 --volume="${GTEST_ROOT}:/src:ro" \ 96 --workdir="/src" \ 97 --rm \ 98 --env="CC=/usr/local/bin/gcc" \ 99 --env="BAZEL_CXXOPTS=-std=${std}" \ 100 ${LINUX_LATEST_CONTAINER} \ 101 /usr/local/bin/bazel test ... \ 102 --copt="-Wall" \ 103 --copt="-Werror" \ 104 --copt="-Wuninitialized" \ 105 --copt="-Wundef" \ 106 --define="absl=${absl}" \ 107 --enable_bzlmod=true \ 108 --features=external_include_paths \ 109 --keep_going \ 110 --show_timestamps \ 111 --test_output=errors 112 done 113done 114 115# Test Clang 116for std in ${STD}; do 117 for absl in 0 1; do 118 time docker run \ 119 --volume="${GTEST_ROOT}:/src:ro" \ 120 --workdir="/src" \ 121 --rm \ 122 --env="CC=/opt/llvm/clang/bin/clang" \ 123 --env="BAZEL_CXXOPTS=-std=${std}" \ 124 ${LINUX_LATEST_CONTAINER} \ 125 /usr/local/bin/bazel test ... \ 126 --copt="--gcc-toolchain=/usr/local" \ 127 --copt="-Wall" \ 128 --copt="-Werror" \ 129 --copt="-Wuninitialized" \ 130 --copt="-Wundef" \ 131 --define="absl=${absl}" \ 132 --enable_bzlmod=true \ 133 --features=external_include_paths \ 134 --keep_going \ 135 --linkopt="--gcc-toolchain=/usr/local" \ 136 --show_timestamps \ 137 --test_output=errors 138 done 139done 140