Browse Source

Jenkins re-enable clang-tidy and update .clang-tidy

- device/Device: fix explicit constructor and uninitialized fields
 - systemcmds/motor_test: update NULL to nullptr
sbg
Daniel Agar 5 years ago committed by GitHub
parent
commit
ae27dd60a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 188
      .clang-tidy
  2. 41
      Jenkinsfile
  3. 7
      platforms/common/include/px4_platform_common/px4_work_queue/WorkItem.hpp
  4. 8
      src/lib/drivers/device/Device.hpp
  5. 18
      src/systemcmds/motor_test/motor_test.cpp
  6. 194
      src/systemcmds/tests/.clang-tidy

188
.clang-tidy

@ -1,78 +1,111 @@
Checks: '* ---
,-cert-dcl50-cpp Checks: '*,
,-cert-env33-c -android*,
,-cert-err34-c -bugprone-integer-division,
,-cert-err58-cpp -cert-dcl50-cpp,
,-cert-msc30-c -cert-env33-c,
,-cert-msc50-cpp -cert-err34-c,
,-clang-analyzer-core.CallAndMessage -cert-err58-cpp,
,-clang-analyzer-core.NullDereference -cert-msc30-c,
,-clang-analyzer-core.UndefinedBinaryOperatorResult -cert-msc50-cpp,
,-clang-analyzer-core.uninitialized.Assign -clang-analyzer-core.CallAndMessage,
,-clang-analyzer-core.VLASize -clang-analyzer-core.NullDereference,
,-clang-analyzer-cplusplus.NewDelete -clang-analyzer-core.UndefinedBinaryOperatorResult,
,-clang-analyzer-cplusplus.NewDeleteLeaks -clang-analyzer-core.uninitialized.Assign,
,-clang-analyzer-deadcode.DeadStores -clang-analyzer-core.VLASize,
,-clang-analyzer-optin.cplusplus.VirtualCall -clang-analyzer-cplusplus.NewDelete,
,-clang-analyzer-optin.performance.Padding -clang-analyzer-cplusplus.NewDeleteLeaks,
,-clang-analyzer-security.insecureAPI.strcpy -clang-analyzer-deadcode.DeadStores,
,-clang-analyzer-unix.API -clang-analyzer-optin.cplusplus.VirtualCall,
,-clang-analyzer-unix.cstring.BadSizeArg -clang-analyzer-optin.performance.Padding,
,-clang-analyzer-unix.Malloc -clang-analyzer-security.insecureAPI.strcpy,
,-clang-analyzer-unix.MallocSizeof -clang-analyzer-unix.API,
,-cppcoreguidelines-c-copy-assignment-signature -clang-analyzer-unix.cstring.BadSizeArg,
,-cppcoreguidelines-interfaces-global-init -clang-analyzer-unix.Malloc,
,-cppcoreguidelines-no-malloc -clang-analyzer-unix.MallocSizeof,
,-cppcoreguidelines-pro-bounds-array-to-pointer-decay -cppcoreguidelines-c-copy-assignment-signature,
,-cppcoreguidelines-pro-bounds-constant-array-index -cppcoreguidelines-interfaces-global-init,
,-cppcoreguidelines-pro-bounds-pointer-arithmetic -cppcoreguidelines-no-malloc,
,-cppcoreguidelines-pro-type-const-cast -cppcoreguidelines-owning-memory,
,-cppcoreguidelines-pro-type-cstyle-cast -cppcoreguidelines-pro-bounds-array-to-pointer-decay,
,-cppcoreguidelines-pro-type-member-init -cppcoreguidelines-pro-bounds-constant-array-index,
,-cppcoreguidelines-pro-type-reinterpret-cast -cppcoreguidelines-pro-bounds-pointer-arithmetic,
,-cppcoreguidelines-pro-type-union-access -cppcoreguidelines-pro-type-const-cast,
,-cppcoreguidelines-pro-type-vararg -cppcoreguidelines-pro-type-cstyle-cast,
,-cppcoreguidelines-special-member-functions -cppcoreguidelines-pro-type-member-init,
,-google-build-using-namespace -cppcoreguidelines-pro-type-reinterpret-cast,
,-google-explicit-constructor -cppcoreguidelines-pro-type-union-access,
,-google-global-names-in-headers -cppcoreguidelines-pro-type-vararg,
,-google-readability-casting -cppcoreguidelines-special-member-functions,
,-google-readability-namespace-comments -fuchsia-default-arguments,
,-google-readability-todo -fuchsia-overloaded-operator,
,-google-runtime-int -google-build-using-namespace,
,-google-runtime-references -google-explicit-constructor,
,-llvm-header-guard -google-global-names-in-headers,
,-llvm-include-order -google-readability-casting,
,-llvm-namespace-comment -google-readability-function-size,
,-misc-incorrect-roundings -google-readability-namespace-comments,
,-misc-macro-parentheses -google-readability-todo,
,-misc-misplaced-widening-cast -google-runtime-int,
,-misc-redundant-expression -google-runtime-references,
,-misc-unconventional-assign-operator -hicpp-braces-around-statements,
,-misc-unused-parameters -hicpp-deprecated-headers,
,-modernize-deprecated-headers -hicpp-explicit-conversions,
,-modernize-loop-convert -hicpp-function-size,
,-modernize-use-auto -hicpp-member-init,
,-modernize-use-bool-literals -hicpp-no-array-decay,
,-modernize-use-default-member-init -hicpp-no-assembler,
,-modernize-use-emplace -hicpp-no-malloc,
,-modernize-use-equals-default -hicpp-signed-bitwise,
,-modernize-use-equals-delete -hicpp-special-member-functions,
,-modernize-use-override -hicpp-use-auto,
,-modernize-use-using -hicpp-use-equals-default,
,-modernize-pass-by-value -hicpp-use-equals-delete,
,-performance-inefficient-string-concatenation -hicpp-use-override,
,-readability-avoid-const-params-in-decls -hicpp-vararg,
,-readability-else-after-return -llvm-header-guard,
,-readability-implicit-bool-cast -llvm-include-order,
,-readability-inconsistent-declaration-parameter-name -llvm-namespace-comment,
,-readability-non-const-parameter -misc-incorrect-roundings,
,-readability-redundant-declaration -misc-macro-parentheses,
,-readability-redundant-member-init -misc-misplaced-widening-cast,
,-readability-simplify-boolean-expr -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: '*' WarningsAsErrors: '*'
CheckOptions: CheckOptions:
- key: google-readability-braces-around-statements.ShortStatementLines - key: google-readability-braces-around-statements.ShortStatementLines
value: '1' value: '1'
- key: google-readability-function-size.BranchThreshold - key: google-readability-function-size.BranchThreshold
@ -81,9 +114,4 @@ CheckOptions:
value: '4000' value: '4000'
- key: google-readability-function-size.StatementThreshold - key: google-readability-function-size.StatementThreshold
value: '4000' value: '4000'
- key: readability-braces-around-statements.ShortStatementLines ...
value: '1'
- key: readability-function-size.LineThreshold
value: '4000'
- key: readability-function-size.StatementThreshold
value: '4000'

41
Jenkinsfile vendored

@ -305,26 +305,27 @@ pipeline {
} }
} }
// stage('Clang tidy') { stage('Clang tidy') {
// agent { agent {
// docker { docker {
// image 'px4io/px4-dev-clang:2019-10-24' image 'px4io/px4-dev-clang:2019-10-24'
// args '-e CCACHE_BASEDIR=$WORKSPACE -v ${CCACHE_DIR}:${CCACHE_DIR}:rw' args '-e CCACHE_BASEDIR=$WORKSPACE -v ${CCACHE_DIR}:${CCACHE_DIR}:rw'
// } }
// } }
// steps { steps {
// sh 'export' sh 'export'
// retry (3) { sh 'make distclean'
// sh 'make distclean' sh 'git fetch --tags'
// sh 'make clang-tidy-quiet' retry (3) {
// } sh 'make clang-tidy-quiet'
// } }
// post { }
// always { post {
// sh 'make distclean' always {
// } sh 'make distclean'
// } }
// } }
}
stage('Cppcheck') { stage('Cppcheck') {
agent { agent {

7
platforms/common/include/px4_platform_common/px4_work_queue/WorkItem.hpp

@ -49,7 +49,12 @@ class WorkItem : public ListNode<WorkItem *>, public IntrusiveQueueNode<WorkItem
{ {
public: public:
inline void ScheduleNow() { if (_wq != nullptr) _wq->Add(this); } inline void ScheduleNow()
{
if (_wq != nullptr) {
_wq->Add(this);
}
}
virtual void print_run_status() const; virtual void print_run_status() const;

8
src/lib/drivers/device/Device.hpp

@ -216,7 +216,7 @@ public:
*/ */
static int device_id_print_buffer(char *buffer, int length, uint32_t id) static int device_id_print_buffer(char *buffer, int length, uint32_t id)
{ {
DeviceId dev_id; DeviceId dev_id{};
dev_id.devid = id; dev_id.devid = id;
int num_written = snprintf(buffer, length, "Type: 0x%02X, %s:%d (0x%02X)", dev_id.devid_s.devtype, int num_written = snprintf(buffer, length, "Type: 0x%02X, %s:%d (0x%02X)", dev_id.devid_s.devtype,
@ -228,12 +228,12 @@ public:
} }
protected: 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 */ 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 /* setup a default device ID. When bus_type is UNKNOWN the
other fields are invalid */ other fields are invalid */

18
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) static void usage(const char *reason)
{ {
if (reason != NULL) { if (reason != nullptr) {
PX4_WARN("%s", reason); PX4_WARN("%s", reason);
} }
@ -108,23 +108,23 @@ int motor_test_main(int argc, char *argv[])
int timeout_ms = 0; int timeout_ms = 0;
int myoptind = 1; int myoptind = 1;
const char *myoptarg = NULL; const char *myoptarg = nullptr;
while ((ch = px4_getopt(argc, argv, "i:m:p:t:", &myoptind, &myoptarg)) != EOF) { while ((ch = px4_getopt(argc, argv, "i:m:p:t:", &myoptind, &myoptarg)) != EOF) {
switch (ch) { switch (ch) {
case 'i': case 'i':
driver_instance = (uint8_t)strtol(myoptarg, NULL, 0); driver_instance = (uint8_t)strtol(myoptarg, nullptr, 0);
break; break;
case 'm': case 'm':
/* Read in motor number */ /* Read in motor number */
channel = (int)strtol(myoptarg, NULL, 0); channel = (int)strtol(myoptarg, nullptr, 0);
break; break;
case 'p': case 'p':
/* Read in power value */ /* Read in power value */
lval = strtoul(myoptarg, NULL, 0); lval = strtoul(myoptarg, nullptr, 0);
if (lval > 100) { if (lval > 100) {
usage("value invalid"); usage("value invalid");
@ -135,11 +135,11 @@ int motor_test_main(int argc, char *argv[])
break; break;
case 't': case 't':
timeout_ms = strtol(myoptarg, NULL, 0) * 1000; timeout_ms = strtol(myoptarg, nullptr, 0) * 1000;
break; break;
default: default:
usage(NULL); usage(nullptr);
return 1; return 1;
} }
} }
@ -166,12 +166,12 @@ int motor_test_main(int argc, char *argv[])
} else if (strcmp("test", argv[myoptind]) == 0) { } else if (strcmp("test", argv[myoptind]) == 0) {
// nothing to do // nothing to do
} else { } else {
usage(NULL); usage(nullptr);
return 0; return 0;
} }
} else { } else {
usage(NULL); usage(nullptr);
return 0; return 0;
} }

194
src/systemcmds/tests/.clang-tidy

@ -1,77 +1,119 @@
Checks: '* ---
,-cert-dcl50-cpp Checks: '*,
,-cert-err34-c -android*,
,-cert-err58-cpp -bugprone-integer-division,
,-cert-flp30-c -cert-dcl50-cpp,
,-cert-msc30-c -cert-env33-c,
,-cert-msc50-cpp -cert-err34-c,
,-clang-analyzer-core.CallAndMessage -cert-err58-cpp,
,-clang-analyzer-core.NullDereference -cert-msc30-c,
,-clang-analyzer-core.UndefinedBinaryOperatorResult -cert-msc50-cpp,
,-clang-analyzer-core.uninitialized.Assign -cert-flp30-c,
,-clang-analyzer-core.VLASize -clang-analyzer-core.CallAndMessage,
,-clang-analyzer-cplusplus.NewDeleteLeaks -clang-analyzer-core.NullDereference,
,-clang-analyzer-deadcode.DeadStores -clang-analyzer-core.UndefinedBinaryOperatorResult,
,-clang-analyzer-optin.cplusplus.VirtualCall -clang-analyzer-core.uninitialized.Assign,
,-clang-analyzer-optin.performance.Padding -clang-analyzer-core.VLASize,
,-clang-analyzer-security.FloatLoopCounter -clang-analyzer-cplusplus.NewDelete,
,-clang-analyzer-security.insecureAPI.strcpy -clang-analyzer-cplusplus.NewDeleteLeaks,
,-clang-analyzer-unix.cstring.BadSizeArg -clang-analyzer-deadcode.DeadStores,
,-clang-analyzer-unix.Malloc -clang-analyzer-optin.cplusplus.VirtualCall,
,-clang-analyzer-unix.MallocSizeof -clang-analyzer-optin.performance.Padding,
,-cppcoreguidelines-c-copy-assignment-signature -clang-analyzer-security.FloatLoopCounter,
,-cppcoreguidelines-interfaces-global-init -clang-analyzer-security.insecureAPI.strcpy,
,-cppcoreguidelines-no-malloc -clang-analyzer-unix.API,
,-cppcoreguidelines-pro-bounds-array-to-pointer-decay -clang-analyzer-unix.cstring.BadSizeArg,
,-cppcoreguidelines-pro-bounds-constant-array-index -clang-analyzer-unix.Malloc,
,-cppcoreguidelines-pro-bounds-pointer-arithmetic -clang-analyzer-unix.MallocSizeof,
,-cppcoreguidelines-pro-type-const-cast -cppcoreguidelines-c-copy-assignment-signature,
,-cppcoreguidelines-pro-type-cstyle-cast -cppcoreguidelines-interfaces-global-init,
,-cppcoreguidelines-pro-type-member-init -cppcoreguidelines-no-malloc,
,-cppcoreguidelines-pro-type-reinterpret-cast -cppcoreguidelines-owning-memory,
,-cppcoreguidelines-pro-type-union-access -cppcoreguidelines-pro-bounds-array-to-pointer-decay,
,-cppcoreguidelines-pro-type-vararg -cppcoreguidelines-pro-bounds-constant-array-index,
,-cppcoreguidelines-special-member-functions -cppcoreguidelines-pro-bounds-pointer-arithmetic,
,-google-build-using-namespace -cppcoreguidelines-pro-type-const-cast,
,-google-explicit-constructor -cppcoreguidelines-pro-type-cstyle-cast,
,-google-global-names-in-headers -cppcoreguidelines-pro-type-member-init,
,-google-readability-casting -cppcoreguidelines-pro-type-reinterpret-cast,
,-google-readability-function-size -cppcoreguidelines-pro-type-union-access,
,-google-readability-namespace-comments -cppcoreguidelines-pro-type-vararg,
,-google-readability-todo -cppcoreguidelines-special-member-functions,
,-google-runtime-int -fuchsia-default-arguments,
,-google-runtime-references -fuchsia-overloaded-operator,
,-llvm-header-guard -google-build-using-namespace,
,-llvm-include-order -google-explicit-constructor,
,-llvm-namespace-comment -google-global-names-in-headers,
,-misc-incorrect-roundings -google-readability-casting,
,-misc-macro-parentheses -google-readability-function-size,
,-misc-misplaced-widening-cast -google-readability-namespace-comments,
,-misc-redundant-expression -google-readability-todo,
,-misc-unconventional-assign-operator -google-runtime-int,
,-misc-unused-parameters -google-runtime-references,
,-modernize-deprecated-headers -hicpp-braces-around-statements,
,-modernize-loop-convert -hicpp-deprecated-headers,
,-modernize-pass-by-value -hicpp-explicit-conversions,
,-modernize-use-auto -hicpp-function-size,
,-modernize-use-bool-literals -hicpp-member-init,
,-modernize-use-default-member-init -hicpp-no-array-decay,
,-modernize-use-emplace -hicpp-no-assembler,
,-modernize-use-equals-default -hicpp-no-malloc,
,-modernize-use-equals-delete -hicpp-signed-bitwise,
,-modernize-use-override -hicpp-special-member-functions,
,-modernize-use-using -hicpp-use-auto,
,-performance-inefficient-string-concatenation -hicpp-use-equals-default,
,-readability-avoid-const-params-in-decls -hicpp-use-equals-delete,
,-readability-braces-around-statements -hicpp-use-override,
,-readability-else-after-return -hicpp-vararg,
,-readability-function-size -llvm-header-guard,
,-readability-implicit-bool-cast -llvm-include-order,
,-readability-inconsistent-declaration-parameter-name -llvm-namespace-comment,
,-readability-named-parameter -misc-incorrect-roundings,
,-readability-non-const-parameter -misc-macro-parentheses,
,-readability-redundant-declaration -misc-misplaced-widening-cast,
,-readability-redundant-member-init -misc-redundant-expression,
,-readability-simplify-boolean-expr -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: '*' 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'
...

Loading…
Cancel
Save