diff options
author | Paul Bartell <pbartell@amazon.com> | 2021-03-16 13:55:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-16 13:55:01 -0700 |
commit | 6257160ee6bed0aaf429de41395bbec973daf2b0 (patch) | |
tree | 983763840a4466f7219491f178a87106b0f8a267 | |
parent | cbc96ff5966deb6ea730d4da4beaf4c6c4d0ea4e (diff) | |
download | freertos-git-6257160ee6bed0aaf429de41395bbec973daf2b0.tar.gz |
Make the address sanitizer optional for CMock kernel unit tests (#526)
* Make the address sanitizer optional
The address sanitizer is now disabled by default for CMock tests because it introduces additional branches into the compiled code. When make is run with the ENABLE_SANITIZER=1 argument, the address sanitizer is enabled and coverage data may not be accurate.
* Change from ifdef to ifeq ($(ENABLE_SANITIZER),1) to address PR comment
-rw-r--r-- | FreeRTOS/Test/CMock/Readme.md | 5 | ||||
-rw-r--r-- | FreeRTOS/Test/CMock/makefile.in | 8 |
2 files changed, 11 insertions, 2 deletions
diff --git a/FreeRTOS/Test/CMock/Readme.md b/FreeRTOS/Test/CMock/Readme.md index 059f65303..e5ce98f8a 100644 --- a/FreeRTOS/Test/CMock/Readme.md +++ b/FreeRTOS/Test/CMock/Readme.md @@ -60,6 +60,11 @@ $ make coverage Would build all unit tests, runs them one after the other, then generates html code coverage and places them in build/coverage with initial file index.html +## Runing tests with Address Sanitizer enabled ## +The GCC address sanitizer can be enabled by passing in "ENABLE_SANITIZER=1" when calling make. + +Note: Enabling the address sanitizer will introduce additional branches that may not be possible to get test coverage of. For this reason, the address sanitizer is not enabled by default. It is recommended that developers enable the address sanitizer when modifying or developing new test cases. + ## Running individual tests From each test directory, you can build, run the test, and generate gcov coverage with the default "all" target like so: ``` diff --git a/FreeRTOS/Test/CMock/makefile.in b/FreeRTOS/Test/CMock/makefile.in index 17ab96cb6..ac56f4ba6 100644 --- a/FreeRTOS/Test/CMock/makefile.in +++ b/FreeRTOS/Test/CMock/makefile.in @@ -41,20 +41,24 @@ CPPFLAGS := # Compiler flags CFLAGS := $(INCLUDE_DIR) -O0 -ggdb -pthread --std=c99 -Werror -Wall -CFLAGS += -fsanitize=address,undefined -fsanitize-recover=address CFLAGS += -fstack-protector-all CFLAGS += -Wformat -Werror=format-security -Werror=array-bounds CFLAGS += -D_FORTIFY_SOURCE=2 +ifeq ($(ENABLE_SANITIZER),1) + CFLAGS += -fsanitize=address,undefined -fsanitize-recover=address +endif # Linker flags LDFLAGS := -L$(LIB_DIR) -Wl,-rpath,$(LIB_DIR) -LDFLAGS += -fsanitize=address,undefined LDFLAGS += -pthread LDFLAGS += -lunity LDFLAGS += -lunitymemory LDFLAGS += -lcexception LDFLAGS += -lcmock LDFLAGS += -lgcov +ifeq ($(ENABLE_SANITIZER),1) + LDFLAGS += -fsanitize=address,undefined +endif # Shared libraries LIBS := libunity |