Skip to content

Commit fa7a860

Browse files
authored
Make cppcheck github workflow (#3000)
Currently works with -DBUILD_TESTING=OFF -DBUILD_UTT=OFF -DUSE_LOG4CPP=OFF
1 parent 4b816a5 commit fa7a860

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+249
-200
lines changed

.cppcheck/exitcode-suppressions.txt

Whitespace-only changes.

.cppcheck/suppressions.txt

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
syntaxError
2-
preprocessorErrorDirective
3-
unknownMacro
4-
missingIncludeSystem
5-
unmatchedSuppression
1+
# Suppressions for concord-bft
2+
# Checked with the following options:
3+
# cmake -DBUILD_TESTING=OFF -DBUILD_UTT=OFF -DUSE_LOG4CPP=OFF -DCPPCHECK=ON ..
4+
# TODO [TK] - do we want enable cppckeck for tests?
65

7-
*:cryptlib.h:*
8-
*:gtest.h:*
6+
incorrectStringBooleanError
7+
uninitMemberVar
8+
noCopyConstructor
9+
noOperatorEq
10+
11+
zerodiv:*ReplicasInfo.cpp
12+
preprocessorErrorDirective:*filesystem.hpp
13+
*:*/proto/*
14+
*:*/_deps/*

.github/workflows/build_and_test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ jobs:
5757
with:
5858
name: artifacts-${{ matrix.ci_build_type }}-${{ matrix.comm_type }}-${{ github.sha }}
5959
path: artifact/
60-
retention-days: 1
60+
retention-days: 7

.github/workflows/cppcheck.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: cppcheck
2+
on: [ push, pull_request ]
3+
4+
concurrency:
5+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
6+
cancel-in-progress: true
7+
8+
jobs:
9+
build:
10+
name: Build
11+
runs-on: ubuntu-22.04
12+
container:
13+
image: concordbft/concord-bft:latest
14+
options: --cap-add=NET_ADMIN
15+
strategy:
16+
fail-fast: false
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
- name: cppcheck
21+
run: |
22+
mkdir build
23+
cd build
24+
echo $(date +%y-%m-%d_%H-%M-%S) > timestamp
25+
cmake -DBUILD_TESTING=OFF -DBUILD_UTT=OFF -DUSE_LOG4CPP=OFF -DCPPCHECK=ON ..
26+
make -j$(nproc)

CMakeLists.txt

+18-121
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ option(USE_HTTPLIB "Enable use of httplib" ON)
3838
option(USE_GRPC "Enable GRPC and Protobuf" ON)
3939
option(USE_OPENSSL "Enable use of OpenSSL" ON)
4040
option(BUILD_THIRDPARTY "Whether to build third party libraries or use preinstalled ones" OFF)
41-
option(CODECOVERAGE "Enable Code Coverage Metrics in Clang" OFF)
4241
option(ENABLE_RESTART_RECOVERY_TESTS "Enable tests for restart recovery" OFF)
4342
option(BUILD_UTT "Build UTT library" ON)
4443
option(BUILD_SHARED_LIBS "whether to create shared libraires" OFF)
@@ -50,131 +49,21 @@ if(SLEEP_FOR_DBG)
5049
add_definitions(-DSLEEP_DBG)
5150
endif()
5251

52+
# include compiler specific options
53+
include(cmake/${CMAKE_CXX_COMPILER_ID}.cmake)
54+
include(cmake/cppcheck.cmake)
5355

54-
#
55-
# Compiler options
56-
#
57-
#
58-
59-
string(APPEND CMAKE_CXX_FLAGS " -Wall")
60-
string(APPEND CMAKE_CXX_FLAGS " -Wbuiltin-macro-redefined")
61-
string(APPEND CMAKE_CXX_FLAGS " -pedantic")
62-
string(APPEND CMAKE_CXX_FLAGS " -Werror")
63-
string(APPEND CMAKE_CXX_FLAGS " -fno-omit-frame-pointer")
64-
65-
# At most, only one of the next options should be defined from below ONLY_ONE_OPT_RAISED_CHECK
66-
set(COUNTER 0)
67-
set(ONLY_ONE_OPT_RAISED_CHECK LEAKCHECK;THREADCHECK;UNDEFINED_BEHAVIOR_CHECK;CODECOVERAGE;HEAPTRACK)
68-
foreach(option IN LISTS ONLY_ONE_OPT_RAISED_CHECK)
69-
if(${option})
70-
MATH(EXPR COUNTER "${COUNTER}+1")
71-
endif()
72-
endforeach()
73-
if(${COUNTER} GREATER 1)
74-
message(FATAL_ERROR "More than one of the following options were chosen: \
75-
LEAKCHECK=${LEAKCHECK} \
76-
THREADCHECK=${THREADCHECK} \
77-
UNDEFINED_BEHAVIOR_CHECK=${UNDEFINED_BEHAVIOR_CHECK} \
78-
CODECOVERAGE=${CODECOVERAGE} \
79-
HEAPTRACK=${HEAPTRACK} \
80-
")
81-
endif()
82-
83-
if(LEAKCHECK)
84-
string(APPEND CMAKE_CXX_FLAGS " -fsanitize=leak -fsanitize=address")
85-
add_compile_definitions(RUN_WITH_LEAKCHECK=1)
86-
message("-- Address and Leak Sanitizers Enabled")
87-
elseif(THREADCHECK)
88-
string(APPEND CMAKE_CXX_FLAGS " -fsanitize=thread")
89-
message("-- Thread Sanitizer Enabled")
90-
elseif(UNDEFINED_BEHAVIOR_CHECK)
91-
string(APPEND CMAKE_CXX_FLAGS " -fsanitize=undefined")
92-
message("-- Undefined Behavior Sanitizer Enabled")
93-
elseif(UNDEFINED_BEHAVIOR_CHECK)
94-
string(APPEND CMAKE_CXX_FLAGS " -fsanitize=undefined")
95-
message("-- Undefined Behavior Sanitizer Enabled")
96-
elseif(HEAPTRACK)
97-
message("-- Heaptrack Enabled")
98-
endif()
99-
100-
101-
if(OMIT_TEST_OUTPUT)
102-
message("-- OMIT_TEST_OUTPUT Enabled")
103-
endif()
104-
if(KEEP_APOLLO_LOGS)
105-
message("-- KEEP_APOLLO_LOGS Enabled")
106-
endif()
107-
if(RUN_APOLLO_TESTS)
108-
message("-- RUN_APOLLO_TESTS Enabled")
109-
endif()
56+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
57+
include(cmake/grpc_utils.cmake)
11058

111-
#
112-
# Code Quality (static, dynamic, coverage) Analysers
113-
#
114-
if(CODECOVERAGE)
115-
string(APPEND CMAKE_CXX_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
116-
string(APPEND CMAKE_EXE_LINKER_FLAGS " -fprofile-instr-generate")
117-
message( "-- Building with llvm Code Coverage Tools")
59+
if(BUILD_TESTING)
60+
include(CTest)
11861
endif()
11962

120-
if(CPPCHECK)
121-
find_program(cppcheck cppcheck HINTS "/usr/local/bin/cppcheck" REQUIRED)
122-
message(STATUS "cppcheck ${cppcheck}")
123-
if(cppcheck MATCHES "NOTFOUND")
124-
message(FATAL_ERROR "failed to find cppcheck executable for CPPCHECK option")
125-
endif()
126-
# Create <cppcheck> work folder for whole program analysis, for faster analysis and to store some useful debug information
127-
# Add cppcheck work folder and reports folder for cppcheck output.
128-
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/cppcheck/reports/)
129-
# max number of threads = number of CPUs
130-
include(ProcessorCount)
131-
ProcessorCount(CPU_CORES)
132-
set(CMAKE_CXX_CPPCHECK
133-
"${cppcheck}"
134-
"--enable=all"
135-
"--inconclusive"
136-
"--inline-suppr"
137-
"--quiet"
138-
"--std=c++17"
139-
"--template=cppcheck1"
140-
"--max-configs=1"
141-
"--library=boost.cfg"
142-
"--library=openssl.cfg"
143-
"--library=googletest"
144-
"--addon=threadsafety.py"
145-
"--cppcheck-build-dir=${PROJECT_BINARY_DIR}/cppcheck/"
146-
"--suppressions-list=${CMAKE_CURRENT_SOURCE_DIR}/.cppcheck/suppressions.txt"
147-
"--exitcode-suppressions=${CMAKE_CURRENT_SOURCE_DIR}/.cppcheck/exitcode-suppressions.txt"
148-
CACHE STRING "Default value for cppcheck CXX_CPPCHECK target property")
149-
endif(CPPCHECK)
150-
15163
if(USE_S3_OBJECT_STORE)
15264
add_compile_definitions(USE_S3_OBJECT_STORE=1)
15365
endif()
154-
# TODO: Figure out right way to deal with -fstrict-overflow / -Wstrict-overflow related errors
155-
# string(APPEND CXX_FLAGS " -fno-strict-overflow")
156-
# Prevents some buffer overflows: https://access.redhat.com/blogs/766093/posts/1976213
157-
string(APPEND CMAKE_CXX_FLAGS_RELEASE " -D_FORTIFY_SOURCE=2")
158-
159-
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -fstack-protector-all")
160-
161-
162-
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
163-
164-
string(APPEND CMAKE_CXX_FLAGS " -ferror-limit=3")
165-
166-
167-
# Export a compile database for use by semantic analysis tools
168-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
169-
170-
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
171-
string(APPEND CMAKE_CXX_FLAGS " -fmax-errors=3")
172-
endif()
173-
174-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
175-
include(cmake/grpc_utils.cmake)
17666

177-
include(CTest)
17867
#
17968
# Subdirectories
18069
#
@@ -207,10 +96,18 @@ endif()
20796
#
20897
# Setup testing
20998
#
210-
211-
option(OMIT_TEST_OUTPUT "Forwards output stdout and stdin to /dev/null" OFF)
212-
21399
if(BUILD_TESTING)
100+
option(OMIT_TEST_OUTPUT "Forwards output stdout and stdin to /dev/null" OFF)
101+
if(OMIT_TEST_OUTPUT)
102+
message("-- OMIT_TEST_OUTPUT Enabled")
103+
endif()
104+
if(KEEP_APOLLO_LOGS)
105+
message("-- KEEP_APOLLO_LOGS Enabled")
106+
endif()
107+
if(RUN_APOLLO_TESTS)
108+
message("-- RUN_APOLLO_TESTS Enabled")
109+
endif()
110+
214111
add_subdirectory(bftengine/tests)
215112
add_subdirectory(tests)
216113
add_subdirectory(messages)

bftengine/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ target_include_directories(corebft PUBLIC include/)
9898
target_include_directories(corebft PUBLIC include/bftengine)
9999
target_include_directories(corebft PUBLIC include/bcstatetransfer)
100100
target_include_directories(corebft PUBLIC include/simplestatetransfer)
101-
target_include_directories(corebft PUBLIC include/metadatastorage)
102101
target_include_directories(corebft PRIVATE src/bftengine)
103102
target_include_directories(corebft PRIVATE src/preprocessor)
104-
target_include_directories(corebft PUBLIC ${perf_include}/performance/include)
105103
target_include_directories(corebft PUBLIC tests/mocks)
106104
target_include_directories(corebft PUBLIC ${Boost_INCLUDE_DIR})
107105
target_link_libraries(corebft PUBLIC

bftengine/include/bftengine/CryptoManager.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class CryptoManager : public IKeyExchanger, public IMultiSigKeyGenerator {
143143
it++;
144144
}
145145
LOG_FATAL(logger(), "Cryptosystem not found for checkpoint: " << chckp << "seqnum: " << sn);
146+
// cppcheck-suppress incorrectStringBooleanError
146147
ConcordAssert(false && "should never reach here");
147148
}
148149
// create CryptoSys for sn if still doesn't exist

bftengine/src/bcstatetransfer/BCStateTran.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ BCStateTran::BCStateTran(const Config &config, IAppState *const stateApi, DataSt
325325

326326
// Make sure that the internal IReplicaForStateTransfer callback is always added, alongside any user-supplied
327327
// callbacks.
328-
addOnTransferringCompleteCallback(
328+
BCStateTran::addOnTransferringCompleteCallback(
329329
[this](uint64_t checkpoint_num) { replicaForStateTransfer_->onTransferringComplete(checkpoint_num); });
330330
}
331331

bftengine/src/bcstatetransfer/InMemoryDataStore.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class InMemoryDataStore : public DataStore {
3131
public:
3232
explicit InMemoryDataStore(uint32_t sizeOfReservedPage);
3333
~InMemoryDataStore() override {
34-
deleteAllPendingPages();
34+
InMemoryDataStore::deleteAllPendingPages();
3535
pages.clear();
3636
}
3737

bftengine/src/bftengine/PersistentStorageDescriptors.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ void DescriptorOfLastExitFromView::serializeSimpleParams(char *buf, size_t bufLe
8080
uint32_t complaintsNum = complaints.size();
8181
size_t complaintsNumSize = sizeof(complaintsNum);
8282
memcpy(buf, &complaintsNum, complaintsNumSize);
83-
buf += complaintsNumSize;
8483

8584
actualSize = isDefaultSize + viewSize + lastStableSize + lastExecutedSize + stableLowerBoundWhenEnteredToViewSize +
8685
myViewChangeMsgSize + elementsNumSize + complaintsNumSize;
@@ -150,7 +149,6 @@ void DescriptorOfLastExitFromView::deserializeSimpleParams(char *buf, size_t buf
150149
uint32_t complaintsNum;
151150
size_t complaintsNumSize = sizeof(complaintsNum);
152151
memcpy(&complaintsNum, buf, complaintsNumSize);
153-
buf += complaintsNumSize;
154152

155153
if (complaintsNum) complaints.resize(complaintsNum);
156154

bftengine/src/bftengine/ReplicasInfo.cpp

+9-11
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,15 @@ bool ReplicasInfo::getCollectorsForPartialProofs(const ReplicaId refReplica,
169169
}
170170
return (collector == refReplica);
171171
} else {
172-
const int16_t n = _numberOfReplicas;
173-
const int16_t c = _cVal;
174172
const int16_t primary = primaryOfView(v);
175173

176-
if (c == 0) {
177-
int16_t collector = (seq % n);
174+
if (_cVal == 0) {
175+
int16_t collector = (seq % _numberOfReplicas);
178176

179177
// ignore primary
180178
if (collector >= primary) {
181-
collector = ((collector + 1) % n);
182-
if (collector == primary) collector = ((collector + 1) % n);
179+
collector = ((collector + 1) % _numberOfReplicas);
180+
if (collector == primary) collector = ((collector + 1) % _numberOfReplicas);
183181
}
184182

185183
if (outNumOfCollectors) {
@@ -189,21 +187,21 @@ bool ReplicasInfo::getCollectorsForPartialProofs(const ReplicaId refReplica,
189187

190188
return (collector == refReplica);
191189
} else {
192-
const int16_t half = (n / 2);
190+
const int16_t half = (_numberOfReplicas / 2);
193191
int16_t collector1 = (seq % half);
194192
int16_t collector2 = collector1 + half;
195193
// int16_t collector1 = (seq % n);
196194
// int16_t collector2 = collector1 + 1;
197195

198196
// ignore primary
199197
if (collector1 >= primary) {
200-
collector1 = ((collector1 + 1) % n);
201-
if (collector1 == primary) collector1 = ((collector1 + 1) % n);
198+
collector1 = ((collector1 + 1) % _numberOfReplicas);
199+
if (collector1 == primary) collector1 = ((collector1 + 1) % _numberOfReplicas);
202200
}
203201

204202
if (collector2 >= primary) {
205-
collector2 = ((collector2 + 1) % n);
206-
if (collector2 == primary) collector2 = ((collector2 + 1) % n);
203+
collector2 = ((collector2 + 1) % _numberOfReplicas);
204+
if (collector2 == primary) collector2 = ((collector2 + 1) % _numberOfReplicas);
207205
}
208206

209207
if (outNumOfCollectors) {

bftengine/src/bftengine/SimpleClientImp.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ class SimpleClientImp : public SimpleClient, public IReceiver {
128128
uint16_t clientSendsRequestToAllReplicasFirstThresh_;
129129
uint16_t clientSendsRequestToAllReplicasPeriodThresh_;
130130
uint16_t clientPeriodicResetThresh_;
131-
std::shared_ptr<concord::performance::PerformanceManager> pm_ = nullptr;
132131

133132
logging::Logger logger_ = logging::getLogger("concord.bft.client");
134133
};
@@ -220,8 +219,7 @@ SimpleClientImp::SimpleClientImp(ICommunication* communication,
220219
p.clientSendsRequestToAllReplicasPeriodThresh),
221220
clientSendsRequestToAllReplicasFirstThresh_{p.clientSendsRequestToAllReplicasFirstThresh},
222221
clientSendsRequestToAllReplicasPeriodThresh_{p.clientSendsRequestToAllReplicasPeriodThresh},
223-
clientPeriodicResetThresh_{p.clientPeriodicResetThresh},
224-
pm_{pm} {
222+
clientPeriodicResetThresh_{p.clientPeriodicResetThresh} {
225223
ConcordAssert(fVal_ >= 1);
226224

227225
timeOfLastTransmission_ = MinTime;

bftengine/src/bftengine/TimeServiceResPageClient.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ constexpr auto RESERVED_PAGE_ID = uint32_t{0};
1919
namespace bftEngine::impl {
2020

2121
TimeServiceResPageClient::TimeServiceResPageClient() {
22+
// cppcheck-suppress incorrectStringBooleanError
2223
ConcordAssert(res_pages_ != nullptr &&
2324
"Reserved pages must be initialized before instantiating TimeServiceResPageClient");
2425
load();

bftengine/src/preprocessor/CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ target_include_directories(preprocessor PUBLIC ${bftengine_SOURCE_DIR}/include)
1818
target_include_directories(preprocessor PUBLIC ${bftengine_SOURCE_DIR}/include/bftengine)
1919
target_include_directories(preprocessor PUBLIC ${bftengine_SOURCE_DIR}/src/bftengine)
2020
get_property(perf_include GLOBAL PROPERTY PERF_MANAGER_INCLUDE_DIR)
21-
get_property(util_include GLOBAL PROPERTY UTIL_INCLUDE_DIR)
2221
get_property(kvbc_include GLOBAL PROPERTY KVBC_INCLUDE_DIR)
23-
target_include_directories(preprocessor PUBLIC ${perf_include} ${util_include} ${kvbc_include})
22+
target_include_directories(preprocessor PUBLIC ${perf_include} ${kvbc_include})
2423

2524
if(BUILD_SLOWDOWN)
2625
target_compile_definitions(preprocessor PUBLIC USE_SLOWDOWN)

bftengine/src/preprocessor/tests/preprocessor_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ TEST(requestPreprocessingState_test, rejectMsgWithInvalidView) {
11521152
int main(int argc, char** argv) {
11531153
::testing::InitGoogleTest(&argc, argv);
11541154
logging::initLogger("logging.properties");
1155-
logging::Logger::getInstance("preprocessor_test").setLogLevel(log4cplus::ERROR_LOG_LEVEL);
1155+
logging::getLogger("preprocessor_test").setLogLevel(logging::ERROR_LOG_LEVEL);
11561156
if (replicaConfig.replicaMsgSigningAlgo == SignatureAlgorithm::EdDSA) {
11571157
replicaPrivKeys = replicaEdDSAPrivKeys;
11581158
replicaPubKeys = replicaEdDSAPubKeys;

client/bftclient/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ target_include_directories(bftclient_new PUBLIC include)
1111
target_include_directories(bftclient_new PUBLIC src)
1212
target_include_directories(bftclient_new PUBLIC ${bftengine_SOURCE_DIR}/src)
1313
target_include_directories(bftclient_new PUBLIC ${bftengine_SOURCE_DIR}/include)
14-
target_include_directories(bftclient_new PUBLIC ${libdiagnostics_SOURCE_DIR}/include)
1514
target_include_directories(bftclient_new PUBLIC ${libbftcommunication_SOURCE_DIR}/include)
1615

1716
target_link_libraries(bftclient_new PRIVATE

0 commit comments

Comments
 (0)