Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Make the unit tests ASAN-clean and run on Travis #131

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,24 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# Unused language features.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")

#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# These flags must be set before we include subdirectories so subprojects
# have these options enabled as well.
if (SANITIZER)
set(COMMON_FLAGS "${COMMON_FLAGS} -g -fno-omit-frame-pointer")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be replaced by -DCMAKE_BUILD_TYPE=Debug in the Makefile?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want the cmake to be usable standalone. Also, ASAN != debug; you could build release (with optimizations) and have asan enabled and generate debug info to print backtraces.

endif ()

if (SANITIZER STREQUAL "asan")
Copy link
Contributor

@grp grp Sep 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use "asan" here? With -DSANITIZE=address it could just be -fsanitize=${SANITIZE}, much less code. Or even just pass it via CMAKE_CXX_FLAGS directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do it this way because "asan" is the name people know about, and because for other sanitizers (e.g.: ubsan), we can't just take the cmake argument and pass it down.

set(COMMON_FLAGS "${COMMON_FLAGS} -fsanitize=address")
elseif (SANITIZER STREQUAL "ubsan")
set(COMMON_FLAGS "${COMMON_FLAGS} -fsanitize=integer -fsanitize=undefined")
elseif (SANITIZER STREQUAL "tsan")
set(COMMON_FLAGS "${COMMON_FLAGS} -fsanitize=thread")
endif ()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS}")
endif ()

# Enable all warnings.
add_compile_options(-Wall -Werror)
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ project := project
cmake := cmake
cmake_flags := -DCMAKE_INSTALL_PREFIX=

ifeq ($(CI),true)
cmake_flags += -DSANITIZER=asan
endif

ninja := $(if $(shell which llbuild),llbuild ninja build,ninja)
ninja_flags := $(if $(shell echo "$$NINJA_JOBS"),-j$(shell echo "$$NINJA_JOBS"),)

Expand Down