tests: add cgi-io built with clang sanitizers
authorPetr Štetiar <ynezz@true.cz>
Mon, 12 Oct 2020 12:03:59 +0000 (14:03 +0200)
committerPetr Štetiar <ynezz@true.cz>
Tue, 27 Oct 2020 22:03:04 +0000 (23:03 +0100)
Will be used later for testing.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
CMakeLists.txt

index ae37f1f68cfa6308d1901ebe98fb50fe2ebe4a41..acf68086a8016b72367fce1b403c44c9a09cadd3 100644 (file)
@@ -19,7 +19,8 @@ IF(APPLE)
   LINK_DIRECTORIES(/opt/local/lib)
 ENDIF()
 
-ADD_LIBRARY(cgi-lib STATIC multipart_parser.c util.c)
+SET(LIB_SOURCES multipart_parser.c util.c)
+ADD_LIBRARY(cgi-lib STATIC ${LIB_SOURCES})
 
 ADD_EXECUTABLE(cgi-io main.c)
 TARGET_LINK_LIBRARIES(cgi-io cgi-lib ${ubox} ${ubus})
@@ -28,6 +29,18 @@ IF(UNIT_TESTING)
   ADD_DEFINITIONS(-DUNIT_TESTING)
   ENABLE_TESTING()
   ADD_SUBDIRECTORY(tests)
+
+  IF(CMAKE_C_COMPILER_ID STREQUAL "Clang")
+    ADD_LIBRARY(cgi-lib-san SHARED ${LIB_SOURCES})
+    TARGET_COMPILE_OPTIONS(cgi-lib-san PRIVATE -g -fno-omit-frame-pointer -fsanitize=undefined,address,leak -fno-sanitize-recover=all)
+    TARGET_LINK_OPTIONS(cgi-lib-san PRIVATE -fsanitize=undefined,address,leak)
+    TARGET_LINK_LIBRARIES(cgi-lib-san ${ubox} ${ubus})
+
+    ADD_EXECUTABLE(cgi-io-san main.c)
+    TARGET_COMPILE_OPTIONS(cgi-io-san PRIVATE -g -fno-omit-frame-pointer -fsanitize=undefined,address,leak -fno-sanitize-recover=all)
+    TARGET_LINK_OPTIONS(cgi-io-san PRIVATE -fsanitize=undefined,address,leak)
+    TARGET_LINK_LIBRARIES(cgi-io-san cgi-lib-san ${ubox})
+  ENDIF()
 ENDIF()
 
 INSTALL(TARGETS cgi-io RUNTIME DESTINATION sbin)