mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 05:53:34 +08:00
Running cppcheck with every build
This commit is contained in:
@@ -26,7 +26,7 @@ add_library(uavcan SHARED ${LIBUAVCAN_CXX_FILES})
|
|||||||
# TODO installation rules
|
# TODO installation rules
|
||||||
|
|
||||||
#
|
#
|
||||||
# Test
|
# Unit tests with gtest (optional)
|
||||||
#
|
#
|
||||||
find_package(GTest QUIET)
|
find_package(GTest QUIET)
|
||||||
if (GTEST_FOUND)
|
if (GTEST_FOUND)
|
||||||
@@ -47,8 +47,15 @@ if (GTEST_FOUND)
|
|||||||
# Tests run automatically upon successful build
|
# Tests run automatically upon successful build
|
||||||
# If failing tests need to be investigated with debugger, use 'make --ignore-errors'
|
# If failing tests need to be investigated with debugger, use 'make --ignore-errors'
|
||||||
add_custom_command(TARGET libuavcan_test POST_BUILD
|
add_custom_command(TARGET libuavcan_test POST_BUILD
|
||||||
COMMAND "./libuavcan_test"
|
COMMAND ./libuavcan_test
|
||||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
else (GTEST_FOUND)
|
else (GTEST_FOUND)
|
||||||
message(">> Google test library is not found, you will not be able to run tests")
|
message(">> Google test library is not found, you will not be able to run tests")
|
||||||
endif (GTEST_FOUND)
|
endif (GTEST_FOUND)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Static analysis with cppcheck (required), both library and unit test sources
|
||||||
|
#
|
||||||
|
add_custom_command(TARGET uavcan PRE_BUILD
|
||||||
|
COMMAND ./cppcheck.sh
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
||||||
|
|||||||
Executable
+10
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# cppcheck static analysis
|
||||||
|
# For Debian based: apt-get install cppcheck
|
||||||
|
#
|
||||||
|
|
||||||
|
# TODO: with future versions of cppcheck, add --library=glibc
|
||||||
|
cppcheck . --error-exitcode=1 --quiet --enable=all --platform=unix64 --std=c99 --std=c++11 \
|
||||||
|
--inconclusive --inline-suppr --force --template=gcc \
|
||||||
|
-Iinclude $@
|
||||||
@@ -30,7 +30,9 @@ struct CanFrame
|
|||||||
CanFrame()
|
CanFrame()
|
||||||
: id(0)
|
: id(0)
|
||||||
, dlc(0)
|
, dlc(0)
|
||||||
{ }
|
{
|
||||||
|
std::memset(data, 0, sizeof(data));
|
||||||
|
}
|
||||||
|
|
||||||
CanFrame(uint32_t id, const uint8_t* data, unsigned int dlc)
|
CanFrame(uint32_t id, const uint8_t* data, unsigned int dlc)
|
||||||
: id(id)
|
: id(id)
|
||||||
|
|||||||
@@ -82,7 +82,10 @@ public:
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction
|
||||||
|
// cppcheck-suppress functionConst
|
||||||
int configureFilters(const uavcan::CanFilterConfig* filter_configs, int num_configs) { return -1; }
|
int configureFilters(const uavcan::CanFilterConfig* filter_configs, int num_configs) { return -1; }
|
||||||
|
// cppcheck-suppress unusedFunction
|
||||||
int getNumFilters() const { return 0; }
|
int getNumFilters() const { return 0; }
|
||||||
uint64_t getNumErrors() const { return num_errors; }
|
uint64_t getNumErrors() const { return num_errors; }
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user