Browse Source

Add optional CSA checker to tests

To run full tests with the static analyzer:
cmake -DBUILD_TESTING_ANALYZER=1 -DCMAKE_BUILD_TYPE=Debug .. && make CTEST_OUTPUT_ON_FAILURE=1 all test
Christian W. Zuckschwerdt 3 months ago
parent
commit
70c506e6b9
2 changed files with 25 additions and 0 deletions
  1. 6 0
      CMakeLists.txt
  2. 19 0
      tests/CMakeLists.txt

+ 6 - 0
CMakeLists.txt

@@ -195,6 +195,12 @@ if(BUILD_DOCUMENTATION)
     #    install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/html DESTINATION share/doc)
 endif()
 
+########################################################################
+# Build tests with analyzer
+########################################################################
+option(BUILD_TESTING_ANALYZER "Build the testing tree with static
+analyzer (requires Clang)" OFF)
+
 ########################################################################
 # Build tests
 ########################################################################

+ 19 - 0
tests/CMakeLists.txt

@@ -42,3 +42,22 @@ list(REMOVE_ITEM STYLE_CHECK_FILES
     "${CMAKE_CURRENT_SOURCE_DIR}/../include/mongoose.h"
     "${CMAKE_CURRENT_SOURCE_DIR}/../src/mongoose.c")
 add_test(style-check style-check ${STYLE_CHECK_FILES})
+
+########################################################################
+# Define clang static analyzer checks
+########################################################################
+if(BUILD_TESTING_ANALYZER)
+file(GLOB ANALYZER_CHECK_FILES  ../include/*.h ../src/*.c ../src/devices/*.c)
+list(REMOVE_ITEM ANALYZER_CHECK_FILES
+    "${CMAKE_CURRENT_SOURCE_DIR}/../include/mongoose.h"
+    "${CMAKE_CURRENT_SOURCE_DIR}/../src/mongoose.c")
+add_test(clang-analyzer
+    clang
+    -I${CMAKE_CURRENT_SOURCE_DIR}/../include
+    --analyze
+    -Xanalyzer
+    -analyzer-output=text
+    -Xanalyzer
+    -analyzer-disable-checker=deadcode.DeadStores
+    ${ANALYZER_CHECK_FILES})
+endif()