update cppcheck (#1859)

* update cppcheck

* Update tests/misra/install.sh

* delete cppcheck cache

* remove misra 5.8 erroors

* fixed uninitialized data error

* suppress misra-c2012-2.3 and misra-c2012-2.4

* reinstate cache to fix mutation test

* rerun for mutation test

* increase timeout for mutation test

* styling

* comments + variable name changes

* Update tests/misra/install.sh

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>

* Update install.sh

* more variable name changes

* condition on defining CANPacket_t

* just cherry pick

* fix build

---------

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
This commit is contained in:
Aryan
2024-02-11 04:20:36 +05:30
committed by GitHub
parent 32301a855a
commit 54459e694e
7 changed files with 32 additions and 27 deletions

View File

@@ -120,7 +120,7 @@ jobs:
timeout-minutes: 1
run: ${{ env.RUN }} "cd tests/misra && ./test_misra.sh"
- name: MISRA mutation tests
timeout-minutes: 3
timeout-minutes: 4
run: ${{ env.RUN }} "cd tests/misra && ./test_mutation.py"
python_linter:

View File

@@ -15,6 +15,7 @@ const uint8_t PANDA_BUS_CNT = 4U;
#define CANPACKET_DATA_SIZE_MAX 8U
#endif
#ifndef STM32F2
typedef struct {
unsigned char reserved : 1;
unsigned char bus : 3;
@@ -26,6 +27,7 @@ typedef struct {
unsigned char checksum;
unsigned char data[CANPACKET_DATA_SIZE_MAX];
} __attribute__((packed, aligned(4))) CANPacket_t;
#endif
const unsigned char dlc_to_len[] = {0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 12U, 16U, 20U, 24U, 32U, 48U, 64U};

View File

@@ -277,10 +277,10 @@ void can_send(CANPacket_t *to_push, uint8_t bus_number, bool skip_tx_hook) {
}
}
bool is_speed_valid(uint32_t speed, const uint32_t *speeds, uint8_t len) {
bool is_speed_valid(uint32_t speed, const uint32_t *all_speeds, uint8_t len) {
bool ret = false;
for (uint8_t i = 0U; i < len; i++) {
if (speeds[i] == speed) {
if (all_speeds[i] == speed) {
ret = true;
}
}

View File

@@ -79,7 +79,7 @@ void refresh_can_tx_slots_available(void);
#define STS_SETUP_COMP 4
#define STS_SETUP_UPDT 6
uint8_t resp[USBPACKET_MAX_SIZE];
uint8_t response[USBPACKET_MAX_SIZE];
// for the repeating interfaces
#define DSCR_INTERFACE_LEN 9
@@ -557,19 +557,19 @@ void usb_setup(void) {
break;
case STRING_OFFSET_ISERIAL:
#ifdef UID_BASE
resp[0] = 0x02 + (12 * 4);
resp[1] = 0x03;
response[0] = 0x02 + (12 * 4);
response[1] = 0x03;
// 96 bits = 12 bytes
for (int i = 0; i < 12; i++){
uint8_t cc = ((uint8_t *)UID_BASE)[i];
resp[2 + (i * 4)] = to_hex_char((cc >> 4) & 0xFU);
resp[2 + (i * 4) + 1] = '\0';
resp[2 + (i * 4) + 2] = to_hex_char((cc >> 0) & 0xFU);
resp[2 + (i * 4) + 3] = '\0';
response[2 + (i * 4)] = to_hex_char((cc >> 4) & 0xFU);
response[2 + (i * 4) + 1] = '\0';
response[2 + (i * 4) + 2] = to_hex_char((cc >> 0) & 0xFU);
response[2 + (i * 4) + 3] = '\0';
}
USB_WritePacket(resp, MIN(resp[0], setup.b.wLength.w), 0);
USB_WritePacket(response, MIN(response[0], setup.b.wLength.w), 0);
#else
USB_WritePacket((const uint8_t *)string_serial_desc, MIN(sizeof(string_serial_desc), setup.b.wLength.w), 0);
#endif
@@ -599,10 +599,10 @@ void usb_setup(void) {
}
break;
case USB_REQ_GET_STATUS:
// empty resp?
resp[0] = 0;
resp[1] = 0;
USB_WritePacket((void*)&resp, 2, 0);
// empty response?
response[0] = 0;
response[1] = 0;
USB_WritePacket((void*)&response, 2, 0);
USBx_OUTEP(0)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK;
break;
case USB_REQ_SET_INTERFACE:
@@ -648,10 +648,10 @@ void usb_setup(void) {
control_req.param2 = setup.b.wIndex.w;
control_req.length = setup.b.wLength.w;
resp_len = comms_control_handler(&control_req, resp);
resp_len = comms_control_handler(&control_req, response);
// response pending if -1 was returned
if (resp_len != -1) {
USB_WritePacket(resp, MIN(resp_len, setup.b.wLength.w), 0);
USB_WritePacket(response, MIN(resp_len, setup.b.wLength.w), 0);
USBx_OUTEP(0)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK;
}
}
@@ -877,7 +877,7 @@ void usb_irqhandler(void) {
print(" IN PACKET QUEUE\n");
#endif
// TODO: always assuming max len, can we get the length?
USB_WritePacket((void *)resp, comms_can_read(resp, 0x40), 1);
USB_WritePacket((void *)response, comms_can_read(response, 0x40), 1);
}
break;
@@ -888,9 +888,9 @@ void usb_irqhandler(void) {
print(" IN PACKET QUEUE\n");
#endif
// TODO: always assuming max len, can we get the length?
int len = comms_can_read(resp, 0x40);
int len = comms_can_read(response, 0x40);
if (len > 0) {
USB_WritePacket((void *)resp, len, 1);
USB_WritePacket((void *)response, len, 1);
}
}
break;

View File

@@ -21,10 +21,10 @@ struct __attribute__((packed)) health_t {
uint8_t power_save_enabled_pkt;
uint8_t heartbeat_lost_pkt;
uint16_t alternative_experience_pkt;
float interrupt_load;
float interrupt_load_pkt;
uint8_t fan_power;
uint8_t safety_rx_checks_invalid;
uint16_t spi_checksum_error_count;
uint8_t safety_rx_checks_invalid_pkt;
uint16_t spi_checksum_error_count_pkt;
uint8_t fan_stall_count;
uint16_t sbu1_voltage_mV;
uint16_t sbu2_voltage_mV;

View File

@@ -28,14 +28,14 @@ int get_health_pkt(void *dat) {
health->alternative_experience_pkt = alternative_experience;
health->power_save_enabled_pkt = power_save_status == POWER_SAVE_STATUS_ENABLED;
health->heartbeat_lost_pkt = heartbeat_lost;
health->safety_rx_checks_invalid = safety_rx_checks_invalid;
health->safety_rx_checks_invalid_pkt = safety_rx_checks_invalid;
health->spi_checksum_error_count = spi_checksum_error_count;
health->spi_checksum_error_count_pkt = spi_checksum_error_count;
health->fault_status_pkt = fault_status;
health->faults_pkt = faults;
health->interrupt_load = interrupt_load;
health->interrupt_load_pkt = interrupt_load;
health->fan_power = fan_state.power;
health->fan_stall_count = fan_state.total_stall_count;

View File

@@ -9,8 +9,11 @@ if [ ! -d "$CPPCHECK_DIR" ]; then
fi
cd $CPPCHECK_DIR
VERS="2.13.0"
git fetch --tags origin $VERS
git fetch --all --tags
git checkout $VERS
git cherry-pick -n f6b538e855f0bacea33c4074664628024ef39dc6
#make clean
make MATCHCOMPILTER=yes CXXFLAGS="-O2" -j8