Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable unusedFunction #1878

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Conversation

0x41head
Copy link
Contributor

for #1794

@@ -15,6 +15,9 @@ unmatchedSuppression
# All interrupt handlers are defined, including ones we don't use
unusedFunction:*/interrupt_handlers*.h

# REGISTER_INTERRUPT defined in interrupt_handlers.h
unknownMacro:*/gmlan_alt.h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this fix it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used this to suppress the unknownMacro error that was being generated. Nothing to do with the unusedFunction error. Need to figure out if this is a false positive.

#printf "\n${GREEN}** UNUSED ALL CODE **${NC}\n"
#cppcheck --enable=unusedFunction --quiet $PANDA_DIR/board/
printf "\n${GREEN}** UNUSED ALL CODE **${NC}\n"
cppcheck --enable=unusedFunction --quiet $PANDA_DIR/board/main.c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, also not sure how this works now. it needs to also analyze the bootstub and jungle builds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a bug from cppchecker's side. All the unused function seems to have been be generated by board/main.c as we can see in previous CI runs.
Running cppcheck $PANDA_OPTS -DSTM32H7 -DUID_BASE $PANDA_DIR/board/main.c $PANDA_DIR/board/jungle/main.c $PANDA_DIR/board/jungle/bootstub.c also seems to remove the unused function error ( it also adds another unknownMacro error )

@adeebshihadeh
Copy link
Contributor

We should also add a test case for unusedFunction here since it takes a very unique code path.

@adeebshihadeh
Copy link
Contributor

Not sure how the new test case is passing. It didn't catch either of these:

batman:panda$ git diff .
diff --git a/board/bootstub.c b/board/bootstub.c
index aee665e7..16d18903 100644
--- a/board/bootstub.c
+++ b/board/bootstub.c
@@ -28,6 +28,10 @@ void fail(void) {
   soft_flasher_start();
 }

+void abc(void) {
+
+}
+
 // know where to sig check
 extern void *_app_start[];

diff --git a/board/main.c b/board/main.c
index 061a9138..37f6c236 100644
--- a/board/main.c
+++ b/board/main.c
@@ -32,6 +32,10 @@

 // ********************* Serial debugging *********************

+void unusedfunction(void) {
+
+}
+
 bool check_started(void) {
   bool started = current_board->check_ignition() || ignition_can;
   ignition_seen |= started;

@0x41head
Copy link
Contributor Author

hmm.. defining pre-processor symbols like seems to invoke the unusedFunction error.
cppcheck --enable=unusedFunction --quiet -DSTM32F4 -DUID_BASE -DPANDA -DSTM32H7 $PANDA_DIR/board/

Any particular reason you undefined it @adeebshihadeh ?

Log:

/home/aryan/Desktop/open-source/panda/board/jungle/main.c:169:3: error: There is an unknown macro here somewhere. Configuration is required. If REGISTER_INTERRUPT is a macro then please configure it. [unknownMacro]
  REGISTER_INTERRUPT(TICK_TIMER_IRQ, tick_handler, 10U, FAULT_INTERRUPT_RATE_TICK)
  ^
/home/aryan/Desktop/open-source/panda/board/drivers/can_common.h:200:0: style: The function 'can_set_forwarding' is never used. [unusedFunction]
void can_set_forwarding(uint8_t from, uint8_t to) {
^
/home/aryan/Desktop/open-source/panda/board/drivers/gpio.h:71:0: style: The function 'gpio_set_all_output' is never used. [unusedFunction]
void gpio_set_all_output(const gpio_t *pins, uint8_t num_pins, bool enabled) {
^
/home/aryan/Desktop/open-source/panda/board/drivers/gpio.h:77:0: style: The function 'gpio_set_bitmask' is never used. [unusedFunction]
void gpio_set_bitmask(const gpio_t *pins, uint8_t num_pins, uint32_t bitmask) {
^
/home/aryan/Desktop/open-source/panda/board/drivers/uart.h:154:0: style: The function 'putui' is never used. [unusedFunction]
void putui(uint32_t i) {
^
/home/aryan/Desktop/open-source/panda/board/drivers/watchdog.h:10:0: style: The function 'watchdog_init' is never used. [unusedFunction]
void watchdog_init(WatchdogTimeout timeout) {
^
/home/aryan/Desktop/open-source/panda/board/main.c:35:0: style: The function 'test' is never used. [unusedFunction]
void test(void) {}
^
/home/aryan/Desktop/open-source/panda/board/safety.h:110:0: style: The function 'gen_crc_lookup_table_16' is never used. [unusedFunction]
void gen_crc_lookup_table_16(uint16_t poly, uint16_t crc_lut[]) {
^
/home/aryan/Desktop/open-source/panda/board/safety/safety_hyundai_common.h:90:0: style: The function 'hyundai_common_canfd_compute_checksum' is never used. [unusedFunction]
uint32_t hyundai_common_canfd_compute_checksum(const CANPacket_t *to_push) {
^
/home/aryan/Desktop/open-source/panda/board/stm32h7/lldac.h:1:0: style: The function 'dac_init' is never used. [unusedFunction]
void dac_init(DAC_TypeDef *dac, uint8_t channel, bool dma) {
^
/home/aryan/Desktop/open-source/panda/board/stm32h7/lldac.h:30:0: style: The function 'dac_set' is never used. [unusedFunction]
void dac_set(DAC_TypeDef *dac, uint8_t channel, uint32_t value) {

@adeebshihadeh
Copy link
Contributor

H7 and F4 should be mutually exclusive.

@0x41head
Copy link
Contributor Author

cppcheck --enable=unusedFunction --quiet -DUID_BASE -DPANDA -DSTM32F4 $PANDA_DIR/board/main.c generates

/home/aryan/Desktop/open-source/panda/board/jungle/main.c:169:3: error: There is an unknown macro here somewhere. Configuration is required. If REGISTER_INTERRUPT is a macro then please configure it. [unknownMacro]
  REGISTER_INTERRUPT(TICK_TIMER_IRQ, tick_handler, 10U, FAULT_INTERRUPT_RATE_TICK)
  ^
/home/aryan/Desktop/open-source/panda/board/bootstub_declarations.h:16:0: style: The function 'uart_init' is never used. [unusedFunction]
void uart_init(uart_ring *q, int baud) { UNUSED(q); UNUSED(baud); }
^
/home/aryan/Desktop/open-source/panda/board/drivers/can_common.h:200:0: style: The function 'can_set_forwarding' is never used. [unusedFunction]
void can_set_forwarding(uint8_t from, uint8_t to) {
^
/home/aryan/Desktop/open-source/panda/board/drivers/gpio.h:71:0: style: The function 'gpio_set_all_output' is never used. [unusedFunction]
void gpio_set_all_output(const gpio_t *pins, uint8_t num_pins, bool enabled) {
^
/home/aryan/Desktop/open-source/panda/board/drivers/gpio.h:77:0: style: The function 'gpio_set_bitmask' is never used. [unusedFunction]
void gpio_set_bitmask(const gpio_t *pins, uint8_t num_pins, uint32_t bitmask) {
^
/home/aryan/Desktop/open-source/panda/board/drivers/uart.h:154:0: style: The function 'putui' is never used. [unusedFunction]
void putui(uint32_t i) {
^
/home/aryan/Desktop/open-source/panda/board/drivers/watchdog.h:10:0: style: The function 'watchdog_init' is never used. [unusedFunction]
void watchdog_init(WatchdogTimeout timeout) {
^
/home/aryan/Desktop/open-source/panda/board/main.c:34:0: style: The function 'test' is never used. [unusedFunction]
void test(void){}
^
/home/aryan/Desktop/open-source/panda/board/safety.h:110:0: style: The function 'gen_crc_lookup_table_16' is never used. [unusedFunction]
void gen_crc_lookup_table_16(uint16_t poly, uint16_t crc_lut[]) {
^
/home/aryan/Desktop/open-source/panda/board/safety/safety_hyundai_common.h:90:0: style: The function 'hyundai_common_canfd_compute_checksum' is never used. [unusedFunction]
uint32_t hyundai_common_canfd_compute_checksum(const CANPacket_t *to_push) {
^
/home/aryan/Desktop/open-source/panda/board/stm32fx/lluart.h:48:0: style: The function 'uart_send_break' is never used. [unusedFunction]
void uart_send_break(uart_ring *u) {
^
/home/aryan/Desktop/open-source/panda/board/stm32fx/lluart.h:81:0: style: The function 'USART2_IRQ_Handler' is never used. [unusedFunction]
void USART2_IRQ_Handler(void) { uart_interrupt_handler(&uart_ring_debug); }


cppcheck --enable=unusedFunction --quiet -DUID_BASE -DPANDA -DSTM32H7 $PANDA_DIR/board/ generates

** UNUSED ALL CODE **
/home/aryan/Desktop/open-source/panda/board/jungle/main.c:169:3: error: There is an unknown macro here somewhere. Configuration is required. If REGISTER_INTERRUPT is a macro then please configure it. [unknownMacro]
  REGISTER_INTERRUPT(TICK_TIMER_IRQ, tick_handler, 10U, FAULT_INTERRUPT_RATE_TICK)
  ^
/home/aryan/Desktop/open-source/panda/board/drivers/can_common.h:200:0: style: The function 'can_set_forwarding' is never used. [unusedFunction]
void can_set_forwarding(uint8_t from, uint8_t to) {
^
/home/aryan/Desktop/open-source/panda/board/drivers/gpio.h:71:0: style: The function 'gpio_set_all_output' is never used. [unusedFunction]
void gpio_set_all_output(const gpio_t *pins, uint8_t num_pins, bool enabled) {
^
/home/aryan/Desktop/open-source/panda/board/drivers/gpio.h:77:0: style: The function 'gpio_set_bitmask' is never used. [unusedFunction]
void gpio_set_bitmask(const gpio_t *pins, uint8_t num_pins, uint32_t bitmask) {
^
/home/aryan/Desktop/open-source/panda/board/drivers/uart.h:154:0: style: The function 'putui' is never used. [unusedFunction]
void putui(uint32_t i) {
^
/home/aryan/Desktop/open-source/panda/board/drivers/watchdog.h:10:0: style: The function 'watchdog_init' is never used. [unusedFunction]
void watchdog_init(WatchdogTimeout timeout) {
^
/home/aryan/Desktop/open-source/panda/board/main.c:34:0: style: The function 'test' is never used. [unusedFunction]
void test(void){}
^
/home/aryan/Desktop/open-source/panda/board/stm32h7/lldac.h:1:0: style: The function 'dac_init' is never used. [unusedFunction]
void dac_init(DAC_TypeDef *dac, uint8_t channel, bool dma) {
^
/home/aryan/Desktop/open-source/panda/board/stm32h7/lldac.h:30:0: style: The function 'dac_set' is never used. [unusedFunction]
void dac_set(DAC_TypeDef *dac, uint8_t channel, uint32_t value) {
^

I guess we can add both cases to our misra tests since they generate slightly different results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants