Commit 091fa1fd authored by Vladimir Glavnyy's avatar Vladimir Glavnyy Committed by Wouter van Oortmerssen

Add testing of C++ with sanitizers (CI-Docker) (#5631)

* Add C++ build testing with clang and gcc

This adds Dockerfiles which test building flatc and the C++ library against clang
and gcc. See discussion at #5119.  It is derived from the Travis CI tooling.

The GRPC tests are failing due to #5099 so those are commented out.

These are run from the .travis.yml file rather than the tests/docker/languages
folder because the builds may each take longer than 30 minutes and were hitting
Travis timeouts.

Parallel builds and build caching attempt to keep the build times low.

* Add GCC 8.3 and Clang 7.0 with sanitizers into CI (based on #5130)

- Add a docker based on Debian Buster.
- Add C++ building scripts for the docker.
- Leak-sanitizer requires SYS_PTRACE.
parent ff3781dc
......@@ -15,10 +15,15 @@
# limitations under the License.
set -e
# build flatc on debian once to speed up the test loop below
docker build -t build_flatc_debian_stretch -f tests/docker/Dockerfile.testing.build_flatc_debian_stretch .
BUILD_CONTAINER_ID=$(docker create --read-only build_flatc_debian_stretch)
docker cp ${BUILD_CONTAINER_ID}:/code/flatc flatc_debian_stretch
docker build -t build_cpp_image -f tests/docker/Dockerfile.testing.cpp.debian_buster .
# Run tests with sanitizers (--cap-add SYS_PTRACE), both GCC and Clang.
cpp_test_args="--cap-add SYS_PTRACE build_cpp_image sh ./tests/docker/cpp_test.run.sh Debug"
docker run --rm $cpp_test_args
docker run --rm --env CC=/usr/bin/clang --env CXX=/usr/bin/clang++ $cpp_test_args
# Build flatc on debian once to speed up the test loop below.
docker run --name flatc_container build_cpp_image sh ./tests/docker/build_flatc.run.sh Debug
# All dependent dockers refer to 'flatc_debian_stretch'.
docker cp flatc_container:/flatbuffers/flatc flatc_debian_stretch
for f in $(ls tests/docker/languages | sort)
do
......
......@@ -13,6 +13,8 @@ option(FLATBUFFERS_BUILD_FLATLIB "Enable the build of the flatbuffers library"
ON)
option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler"
ON)
option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag"
OFF)
option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON)
option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF)
option(FLATBUFFERS_BUILD_SHAREDLIB
......@@ -295,6 +297,9 @@ if(FLATBUFFERS_BUILD_FLATC)
# Make flatc.exe not depend on runtime dlls for easy distribution.
target_compile_options(flatc PUBLIC $<$<CONFIG:Release>:/MT>)
endif()
if(FLATBUFFERS_STATIC_FLATC AND NOT MSVC)
target_link_libraries(flatc PRIVATE -static)
endif()
endif()
if(FLATBUFFERS_BUILD_FLATHASH)
......
FROM debian:10.1-slim as base
RUN apt -qq update >/dev/null
RUN apt -qq install -y cmake make build-essential >/dev/null
RUN apt -qq install -y autoconf git libtool >/dev/null
RUN apt -qq install -y clang >/dev/null
FROM base
# Travis machines have 2 cores. Can be redefined with 'run --env PAR_JOBS=N'.
ENV JOBS=2
WORKDIR /flatbuffers
ADD . .
set -e
JOBS=${JOBS:-1}
config=$1
echo ""
echo "Build 'flatc' compiler for '$config'"
cmake . -DCMAKE_BUILD_TYPE=$config \
-DFLATBUFFERS_BUILD_FLATC=1 -DFLATBUFFERS_STATIC_FLATC=1 \
-DFLATBUFFERS_BUILD_TESTS=0 -DFLATBUFFERS_INSTALL=0
cmake --build . --target flatc --clean-first -- -j$JOBS
echo "Check generated code"
.travis/check-generate-code.sh
echo "Done"
set -e
JOBS=${JOBS:-1}
export UBSAN_OPTIONS=halt_on_error=1
export ASAN_OPTIONS=halt_on_error=1
export MAKEFLAGS="-j$JOBS"
config=$1
echo ""
echo "Build Flatbuffers project for '$config' with jobs=$JOBS"
cmake . -DCMAKE_BUILD_TYPE=$config \
-DFLATBUFFERS_BUILD_TESTS=ON -DFLATBUFFERS_CODE_SANITIZE=ON
cmake --build . --target all --clean-first -- -j$JOBS
ctest --extra-verbose --output-on-failure -j$JOBS
echo "Check generated code"
.travis/check-generate-code.sh
echo "C++ tests done"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment