Skip to content

Commit 7c96d1b

Browse files
committed
Add AddressSanitizer to CI tests
1 parent d33f058 commit 7c96d1b

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

.github/workflows/build-check.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Build & run tests
3131
run: |
3232
sudo apt install -y ninja-build
33-
CMAKE_GENERATOR=Ninja make test
33+
CMAKE_GENERATOR=Ninja ASAN=ON make test
3434
3535
check_format:
3636
name: Check codebase format with clang-format
@@ -290,6 +290,6 @@ jobs:
290290
- name: Build & test pico
291291
run: |
292292
sudo apt install -y ninja-build
293-
CMAKE_GENERATOR=Ninja make
293+
CMAKE_GENERATOR=Ninja ASAN=ON make
294294
python3 ./build/tests/no_router.py
295295
timeout-minutes: 5

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ else()
9797
add_compile_options(-Wpedantic)
9898
endif()
9999
# add_compile_options(-Wconversion)
100-
# add_link_options(-fsanitize=address)
101100
elseif(MSVC)
102101
add_compile_options(/W4 /WX /Od /wd4127)
103102
elseif(CMAKE_SYSTEM_NAME MATCHES "Generic")
@@ -379,12 +378,14 @@ option(BUILD_EXAMPLES "Use this to also build the examples." ON)
379378
option(BUILD_TOOLS "Use this to also build the tools." OFF)
380379
option(BUILD_TESTING "Use this to also build tests." ON)
381380
option(BUILD_INTEGRATION "Use this to also build integration tests." OFF)
381+
option(ASAN "Enable AddressSanitizer." OFF)
382382

383383
message(STATUS "Produce Debian and RPM packages: ${PACKAGING}")
384384
message(STATUS "Build examples: ${BUILD_EXAMPLES}")
385385
message(STATUS "Build tools: ${BUILD_TOOLS}")
386386
message(STATUS "Build tests: ${BUILD_TESTING}")
387387
message(STATUS "Build integration: ${BUILD_INTEGRATION}")
388+
message(STATUS "AddressSanitizer: ${ASAN}")
388389

389390
set(PICO_LIBS "")
390391
if(PICO_STATIC)
@@ -453,6 +454,11 @@ if(BUILD_EXAMPLES)
453454
add_subdirectory(examples)
454455
endif()
455456

457+
if(ASAN)
458+
add_compile_options(-fsanitize=address)
459+
add_link_options(-fsanitize=address)
460+
endif()
461+
456462
if(UNIX OR MSVC)
457463
if(BUILD_TOOLS)
458464
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tools)

GNUmakefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ BUILD_TOOLS?=OFF
4141
# Accepted values: ON, OFF
4242
FORCE_C99?=OFF
4343

44+
# Enable AddressSanitizer.
45+
# Accepted values: ON, OFF
46+
ASAN?=OFF
47+
4448
# Debug level. This sets the ZENOH_DEBUG variable.
4549
# Accepted values:
4650
# 0: NONE
@@ -82,7 +86,7 @@ CMAKE_OPT=-DZENOH_DEBUG=$(ZENOH_DEBUG) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DCMAK
8286
-DZ_FEATURE_MULTI_THREAD=$(Z_FEATURE_MULTI_THREAD) -DZ_FEATURE_INTEREST=$(Z_FEATURE_INTEREST) -DZ_FEATURE_UNSTABLE_API=$(Z_FEATURE_UNSTABLE_API)\
8387
-DZ_FEATURE_PUBLICATION=$(Z_FEATURE_PUBLICATION) -DZ_FEATURE_SUBSCRIPTION=$(Z_FEATURE_SUBSCRIPTION) -DZ_FEATURE_QUERY=$(Z_FEATURE_QUERY) -DZ_FEATURE_QUERYABLE=$(Z_FEATURE_QUERYABLE)\
8488
-DZ_FEATURE_RAWETH_TRANSPORT=$(Z_FEATURE_RAWETH_TRANSPORT) -DFRAG_MAX_SIZE=$(FRAG_MAX_SIZE) -DBATCH_UNICAST_SIZE=$(BATCH_UNICAST_SIZE) -DBATCH_MULTICAST_SIZE=$(BATCH_MULTICAST_SIZE)\
85-
-DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.
89+
-DASAN=$(ASAN) -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.
8690

8791
ifeq ($(FORCE_C99), ON)
8892
CMAKE_OPT += -DCMAKE_C_STANDARD=99

0 commit comments

Comments
 (0)