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

MISRSA results different in CI and workstation #1847

Closed
adeebshihadeh opened this issue Feb 3, 2024 · 11 comments
Closed

MISRSA results different in CI and workstation #1847

adeebshihadeh opened this issue Feb 3, 2024 · 11 comments

Comments

@adeebshihadeh
Copy link
Contributor

adeebshihadeh commented Feb 3, 2024

Running test_misra.sh on my workstation, I get no errors, but CI reports a few style violations and doesn't fail. We need to figure out why the results are different and why CI doesn't fail even though errors are reported. Also need to fix these violations.

https://github.com/commaai/panda/actions/runs/7770060952/job/21189783553

** PANDA F4 CODE **
Checking /tmp/openpilot/panda/board/main.c ...
Checking /tmp/openpilot/panda/board/main.c: CAN3=1;PANDA=1;STM32F4=1;UID_BASE=1;STM32F423xx...
/tmp/openpilot/panda/board/health.h:24:9: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-5.8]
  float interrupt_load;
        ^
/tmp/openpilot/panda/board/drivers/interrupts.h:35:7: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-5.8]
float interrupt_load = 0.0f;
      ^
/tmp/openpilot/panda/board/health.h:27:12: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-5.8]
  uint16_t spi_checksum_error_count;
           ^
/tmp/openpilot/panda/board/drivers/spi.h:43:10: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-5.8]
uint16_t spi_checksum_error_count = 0;
         ^
/tmp/openpilot/panda/board/main_comms.h:71:58: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-5.8]
int comms_control_handler(ControlPacket_t *req, uint8_t *resp) {
                                                         ^
/tmp/openpilot/panda/board/drivers/usb.h:82:9: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-5.8]
uint8_t resp[USBPACKET_MAX_SIZE];
        ^
/tmp/openpilot/panda/board/health.h:26:11: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-5.8]
  uint8_t safety_rx_checks_invalid;
          ^
/tmp/openpilot/panda/board/safety_declarations.h:227:6: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-5.8]
bool safety_rx_checks_invalid = false;
     ^
/tmp/openpilot/panda/board/drivers/can_common.h:280:53: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-5.8]
bool is_speed_valid(uint32_t speed, const uint32_t *speeds, uint8_t len) {
                                                    ^
/tmp/openpilot/panda/board/stm32fx/llbxcan.h:22:16: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-5.8]
const uint32_t speeds[] = {100U, 200U, 500U, 1000U, 1250U, 2500U, 5000U, 10000U};
               ^
nofile:0:0: information: Active checkers: 279/792 (use --checkers-report=<filename> to see details) [checkersReport]
@0x41head
Copy link
Contributor

0x41head commented Feb 7, 2024

With #1859 , the errors in my local system have now become consistent with the CI.
Can you confirm @adeebshihadeh ?
I am also looking into what commit in cppcheck fixed this issue.

OS: Manjaro Linux x86_64 
Kernel: 5.15.146-1-MANJARO

@0x41head
Copy link
Contributor

0x41head commented Feb 7, 2024

danmar/cppcheck#5925 seems to be the PR that generates the misra 5.8 errors in my local system.
Need to do a deeper dive as to understand why this happens.

@adeebshihadeh
Copy link
Contributor Author

Confirmed the results seem to match on my workstation now

** PANDA F4 CODE **
Checking /home/batman/sixpilot/panda/board/main.c ...
Checking /home/batman/sixpilot/panda/board/main.c: CAN3=1;PANDA=1;STM32F4=1;UID_BASE=1;STM32F423xx...
/home/batman/sixpilot/panda/board/libc.h:50:10: warning: Uninitialized variable: dest [uninitvar]
  return dest;
         ^
/home/batman/sixpilot/panda/board/can_comms.h:72:20: note: Calling function 'memcpy', 1st argument '&to_push' value is <Uninit>
      (void)memcpy(&to_push, can_write_buffer.data, can_write_buffer.ptr);
                   ^
/home/batman/sixpilot/panda/board/libc.h:50:10: note: Uninitialized variable: dest
  return dest;
         ^


/home/batman/sixpilot/panda/board/health.h:24:9: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-5.8]
  float interrupt_load;
        ^
/home/batman/sixpilot/panda/board/drivers/interrupts.h:35:7: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-5.8]
float interrupt_load = 0.0f;
      ^
/home/batman/sixpilot/panda/board/provision.h:8:35: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-5.8]
void get_provision_chunk(uint8_t *resp) {
                                  ^
/home/batman/sixpilot/panda/board/drivers/usb.h:82:9: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-5.8]
uint8_t resp[USBPACKET_MAX_SIZE];
        ^
/home/batman/sixpilot/panda/board/drivers/can_common.h:280:53: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-5.8]
bool is_speed_valid(uint32_t speed, const uint32_t *speeds, uint8_t len) {
                                                    ^
/home/batman/sixpilot/panda/board/stm32fx/llbxcan.h:22:16: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-5.8]
const uint32_t speeds[] = {100U, 200U, 500U, 1000U, 1250U, 2500U, 5000U, 10000U};
               ^
nofile:0:0: information: Active checkers: 279/792 (use --checkers-report=<filename> to see details) [checkersReport]

However, if I run it again, I don't get back all the failures, particularly the 5.8 ones. Perhaps the cache is the reason?

** PANDA F4 CODE **
Checking /home/batman/sixpilot/panda/board/main.c ...
/home/batman/sixpilot/panda/board/libc.h:50:10: warning: Uninitialized variable: dest [uninitvar]
  return dest;
         ^
/home/batman/sixpilot/panda/board/can_comms.h:72:20: note: Calling function 'memcpy', 1st argument '&to_push' value is <Uninit>
      (void)memcpy(&to_push, can_write_buffer.data, can_write_buffer.ptr);
                   ^
/home/batman/sixpilot/panda/board/libc.h:50:10: note: Uninitialized variable: dest
  return dest;
         ^
nofile:0:0: information: Active checkers: 177/792 (use --checkers-report=<filename> to see details) [checkersReport]

@0x41head
Copy link
Contributor

0x41head commented Feb 7, 2024

Can confirm it is the cache. Deleting and running a fresh cppcheck returns back the misra errors.

@adeebshihadeh
Copy link
Contributor Author

Alright, so the update seems to partially solve this. Let's just get the violations fixed in the update PR and get that merged, then we can tackle the rest of this separately. Bounty is locked to you

@adeebshihadeh adeebshihadeh moved this from Open to Locked in openpilot bounties Feb 7, 2024
@0x41head
Copy link
Contributor

0x41head commented Feb 12, 2024

inconsistent results from multiple cppcheck analysis seems to be an issue from cppchecker's side.

This issue seems to be caused by the caching done by --cppcheck-build-dir flag.

We can probably creating a work around by deleting the cache everytime we run into an error while running cppchecker. Though we would probably lose some of the speed up that come with caching.
Let me know what you think @adeebshihadeh .

@adeebshihadeh
Copy link
Contributor Author

If that's true, let's just drop the caching entirely. Any speedup is not worth an inconsistent test.

The other part of this is the not failing CI even though it reports errors; is this a separate cppcheck bug?

@0x41head
Copy link
Contributor

Seems like it.
Running the cppchecker with the --addon flag seems to generate the wrong exit code of 0.
Creating a dump and then running the misra addon over it directly seems to generate the correct exit code of 1.
Created an issue on cppchecker's issue tracker for the same.

@adeebshihadeh
Copy link
Contributor Author

Seems like it. Running the cppchecker with the --addon flag seems to generate the wrong exit code of 0. Creating a dump and then running the misra addon over it directly seems to generate the correct exit code of 1. Created an issue on cppchecker's issue tracker for the same.

Nice find. Can we fix this for now by just adding a second pass? Or maybe it's just easier too fix this in upstream cppecheck?

@0x41head
Copy link
Contributor

If the time difference between both of these options isn't too substantial, I would prefer we just run the misra addon over the dump, as we are already cherrypicking my previous commit.

@adeebshihadeh
Copy link
Contributor Author

Nice job @0x41head. There's a bunch of good open openpilot bounties up for grabs if you want - https://github.com/orgs/commaai/projects/26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

2 participants