xref: /freebsd/contrib/googletest/ci/linux-presubmit.sh (revision 5ca8c28cd8c725b81781201cfdb5f9969396f934)
128f6c2f2SEnji Cooper#!/bin/bash
228f6c2f2SEnji Cooper#
328f6c2f2SEnji Cooper# Copyright 2020, Google Inc.
428f6c2f2SEnji Cooper# All rights reserved.
528f6c2f2SEnji Cooper#
628f6c2f2SEnji Cooper# Redistribution and use in source and binary forms, with or without
728f6c2f2SEnji Cooper# modification, are permitted provided that the following conditions are
828f6c2f2SEnji Cooper# met:
928f6c2f2SEnji Cooper#
1028f6c2f2SEnji Cooper#     * Redistributions of source code must retain the above copyright
1128f6c2f2SEnji Cooper# notice, this list of conditions and the following disclaimer.
1228f6c2f2SEnji Cooper#     * Redistributions in binary form must reproduce the above
1328f6c2f2SEnji Cooper# copyright notice, this list of conditions and the following disclaimer
1428f6c2f2SEnji Cooper# in the documentation and/or other materials provided with the
1528f6c2f2SEnji Cooper# distribution.
1628f6c2f2SEnji Cooper#     * Neither the name of Google Inc. nor the names of its
1728f6c2f2SEnji Cooper# contributors may be used to endorse or promote products derived from
1828f6c2f2SEnji Cooper# this software without specific prior written permission.
1928f6c2f2SEnji Cooper#
2028f6c2f2SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2128f6c2f2SEnji Cooper# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2228f6c2f2SEnji Cooper# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2328f6c2f2SEnji Cooper# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2428f6c2f2SEnji Cooper# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2528f6c2f2SEnji Cooper# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2628f6c2f2SEnji Cooper# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2728f6c2f2SEnji Cooper# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2828f6c2f2SEnji Cooper# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2928f6c2f2SEnji Cooper# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3028f6c2f2SEnji Cooper# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3128f6c2f2SEnji Cooper
3228f6c2f2SEnji Cooperset -euox pipefail
3328f6c2f2SEnji Cooper
34*5ca8c28cSEnji Cooperreadonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20240523"
3528f6c2f2SEnji Cooperreadonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20230120"
3628f6c2f2SEnji Cooper
3728f6c2f2SEnji Cooperif [[ -z ${GTEST_ROOT:-} ]]; then
3828f6c2f2SEnji Cooper  GTEST_ROOT="$(realpath $(dirname ${0})/..)"
3928f6c2f2SEnji Cooperfi
4028f6c2f2SEnji Cooper
4128f6c2f2SEnji Cooperif [[ -z ${STD:-} ]]; then
4228f6c2f2SEnji Cooper  STD="c++14 c++17 c++20"
4328f6c2f2SEnji Cooperfi
4428f6c2f2SEnji Cooper
4528f6c2f2SEnji Cooper# Test the CMake build
4628f6c2f2SEnji Cooperfor cc in /usr/local/bin/gcc /opt/llvm/clang/bin/clang; do
4728f6c2f2SEnji Cooper  for cmake_off_on in OFF ON; do
4828f6c2f2SEnji Cooper    time docker run \
4928f6c2f2SEnji Cooper      --volume="${GTEST_ROOT}:/src:ro" \
5028f6c2f2SEnji Cooper      --tmpfs="/build:exec" \
5128f6c2f2SEnji Cooper      --workdir="/build" \
5228f6c2f2SEnji Cooper      --rm \
5328f6c2f2SEnji Cooper      --env="CC=${cc}" \
5428f6c2f2SEnji Cooper      --env=CXXFLAGS="-Werror -Wdeprecated" \
5528f6c2f2SEnji Cooper      ${LINUX_LATEST_CONTAINER} \
5628f6c2f2SEnji Cooper      /bin/bash -c "
5728f6c2f2SEnji Cooper        cmake /src \
5828f6c2f2SEnji Cooper          -DCMAKE_CXX_STANDARD=14 \
5928f6c2f2SEnji Cooper          -Dgtest_build_samples=ON \
6028f6c2f2SEnji Cooper          -Dgtest_build_tests=ON \
6128f6c2f2SEnji Cooper          -Dgmock_build_tests=ON \
6228f6c2f2SEnji Cooper          -Dcxx_no_exception=${cmake_off_on} \
6328f6c2f2SEnji Cooper          -Dcxx_no_rtti=${cmake_off_on} && \
6428f6c2f2SEnji Cooper        make -j$(nproc) && \
6528f6c2f2SEnji Cooper        ctest -j$(nproc) --output-on-failure"
6628f6c2f2SEnji Cooper  done
6728f6c2f2SEnji Cooperdone
6828f6c2f2SEnji Cooper
6928f6c2f2SEnji Cooper# Do one test with an older version of GCC
70*5ca8c28cSEnji Cooper# TODO(googletest-team): This currently uses Bazel 5. When upgrading to a
71*5ca8c28cSEnji Cooper# version of Bazel that supports Bzlmod, add --enable_bzlmod=false to keep test
72*5ca8c28cSEnji Cooper# coverage for the old WORKSPACE dependency management.
7328f6c2f2SEnji Coopertime docker run \
7428f6c2f2SEnji Cooper  --volume="${GTEST_ROOT}:/src:ro" \
7528f6c2f2SEnji Cooper  --workdir="/src" \
7628f6c2f2SEnji Cooper  --rm \
7728f6c2f2SEnji Cooper  --env="CC=/usr/local/bin/gcc" \
7828f6c2f2SEnji Cooper  --env="BAZEL_CXXOPTS=-std=c++14" \
7928f6c2f2SEnji Cooper  ${LINUX_GCC_FLOOR_CONTAINER} \
8028f6c2f2SEnji Cooper    /usr/local/bin/bazel test ... \
8128f6c2f2SEnji Cooper      --copt="-Wall" \
8228f6c2f2SEnji Cooper      --copt="-Werror" \
8328f6c2f2SEnji Cooper      --copt="-Wuninitialized" \
8428f6c2f2SEnji Cooper      --copt="-Wundef" \
8528f6c2f2SEnji Cooper      --copt="-Wno-error=pragmas" \
8628f6c2f2SEnji Cooper      --features=external_include_paths \
8728f6c2f2SEnji Cooper      --keep_going \
8828f6c2f2SEnji Cooper      --show_timestamps \
8928f6c2f2SEnji Cooper      --test_output=errors
9028f6c2f2SEnji Cooper
9128f6c2f2SEnji Cooper# Test GCC
9228f6c2f2SEnji Cooperfor std in ${STD}; do
9328f6c2f2SEnji Cooper  for absl in 0 1; do
9428f6c2f2SEnji Cooper    time docker run \
9528f6c2f2SEnji Cooper      --volume="${GTEST_ROOT}:/src:ro" \
9628f6c2f2SEnji Cooper      --workdir="/src" \
9728f6c2f2SEnji Cooper      --rm \
9828f6c2f2SEnji Cooper      --env="CC=/usr/local/bin/gcc" \
9928f6c2f2SEnji Cooper      --env="BAZEL_CXXOPTS=-std=${std}" \
10028f6c2f2SEnji Cooper      ${LINUX_LATEST_CONTAINER} \
10128f6c2f2SEnji Cooper      /usr/local/bin/bazel test ... \
10228f6c2f2SEnji Cooper        --copt="-Wall" \
10328f6c2f2SEnji Cooper        --copt="-Werror" \
10428f6c2f2SEnji Cooper        --copt="-Wuninitialized" \
10528f6c2f2SEnji Cooper        --copt="-Wundef" \
10628f6c2f2SEnji Cooper        --define="absl=${absl}" \
107*5ca8c28cSEnji Cooper        --enable_bzlmod=true \
10828f6c2f2SEnji Cooper        --features=external_include_paths \
10928f6c2f2SEnji Cooper        --keep_going \
11028f6c2f2SEnji Cooper        --show_timestamps \
11128f6c2f2SEnji Cooper        --test_output=errors
11228f6c2f2SEnji Cooper  done
11328f6c2f2SEnji Cooperdone
11428f6c2f2SEnji Cooper
11528f6c2f2SEnji Cooper# Test Clang
11628f6c2f2SEnji Cooperfor std in ${STD}; do
11728f6c2f2SEnji Cooper  for absl in 0 1; do
11828f6c2f2SEnji Cooper    time docker run \
11928f6c2f2SEnji Cooper      --volume="${GTEST_ROOT}:/src:ro" \
12028f6c2f2SEnji Cooper      --workdir="/src" \
12128f6c2f2SEnji Cooper      --rm \
12228f6c2f2SEnji Cooper      --env="CC=/opt/llvm/clang/bin/clang" \
12328f6c2f2SEnji Cooper      --env="BAZEL_CXXOPTS=-std=${std}" \
12428f6c2f2SEnji Cooper      ${LINUX_LATEST_CONTAINER} \
12528f6c2f2SEnji Cooper      /usr/local/bin/bazel test ... \
12628f6c2f2SEnji Cooper        --copt="--gcc-toolchain=/usr/local" \
12728f6c2f2SEnji Cooper        --copt="-Wall" \
12828f6c2f2SEnji Cooper        --copt="-Werror" \
12928f6c2f2SEnji Cooper        --copt="-Wuninitialized" \
13028f6c2f2SEnji Cooper        --copt="-Wundef" \
13128f6c2f2SEnji Cooper        --define="absl=${absl}" \
132*5ca8c28cSEnji Cooper        --enable_bzlmod=true \
13328f6c2f2SEnji Cooper        --features=external_include_paths \
13428f6c2f2SEnji Cooper        --keep_going \
13528f6c2f2SEnji Cooper        --linkopt="--gcc-toolchain=/usr/local" \
13628f6c2f2SEnji Cooper        --show_timestamps \
13728f6c2f2SEnji Cooper        --test_output=errors
13828f6c2f2SEnji Cooper  done
13928f6c2f2SEnji Cooperdone
140