From ae27dd60a61913b0101eefd1228745172abd955e Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Sun, 27 Oct 2019 17:19:11 -0400 Subject: [PATCH] Jenkins re-enable clang-tidy and update .clang-tidy - device/Device: fix explicit constructor and uninitialized fields - systemcmds/motor_test: update NULL to nullptr --- .clang-tidy | 188 +++++++++-------- Jenkinsfile | 41 ++-- .../px4_work_queue/WorkItem.hpp | 7 +- src/lib/drivers/device/Device.hpp | 8 +- src/systemcmds/motor_test/motor_test.cpp | 18 +- src/systemcmds/tests/.clang-tidy | 194 +++++++++++------- 6 files changed, 266 insertions(+), 190 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 3ceae6ad0f..fd4a125dda 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,78 +1,111 @@ -Checks: '* - ,-cert-dcl50-cpp - ,-cert-env33-c - ,-cert-err34-c - ,-cert-err58-cpp - ,-cert-msc30-c - ,-cert-msc50-cpp - ,-clang-analyzer-core.CallAndMessage - ,-clang-analyzer-core.NullDereference - ,-clang-analyzer-core.UndefinedBinaryOperatorResult - ,-clang-analyzer-core.uninitialized.Assign - ,-clang-analyzer-core.VLASize - ,-clang-analyzer-cplusplus.NewDelete - ,-clang-analyzer-cplusplus.NewDeleteLeaks - ,-clang-analyzer-deadcode.DeadStores - ,-clang-analyzer-optin.cplusplus.VirtualCall - ,-clang-analyzer-optin.performance.Padding - ,-clang-analyzer-security.insecureAPI.strcpy - ,-clang-analyzer-unix.API - ,-clang-analyzer-unix.cstring.BadSizeArg - ,-clang-analyzer-unix.Malloc - ,-clang-analyzer-unix.MallocSizeof - ,-cppcoreguidelines-c-copy-assignment-signature - ,-cppcoreguidelines-interfaces-global-init - ,-cppcoreguidelines-no-malloc - ,-cppcoreguidelines-pro-bounds-array-to-pointer-decay - ,-cppcoreguidelines-pro-bounds-constant-array-index - ,-cppcoreguidelines-pro-bounds-pointer-arithmetic - ,-cppcoreguidelines-pro-type-const-cast - ,-cppcoreguidelines-pro-type-cstyle-cast - ,-cppcoreguidelines-pro-type-member-init - ,-cppcoreguidelines-pro-type-reinterpret-cast - ,-cppcoreguidelines-pro-type-union-access - ,-cppcoreguidelines-pro-type-vararg - ,-cppcoreguidelines-special-member-functions - ,-google-build-using-namespace - ,-google-explicit-constructor - ,-google-global-names-in-headers - ,-google-readability-casting - ,-google-readability-namespace-comments - ,-google-readability-todo - ,-google-runtime-int - ,-google-runtime-references - ,-llvm-header-guard - ,-llvm-include-order - ,-llvm-namespace-comment - ,-misc-incorrect-roundings - ,-misc-macro-parentheses - ,-misc-misplaced-widening-cast - ,-misc-redundant-expression - ,-misc-unconventional-assign-operator - ,-misc-unused-parameters - ,-modernize-deprecated-headers - ,-modernize-loop-convert - ,-modernize-use-auto - ,-modernize-use-bool-literals - ,-modernize-use-default-member-init - ,-modernize-use-emplace - ,-modernize-use-equals-default - ,-modernize-use-equals-delete - ,-modernize-use-override - ,-modernize-use-using - ,-modernize-pass-by-value - ,-performance-inefficient-string-concatenation - ,-readability-avoid-const-params-in-decls - ,-readability-else-after-return - ,-readability-implicit-bool-cast - ,-readability-inconsistent-declaration-parameter-name - ,-readability-non-const-parameter - ,-readability-redundant-declaration - ,-readability-redundant-member-init - ,-readability-simplify-boolean-expr - ' +--- +Checks: '*, + -android*, + -bugprone-integer-division, + -cert-dcl50-cpp, + -cert-env33-c, + -cert-err34-c, + -cert-err58-cpp, + -cert-msc30-c, + -cert-msc50-cpp, + -clang-analyzer-core.CallAndMessage, + -clang-analyzer-core.NullDereference, + -clang-analyzer-core.UndefinedBinaryOperatorResult, + -clang-analyzer-core.uninitialized.Assign, + -clang-analyzer-core.VLASize, + -clang-analyzer-cplusplus.NewDelete, + -clang-analyzer-cplusplus.NewDeleteLeaks, + -clang-analyzer-deadcode.DeadStores, + -clang-analyzer-optin.cplusplus.VirtualCall, + -clang-analyzer-optin.performance.Padding, + -clang-analyzer-security.insecureAPI.strcpy, + -clang-analyzer-unix.API, + -clang-analyzer-unix.cstring.BadSizeArg, + -clang-analyzer-unix.Malloc, + -clang-analyzer-unix.MallocSizeof, + -cppcoreguidelines-c-copy-assignment-signature, + -cppcoreguidelines-interfaces-global-init, + -cppcoreguidelines-no-malloc, + -cppcoreguidelines-owning-memory, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -cppcoreguidelines-pro-bounds-constant-array-index, + -cppcoreguidelines-pro-bounds-pointer-arithmetic, + -cppcoreguidelines-pro-type-const-cast, + -cppcoreguidelines-pro-type-cstyle-cast, + -cppcoreguidelines-pro-type-member-init, + -cppcoreguidelines-pro-type-reinterpret-cast, + -cppcoreguidelines-pro-type-union-access, + -cppcoreguidelines-pro-type-vararg, + -cppcoreguidelines-special-member-functions, + -fuchsia-default-arguments, + -fuchsia-overloaded-operator, + -google-build-using-namespace, + -google-explicit-constructor, + -google-global-names-in-headers, + -google-readability-casting, + -google-readability-function-size, + -google-readability-namespace-comments, + -google-readability-todo, + -google-runtime-int, + -google-runtime-references, + -hicpp-braces-around-statements, + -hicpp-deprecated-headers, + -hicpp-explicit-conversions, + -hicpp-function-size, + -hicpp-member-init, + -hicpp-no-array-decay, + -hicpp-no-assembler, + -hicpp-no-malloc, + -hicpp-signed-bitwise, + -hicpp-special-member-functions, + -hicpp-use-auto, + -hicpp-use-equals-default, + -hicpp-use-equals-delete, + -hicpp-use-override, + -hicpp-vararg, + -llvm-header-guard, + -llvm-include-order, + -llvm-namespace-comment, + -misc-incorrect-roundings, + -misc-macro-parentheses, + -misc-misplaced-widening-cast, + -misc-redundant-expression, + -misc-unconventional-assign-operator, + -misc-unused-parameters, + -modernize-deprecated-headers, + -modernize-loop-convert, + -modernize-pass-by-value, + -modernize-return-braced-init-list, + -modernize-use-auto, + -modernize-use-bool-literals, + -modernize-use-default-member-init, + -modernize-use-emplace, + -modernize-use-equals-default, + -modernize-use-equals-delete, + -modernize-use-override, + -modernize-use-using, + -performance-inefficient-string-concatenation, + -performance-unnecessary-value-param, + -readability-avoid-const-params-in-decls, + -readability-braces-around-statements, + -readability-container-size-empty, + -readability-delete-null-pointer, + -readability-else-after-return, + -readability-function-size, + -readability-implicit-bool-cast, + -readability-implicit-bool-conversion, + -readability-inconsistent-declaration-parameter-name, + -readability-named-parameter, + -readability-non-const-parameter, + -readability-redundant-control-flow, + -readability-redundant-declaration, + -readability-redundant-member-init, + -readability-simplify-boolean-expr, + -readability-static-accessed-through-instance, + -readability-static-definition-in-anonymous-namespace, + ' WarningsAsErrors: '*' -CheckOptions: +CheckOptions: - key: google-readability-braces-around-statements.ShortStatementLines value: '1' - key: google-readability-function-size.BranchThreshold @@ -81,9 +114,4 @@ CheckOptions: value: '4000' - key: google-readability-function-size.StatementThreshold value: '4000' - - key: readability-braces-around-statements.ShortStatementLines - value: '1' - - key: readability-function-size.LineThreshold - value: '4000' - - key: readability-function-size.StatementThreshold - value: '4000' +... diff --git a/Jenkinsfile b/Jenkinsfile index 3cab0aa23e..38364255cf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -305,26 +305,27 @@ pipeline { } } - // stage('Clang tidy') { - // agent { - // docker { - // image 'px4io/px4-dev-clang:2019-10-24' - // args '-e CCACHE_BASEDIR=$WORKSPACE -v ${CCACHE_DIR}:${CCACHE_DIR}:rw' - // } - // } - // steps { - // sh 'export' - // retry (3) { - // sh 'make distclean' - // sh 'make clang-tidy-quiet' - // } - // } - // post { - // always { - // sh 'make distclean' - // } - // } - // } + stage('Clang tidy') { + agent { + docker { + image 'px4io/px4-dev-clang:2019-10-24' + args '-e CCACHE_BASEDIR=$WORKSPACE -v ${CCACHE_DIR}:${CCACHE_DIR}:rw' + } + } + steps { + sh 'export' + sh 'make distclean' + sh 'git fetch --tags' + retry (3) { + sh 'make clang-tidy-quiet' + } + } + post { + always { + sh 'make distclean' + } + } + } stage('Cppcheck') { agent { diff --git a/platforms/common/include/px4_platform_common/px4_work_queue/WorkItem.hpp b/platforms/common/include/px4_platform_common/px4_work_queue/WorkItem.hpp index a99099e295..d229499b62 100644 --- a/platforms/common/include/px4_platform_common/px4_work_queue/WorkItem.hpp +++ b/platforms/common/include/px4_platform_common/px4_work_queue/WorkItem.hpp @@ -49,7 +49,12 @@ class WorkItem : public ListNode, public IntrusiveQueueNodeAdd(this); } + inline void ScheduleNow() + { + if (_wq != nullptr) { + _wq->Add(this); + } + } virtual void print_run_status() const; diff --git a/src/lib/drivers/device/Device.hpp b/src/lib/drivers/device/Device.hpp index baa7c8017a..5d734a6522 100644 --- a/src/lib/drivers/device/Device.hpp +++ b/src/lib/drivers/device/Device.hpp @@ -216,7 +216,7 @@ public: */ static int device_id_print_buffer(char *buffer, int length, uint32_t id) { - DeviceId dev_id; + DeviceId dev_id{}; dev_id.devid = id; int num_written = snprintf(buffer, length, "Type: 0x%02X, %s:%d (0x%02X)", dev_id.devid_s.devtype, @@ -228,12 +228,12 @@ public: } protected: - union DeviceId _device_id; /**< device identifier information */ + union DeviceId _device_id {}; /**< device identifier information */ - const char *_name; /**< driver name */ + const char *_name{nullptr}; /**< driver name */ bool _debug_enabled{false}; /**< if true, debug messages are printed */ - Device(const char *name) : _name(name) + explicit Device(const char *name) : _name(name) { /* setup a default device ID. When bus_type is UNKNOWN the other fields are invalid */ diff --git a/src/systemcmds/motor_test/motor_test.cpp b/src/systemcmds/motor_test/motor_test.cpp index dfbd525d7c..6aa1b52b5f 100644 --- a/src/systemcmds/motor_test/motor_test.cpp +++ b/src/systemcmds/motor_test/motor_test.cpp @@ -74,7 +74,7 @@ void motor_test(unsigned channel, float value, uint8_t driver_instance, int time static void usage(const char *reason) { - if (reason != NULL) { + if (reason != nullptr) { PX4_WARN("%s", reason); } @@ -108,23 +108,23 @@ int motor_test_main(int argc, char *argv[]) int timeout_ms = 0; int myoptind = 1; - const char *myoptarg = NULL; + const char *myoptarg = nullptr; while ((ch = px4_getopt(argc, argv, "i:m:p:t:", &myoptind, &myoptarg)) != EOF) { switch (ch) { case 'i': - driver_instance = (uint8_t)strtol(myoptarg, NULL, 0); + driver_instance = (uint8_t)strtol(myoptarg, nullptr, 0); break; case 'm': /* Read in motor number */ - channel = (int)strtol(myoptarg, NULL, 0); + channel = (int)strtol(myoptarg, nullptr, 0); break; case 'p': /* Read in power value */ - lval = strtoul(myoptarg, NULL, 0); + lval = strtoul(myoptarg, nullptr, 0); if (lval > 100) { usage("value invalid"); @@ -135,11 +135,11 @@ int motor_test_main(int argc, char *argv[]) break; case 't': - timeout_ms = strtol(myoptarg, NULL, 0) * 1000; + timeout_ms = strtol(myoptarg, nullptr, 0) * 1000; break; default: - usage(NULL); + usage(nullptr); return 1; } } @@ -166,12 +166,12 @@ int motor_test_main(int argc, char *argv[]) } else if (strcmp("test", argv[myoptind]) == 0) { // nothing to do } else { - usage(NULL); + usage(nullptr); return 0; } } else { - usage(NULL); + usage(nullptr); return 0; } diff --git a/src/systemcmds/tests/.clang-tidy b/src/systemcmds/tests/.clang-tidy index 55b0026214..9d2589717a 100644 --- a/src/systemcmds/tests/.clang-tidy +++ b/src/systemcmds/tests/.clang-tidy @@ -1,77 +1,119 @@ -Checks: '* - ,-cert-dcl50-cpp - ,-cert-err34-c - ,-cert-err58-cpp - ,-cert-flp30-c - ,-cert-msc30-c - ,-cert-msc50-cpp - ,-clang-analyzer-core.CallAndMessage - ,-clang-analyzer-core.NullDereference - ,-clang-analyzer-core.UndefinedBinaryOperatorResult - ,-clang-analyzer-core.uninitialized.Assign - ,-clang-analyzer-core.VLASize - ,-clang-analyzer-cplusplus.NewDeleteLeaks - ,-clang-analyzer-deadcode.DeadStores - ,-clang-analyzer-optin.cplusplus.VirtualCall - ,-clang-analyzer-optin.performance.Padding - ,-clang-analyzer-security.FloatLoopCounter - ,-clang-analyzer-security.insecureAPI.strcpy - ,-clang-analyzer-unix.cstring.BadSizeArg - ,-clang-analyzer-unix.Malloc - ,-clang-analyzer-unix.MallocSizeof - ,-cppcoreguidelines-c-copy-assignment-signature - ,-cppcoreguidelines-interfaces-global-init - ,-cppcoreguidelines-no-malloc - ,-cppcoreguidelines-pro-bounds-array-to-pointer-decay - ,-cppcoreguidelines-pro-bounds-constant-array-index - ,-cppcoreguidelines-pro-bounds-pointer-arithmetic - ,-cppcoreguidelines-pro-type-const-cast - ,-cppcoreguidelines-pro-type-cstyle-cast - ,-cppcoreguidelines-pro-type-member-init - ,-cppcoreguidelines-pro-type-reinterpret-cast - ,-cppcoreguidelines-pro-type-union-access - ,-cppcoreguidelines-pro-type-vararg - ,-cppcoreguidelines-special-member-functions - ,-google-build-using-namespace - ,-google-explicit-constructor - ,-google-global-names-in-headers - ,-google-readability-casting - ,-google-readability-function-size - ,-google-readability-namespace-comments - ,-google-readability-todo - ,-google-runtime-int - ,-google-runtime-references - ,-llvm-header-guard - ,-llvm-include-order - ,-llvm-namespace-comment - ,-misc-incorrect-roundings - ,-misc-macro-parentheses - ,-misc-misplaced-widening-cast - ,-misc-redundant-expression - ,-misc-unconventional-assign-operator - ,-misc-unused-parameters - ,-modernize-deprecated-headers - ,-modernize-loop-convert - ,-modernize-pass-by-value - ,-modernize-use-auto - ,-modernize-use-bool-literals - ,-modernize-use-default-member-init - ,-modernize-use-emplace - ,-modernize-use-equals-default - ,-modernize-use-equals-delete - ,-modernize-use-override - ,-modernize-use-using - ,-performance-inefficient-string-concatenation - ,-readability-avoid-const-params-in-decls - ,-readability-braces-around-statements - ,-readability-else-after-return - ,-readability-function-size - ,-readability-implicit-bool-cast - ,-readability-inconsistent-declaration-parameter-name - ,-readability-named-parameter - ,-readability-non-const-parameter - ,-readability-redundant-declaration - ,-readability-redundant-member-init - ,-readability-simplify-boolean-expr - ' +--- +Checks: '*, + -android*, + -bugprone-integer-division, + -cert-dcl50-cpp, + -cert-env33-c, + -cert-err34-c, + -cert-err58-cpp, + -cert-msc30-c, + -cert-msc50-cpp, + -cert-flp30-c, + -clang-analyzer-core.CallAndMessage, + -clang-analyzer-core.NullDereference, + -clang-analyzer-core.UndefinedBinaryOperatorResult, + -clang-analyzer-core.uninitialized.Assign, + -clang-analyzer-core.VLASize, + -clang-analyzer-cplusplus.NewDelete, + -clang-analyzer-cplusplus.NewDeleteLeaks, + -clang-analyzer-deadcode.DeadStores, + -clang-analyzer-optin.cplusplus.VirtualCall, + -clang-analyzer-optin.performance.Padding, + -clang-analyzer-security.FloatLoopCounter, + -clang-analyzer-security.insecureAPI.strcpy, + -clang-analyzer-unix.API, + -clang-analyzer-unix.cstring.BadSizeArg, + -clang-analyzer-unix.Malloc, + -clang-analyzer-unix.MallocSizeof, + -cppcoreguidelines-c-copy-assignment-signature, + -cppcoreguidelines-interfaces-global-init, + -cppcoreguidelines-no-malloc, + -cppcoreguidelines-owning-memory, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -cppcoreguidelines-pro-bounds-constant-array-index, + -cppcoreguidelines-pro-bounds-pointer-arithmetic, + -cppcoreguidelines-pro-type-const-cast, + -cppcoreguidelines-pro-type-cstyle-cast, + -cppcoreguidelines-pro-type-member-init, + -cppcoreguidelines-pro-type-reinterpret-cast, + -cppcoreguidelines-pro-type-union-access, + -cppcoreguidelines-pro-type-vararg, + -cppcoreguidelines-special-member-functions, + -fuchsia-default-arguments, + -fuchsia-overloaded-operator, + -google-build-using-namespace, + -google-explicit-constructor, + -google-global-names-in-headers, + -google-readability-casting, + -google-readability-function-size, + -google-readability-namespace-comments, + -google-readability-todo, + -google-runtime-int, + -google-runtime-references, + -hicpp-braces-around-statements, + -hicpp-deprecated-headers, + -hicpp-explicit-conversions, + -hicpp-function-size, + -hicpp-member-init, + -hicpp-no-array-decay, + -hicpp-no-assembler, + -hicpp-no-malloc, + -hicpp-signed-bitwise, + -hicpp-special-member-functions, + -hicpp-use-auto, + -hicpp-use-equals-default, + -hicpp-use-equals-delete, + -hicpp-use-override, + -hicpp-vararg, + -llvm-header-guard, + -llvm-include-order, + -llvm-namespace-comment, + -misc-incorrect-roundings, + -misc-macro-parentheses, + -misc-misplaced-widening-cast, + -misc-redundant-expression, + -misc-unconventional-assign-operator, + -misc-unused-parameters, + -modernize-deprecated-headers, + -modernize-loop-convert, + -modernize-pass-by-value, + -modernize-return-braced-init-list, + -modernize-use-auto, + -modernize-use-bool-literals, + -modernize-use-default-member-init, + -modernize-use-emplace, + -modernize-use-equals-default, + -modernize-use-equals-delete, + -modernize-use-override, + -modernize-use-using, + -performance-inefficient-string-concatenation, + -performance-unnecessary-value-param, + -readability-avoid-const-params-in-decls, + -readability-braces-around-statements, + -readability-container-size-empty, + -readability-delete-null-pointer, + -readability-else-after-return, + -readability-function-size, + -readability-implicit-bool-cast, + -readability-implicit-bool-conversion, + -readability-inconsistent-declaration-parameter-name, + -readability-named-parameter, + -readability-non-const-parameter, + -readability-redundant-control-flow, + -readability-redundant-declaration, + -readability-redundant-member-init, + -readability-simplify-boolean-expr, + -readability-static-accessed-through-instance, + -readability-static-definition-in-anonymous-namespace, + ' WarningsAsErrors: '*' +CheckOptions: + - key: google-readability-braces-around-statements.ShortStatementLines + value: '1' + - key: google-readability-function-size.BranchThreshold + value: '600' + - key: google-readability-function-size.LineThreshold + value: '4000' + - key: google-readability-function-size.StatementThreshold + value: '4000' +...