enable cpplint (#2238)

* enable cpplint

* fix misra

* newline

---------

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
This commit is contained in:
Aubrey Wahl
2025-05-14 17:30:49 -04:00
committed by GitHub
parent 35af9d9dde
commit c0bdcc58df
38 changed files with 78 additions and 63 deletions

View File

@@ -29,13 +29,12 @@ repos:
hooks:
- id: cython-lint
- id: double-quote-cython-strings
# TODO: enable this and fix all the errors
#- repo: https://github.com/cpplint/cpplint
# rev: 2.0.2
# hooks:
# - id: cpplint
# args:
# - --quiet
# - --counting=detailed
# - --linelength=240
# - --filter=-build,-legal,-readability,-runtime,-whitespace,+build/include_subdir,+build/forward_decl,+build/include_what_you_use,+build/deprecated,+whitespace/comma,+whitespace/line_length,+whitespace/empty_if_body,+whitespace/empty_loop_body,+whitespace/empty_conditional_body,+whitespace/forcolon,+whitespace/parens,+whitespace/semicolon,+whitespace/tab,+readability/braces
- repo: https://github.com/cpplint/cpplint
rev: 2.0.2
hooks:
- id: cpplint
args:
- --quiet
- --counting=detailed
- --linelength=240
- --filter=-build,-legal,-readability,-runtime,-whitespace,+build/include_subdir,+build/forward_decl,+build/include_what_you_use,+build/deprecated,+whitespace/comma,+whitespace/line_length,+whitespace/empty_if_body,+whitespace/empty_loop_body,+whitespace/empty_conditional_body,+whitespace/forcolon,+whitespace/parens,+whitespace/semicolon,+whitespace/tab,+readability/braces

View File

@@ -11,6 +11,7 @@ if platform.system() == "Darwin":
python_path = sysconfig.get_paths()['include']
cpppath = [
'#',
'#opendbc',
'/usr/lib/include',
python_path
]

View File

@@ -1,5 +1,8 @@
#include <array>
#include <cstdio>
#include <string>
#include <unordered_map>
#include <vector>
#include "opendbc/can/common.h"

View File

@@ -2,9 +2,11 @@
#include <filesystem>
#include <fstream>
#include <map>
#include <memory>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <mutex>
#include <iterator>

View File

@@ -3,7 +3,9 @@
#include <cmath>
#include <map>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
#include "opendbc/can/common.h"

View File

@@ -2,8 +2,11 @@
#include <cassert>
#include <cstring>
#include <limits>
#include <set>
#include <stdexcept>
#include <sstream>
#include <string>
#include <vector>
#include "opendbc/can/common.h"

View File

@@ -1,4 +1,4 @@
#pragma once
#include "can_declarations.h"
#include "safety/board/can_declarations.h"
static const unsigned char dlc_to_len[] = {0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 12U, 16U, 20U, 24U, 32U, 48U, 64U};

View File

@@ -1,5 +1,5 @@
#pragma once
#include "can_common_declarations.h"
#include "safety/board/drivers/can_common_declarations.h"
uint8_t calculate_checksum(const uint8_t *dat, uint32_t len) {
uint8_t checksum = 0U;

View File

@@ -3,7 +3,7 @@
#include <stdint.h>
#include <stdlib.h>
#include "utils.h"
#include "safety/board/utils.h"
#define ALLOW_DEBUG
#define PANDA

View File

@@ -1,4 +1,4 @@
#include "faults_declarations.h"
#include "safety/board/faults_declarations.h"
uint8_t fault_status = FAULT_STATUS_NONE;
uint32_t faults = 0U;

View File

@@ -1,14 +1,14 @@
// cppcheck-suppress-macro misra-c2012-1.2; allow __typeof__ extension
#define MIN(a, b) ({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
__typeof__(a) _a = (a); \
__typeof__(b) _b = (b); \
(_a < _b) ? _a : _b; \
})
// cppcheck-suppress-macro misra-c2012-1.2; allow __typeof__ extension
#define MAX(a, b) ({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
__typeof__(a) _a = (a); \
__typeof__(b) _b = (b); \
(_a > _b) ? _a : _b; \
})
@@ -22,7 +22,7 @@
// cppcheck-suppress-macro misra-c2012-1.2; allow __typeof__ extension
#define ABS(a) ({ \
__typeof__ (a) _a = (a); \
__typeof__(a) _a = (a); \
(_a > 0) ? _a : (-_a); \
})

View File

@@ -1,4 +1,4 @@
#include "safety.h"
#include "safety/safety.h"
// this file is checked by cppcheck

View File

@@ -1,7 +1,7 @@
#pragma once
#include "safety_declarations.h"
#include "can.h"
#include "safety/safety_declarations.h"
#include "safety/board/can.h"
// include the safety policies.
#include "safety/safety_defaults.h"

View File

@@ -1,6 +1,6 @@
#pragma once
#include "safety_declarations.h"
#include "safety/safety_declarations.h"
static void body_rx_hook(const CANPacket_t *to_push) {
// body is never at standstill

View File

@@ -1,6 +1,6 @@
#pragma once
#include "safety_declarations.h"
#include "safety/safety_declarations.h"
typedef struct {
const int EPS_2;

View File

@@ -1,6 +1,6 @@
#pragma once
#include "safety_declarations.h"
#include "safety/safety_declarations.h"
// GCOV_EXCL_START
// Unreachable by design (doesn't define any rx msgs)
@@ -13,7 +13,7 @@ void default_rx_hook(const CANPacket_t *to_push) {
static safety_config nooutput_init(uint16_t param) {
UNUSED(param);
return (safety_config){NULL, 0, NULL, 0, true};
return (safety_config){NULL, 0, NULL, 0, true}; // NOLINT(readability/braces)
}
// GCOV_EXCL_START
@@ -36,7 +36,7 @@ static safety_config alloutput_init(uint16_t param) {
const uint16_t ALLOUTPUT_PARAM_PASSTHROUGH = 1;
controls_allowed = true;
bool alloutput_passthrough = GET_FLAG(param, ALLOUTPUT_PARAM_PASSTHROUGH);
return (safety_config){NULL, 0, NULL, 0, !alloutput_passthrough};
return (safety_config){NULL, 0, NULL, 0, !alloutput_passthrough}; // NOLINT(readability/braces)
}
static bool alloutput_tx_hook(const CANPacket_t *to_send) {

View File

@@ -1,7 +1,7 @@
#pragma once
#include "safety_declarations.h"
#include "safety_defaults.h"
#include "safety/safety_declarations.h"
#include "safety/safety_defaults.h"
static bool elm327_tx_hook(const CANPacket_t *to_send) {
const int GM_CAMERA_DIAG_ADDR = 0x24B;

View File

@@ -1,6 +1,6 @@
#pragma once
#include "safety_declarations.h"
#include "safety/safety_declarations.h"
// Safety-relevant CAN messages for Ford vehicles.
#define FORD_EngBrakeData 0x165 // RX from PCM, for driver brake pedal and cruise state

View File

@@ -1,6 +1,6 @@
#pragma once
#include "safety_declarations.h"
#include "safety/safety_declarations.h"
// TODO: do checksum and counter checks. Add correct timestep, 0.1s for now.
#define GM_COMMON_RX_CHECKS \

View File

@@ -1,6 +1,6 @@
#pragma once
#include "safety_declarations.h"
#include "safety/safety_declarations.h"
// All common address checks except SCM_BUTTONS which isn't on one Nidec safety configuration
#define HONDA_COMMON_NO_SCM_FEEDBACK_RX_CHECKS(pt_bus) \

View File

@@ -1,7 +1,7 @@
#pragma once
#include "safety_declarations.h"
#include "safety_hyundai_common.h"
#include "safety/safety_declarations.h"
#include "safety/safety_hyundai_common.h"
#define HYUNDAI_LIMITS(steer, rate_up, rate_down) { \
.max_torque = (steer), \

View File

@@ -1,7 +1,7 @@
#pragma once
#include "safety_declarations.h"
#include "safety_hyundai_common.h"
#include "safety/safety_declarations.h"
#include "safety/safety_hyundai_common.h"
#define HYUNDAI_CANFD_CRUISE_BUTTON_TX_MSGS(bus) \
{0x1CF, bus, 8, .check_relay = false}, /* CRUISE_BUTTON */ \

View File

@@ -1,6 +1,6 @@
#pragma once
#include "safety_declarations.h"
#include "safety/safety_declarations.h"
extern uint16_t hyundai_canfd_crc_lut[256];
uint16_t hyundai_canfd_crc_lut[256];

View File

@@ -1,6 +1,6 @@
#pragma once
#include "safety_declarations.h"
#include "safety/safety_declarations.h"
// CAN msgs we care about
#define MAZDA_LKAS 0x243

View File

@@ -1,6 +1,6 @@
#pragma once
#include "safety_declarations.h"
#include "safety/safety_declarations.h"
static bool nissan_alt_eps = false;

View File

@@ -1,6 +1,6 @@
#pragma once
#include "safety_declarations.h"
#include "safety/safety_declarations.h"
#define RIVIAN_MAX_SPEED_DELTA 2.0 // m/s

View File

@@ -1,6 +1,6 @@
#pragma once
#include "safety_declarations.h"
#include "safety/safety_declarations.h"
#define SUBARU_STEERING_LIMITS_GENERATOR(steer_max, rate_up, rate_down) \
{ \

View File

@@ -1,6 +1,6 @@
#pragma once
#include "safety_declarations.h"
#include "safety/safety_declarations.h"
// Preglobal platform
// 0x161 is ES_CruiseThrottle

View File

@@ -1,6 +1,6 @@
#pragma once
#include "safety_declarations.h"
#include "safety/safety_declarations.h"
#define TESLA_MAX_SPEED_DELTA 2.0 // m/s

View File

@@ -1,6 +1,6 @@
#pragma once
#include "safety_declarations.h"
#include "safety/safety_declarations.h"
// Stock longitudinal
#define TOYOTA_BASE_TX_MSGS \

View File

@@ -53,15 +53,15 @@ static uint32_t volkswagen_mqb_meb_compute_crc(const CANPacket_t *to_push) {
uint8_t counter = volkswagen_mqb_meb_get_counter(to_push);
if (addr == MSG_LH_EPS_03) {
crc ^= (uint8_t[]){0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5}[counter];
crc ^= (uint8_t[]){0xF5, 0xF5, 0xF5, 0xF5, 0xF5, 0xF5, 0xF5, 0xF5, 0xF5, 0xF5, 0xF5, 0xF5, 0xF5, 0xF5, 0xF5, 0xF5}[counter];
} else if (addr == MSG_ESP_05) {
crc ^= (uint8_t[]){0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07}[counter];
crc ^= (uint8_t[]){0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07}[counter];
} else if (addr == MSG_TSK_06) {
crc ^= (uint8_t[]){0xC4,0xE2,0x4F,0xE4,0xF8,0x2F,0x56,0x81,0x9F,0xE5,0x83,0x44,0x05,0x3F,0x97,0xDF}[counter];
crc ^= (uint8_t[]){0xC4, 0xE2, 0x4F, 0xE4, 0xF8, 0x2F, 0x56, 0x81, 0x9F, 0xE5, 0x83, 0x44, 0x05, 0x3F, 0x97, 0xDF}[counter];
} else if (addr == MSG_MOTOR_20) {
crc ^= (uint8_t[]){0xE9,0x65,0xAE,0x6B,0x7B,0x35,0xE5,0x5F,0x4E,0xC7,0x86,0xA2,0xBB,0xDD,0xEB,0xB4}[counter];
crc ^= (uint8_t[]){0xE9, 0x65, 0xAE, 0x6B, 0x7B, 0x35, 0xE5, 0x5F, 0x4E, 0xC7, 0x86, 0xA2, 0xBB, 0xDD, 0xEB, 0xB4}[counter];
} else if (addr == MSG_GRA_ACC_01) {
crc ^= (uint8_t[]){0x6A,0x38,0xB4,0x27,0x22,0xEF,0xE1,0xBB,0xF8,0x80,0x84,0x49,0xC7,0x9E,0x1E,0x2B}[counter];
crc ^= (uint8_t[]){0x6A, 0x38, 0xB4, 0x27, 0x22, 0xEF, 0xE1, 0xBB, 0xF8, 0x80, 0x84, 0x49, 0xC7, 0x9E, 0x1E, 0x2B}[counter];
} else {
// Undefined CAN message, CRC check expected to fail
}

View File

@@ -1,7 +1,7 @@
#pragma once
#include "safety_declarations.h"
#include "safety_volkswagen_common.h"
#include "safety/safety_declarations.h"
#include "safety/safety_volkswagen_common.h"
static bool volkswagen_mqb_brake_pedal_switch = false;
static bool volkswagen_mqb_brake_pressure_detected = false;

View File

@@ -1,7 +1,7 @@
#pragma once
#include "safety_declarations.h"
#include "safety_volkswagen_common.h"
#include "safety/safety_declarations.h"
#include "safety/safety_volkswagen_common.h"
#define MSG_LENKHILFE_3 0x0D0 // RX from EPS, for steering angle and driver steering torque
#define MSG_HCA_1 0x0D2 // TX by OP, Heading Control Assist steering torque

View File

@@ -52,7 +52,7 @@
(config).tx_msgs = (tx); \
(config).tx_msgs_len = sizeof((tx)) / sizeof((tx)[0]); \
(config).disable_forwarding = false; \
} while(0);
} while (0);
#define UPDATE_VEHICLE_SPEED(val_ms) (update_sample(&vehicle_speed, ROUND((val_ms) * VEHICLE_SPEED_FACTOR)))

View File

@@ -23,7 +23,7 @@ env = Environment(
'-Wfatal-errors',
'-Wno-pointer-to-int-cast',
],
CPPPATH=[".", "../../board/", "../../"],
CPPPATH=[".", "../../board/", "../../", "../../../"],
)
if system == "Darwin":
env.PrependENVPath('PATH', '/opt/homebrew/bin')

View File

@@ -1,13 +1,13 @@
#include <stdbool.h>
#include "fake_stm.h"
#include "can.h"
#include "safety/board/fake_stm.h"
#include "safety/board/can.h"
//int safety_tx_hook(CANPacket_t *to_send) { return 1; }
#include "faults.h"
#include "safety.h"
#include "drivers/can_common.h"
#include "safety/board/faults.h"
#include "safety/safety.h"
#include "safety/board/drivers/can_common.h"
// libsafety stuff
#include "safety_helpers.h"
#include "safety/tests/libsafety/safety_helpers.h"

View File

@@ -1,3 +1,5 @@
#include <stdio.h>
void safety_tick_current_safety_config() {
safety_tick(&current_safety_config);
}

View File

@@ -45,8 +45,11 @@ cppcheck() {
echo -e "\n\n\n\n\nTEST variant options:" >> $CHECKLIST
echo -e ""${@//$BASEDIR/}"\n\n" >> $CHECKLIST # (absolute path removed)
$CPPCHECK_DIR/cppcheck --inline-suppr -I $BASEDIR/opendbc/safety/ \
-I $BASEDIR/opendbc/safety/safety/ -I $BASEDIR/opendbc/safety/board/ \
$CPPCHECK_DIR/cppcheck --inline-suppr \
-I $BASEDIR/opendbc/ \
-I $BASEDIR/opendbc/safety/ \
-I $BASEDIR/opendbc/safety/safety/ \
-I $BASEDIR/opendbc/safety/board/ \
-I "$(arm-none-eabi-gcc -print-file-name=include)" \
--suppressions-list=$DIR/suppressions.txt --suppress=*:*inc/* \
--suppress=*:*include/* --error-exitcode=2 --check-level=exhaustive --safety \