msdk icon indicating copy to clipboard operation
msdk copied to clipboard

feat(ThirdParty): Unity unit test

Open EricB-ADI opened this issue 1 year ago • 16 comments

Pull Request Template

Description

  • Included 3rd party lib unity for unit testing
  • Added unit test example

EricB-ADI avatar Jun 03 '24 18:06 EricB-ADI

Hey @Jake-Carter , I want to integrate unity into our SDK so we can have, and offer a unit test framework. I have it working ok, but it would benefit a lot more if we can integrate it better into the build system. I updated the libs.mk to include the lib. You can run the tests on target, but it is definitely meant to be ran on the PC. Looking for some pointers or help trying to integrate this better.

EricB-ADI avatar Jun 03 '24 19:06 EricB-ADI

/clang-format-run

EricB-ADI avatar Jun 03 '24 19:06 EricB-ADI

Hey @Jake-Carter , I want to integrate unity into our SDK so we can have, and offer a unit test framework. I have it working ok, but it would benefit a lot more if we can integrate it better into the build system. I updated the libs.mk to include the lib. You can run the tests on target, but it is definitely meant to be ran on the PC. Looking for some pointers or help trying to integrate this better.

Sounds good, I'll take a look

Jake-Carter avatar Jun 04 '24 04:06 Jake-Carter

https://github.com/ThrowTheSwitch/Unity

Jake-Carter avatar Jun 05 '24 00:06 Jake-Carter

Just realized it got added as a submodule and none of the folders are there. Yes I did make a unity.mk.

EricB-ADI avatar Jun 05 '24 13:06 EricB-ADI

This should make more sense now.

EricB-ADI avatar Jun 05 '24 14:06 EricB-ADI

/clang-format-run

EricB-ADI avatar Jun 05 '24 14:06 EricB-ADI

/clang-format-run

EricB-ADI avatar Jun 11 '24 16:06 EricB-ADI

@Jake-Carter Everything is working as expected. I reran MSDKGen to update all the makefiles.

EricB-ADI avatar Jun 11 '24 18:06 EricB-ADI

@Jake-Carter Everything is working as expected. I reran MSDKGen to update all the makefiles.

@EricB-ADI can you revert it and just update a single project? My browser crashes now when I try to view the diff

Jake-Carter avatar Jun 11 '24 23:06 Jake-Carter

@Jake-Carter Everything is working as expected. I reran MSDKGen to update all the makefiles.

@EricB-ADI can you revert it and just update a single project? My browser crashes now when I try to view the diff

done

EricB-ADI avatar Jun 12 '24 14:06 EricB-ADI

Removed Unity from the linter.

sihyung-maxim avatar Jul 02 '24 16:07 sihyung-maxim

@EricB-ADI pushed my latest changes. Streamlined the integration with the host PC and added some documentation to the UG. Also slightly modified the example and options.

Of note are some updates to the unity config in https://github.com/analogdevicesinc/msdk/pull/1033/commits/274b74fdb409b4da8142107f39350e86ce5b5da4. I was seeing hard faults on the host micro from those setjmp calls on assertion failures so I disabled them.

Works well on my target micro and host machine. Have you already developed some way to check the return code of a micro's main function when it's under debug? This would be a useful addition to the documentation for developing automated hardware-in-the-loop testing with this framework.

Jake-Carter avatar Oct 04 '24 23:10 Jake-Carter

Thanks for

@EricB-ADI pushed my latest changes. Streamlined the integration with the host PC and added some documentation to the UG. Also slightly modified the example and options.

Of note are some updates to the unity config in 274b74f. I was seeing hard faults on the host micro from those setjmp calls on assertion failures so I disabled them.

Works well on my target micro and host machine. Have you already developed some way to check the return code of a micro's main function when it's under debug? This would be a useful addition to the documentation for developing automated hardware-in-the-loop testing with this framework.

I have not, but I suspect we can do it by checking the register after a return. I have some pyocd automation scripts so I may take a look at that to see what happens.

EricB-ADI avatar Oct 07 '24 13:10 EricB-ADI

Sounds good. I poked around r0-r3 a bit but didn't pick out a consistent pattern. I was hoping GDB would exit and pass through the return code but the micro just goes into .SPIN and GDB doesn't really support finish on the outermost frame.

Lmk if you find anything, otherwise I think we can add some documentation on parsing the serial output. OK and FAIL are consistent strings

Jake-Carter avatar Oct 07 '24 18:10 Jake-Carter

It should be pretty easy to make an automation script with GDB to break at void UnityFail(...) If it doesn't break and we hit a while loop or spin then it passed. We also have a test now that looks for serial prints. So we could modify to make sure the tests are passing from the print outs

EricB-ADI avatar Oct 07 '24 18:10 EricB-ADI

@crsz20 Can you check it out and run the unity test example for ME18? you only need to build it. I am having issues with the makefile. The gcc.mk was updated to run the unit test code, but it is missing some file. I am not sure if this is just a me issue, or its something we need to fix.

EricB-ADI avatar Jan 06 '25 20:01 EricB-ADI

@crsz20 Can you check it out and run the unity test example for ME18? you only need to build it. I am having issues with the makefile. The gcc.mk was updated to run the unit test code, but it is missing some file. I am not sure if this is just a me issue, or its something we need to fix.

When building for the host PC, it compiles and outputs as expected, but for some reason reports an error at the end:

- MKDIR msdk/Examples/MAX32690/Unity_Test/build/unittest
- CC msdk/Examples/MAX32690/Unity_Test/build/unittest/max32690_unittest
- RUN msdk/Examples/MAX32690/Unity_Test/build/unittest/max32690_unittest
test_functions.c:59:test_simple_add_ok:PASS
test_functions.c:35:test_simple_add_fail:FAIL: Expected -1 Was 255

-----------------------
2 Tests 1 Failures 0 Ignored 
FAIL
make: *** [msdk/Libraries/Unity/unity.mk:82: test] Error 1

When building for the target ME18, it fails to compile:

- MKDIR msdk/Examples/MAX32690/Unity_Test/build
- CC main.c
- CC simple_code.c

...

make[1]: Entering directory 'msdk/Examples/MAX32690/Unity_Test'
msdk/Libraries/CMSIS/Device/Maxim/GCC/gcc.mk:114: /Libraries/CMSIS/Device/Maxim/GCC/detect_os.mk: No such file or directory
make[1]: *** No rule to make target '/Libraries/CMSIS/Device/Maxim/GCC/detect_os.mk'.  Stop.
make[1]: Leaving directory 'msdk/Examples/MAX32690/Unity_Test'
make: *** [msdk/Libraries/PeriphDrivers/periphdriver.mk:102: msdk/Libraries/PeriphDrivers/bin/MAX32690/spi-v1_softfp/libPeriphDriver_spi-v1_softfp.a] Error 2
make: *** Waiting for unfinished jobs....

crsz20 avatar Jan 06 '25 20:01 crsz20

Yeah thats what I am getting. Probably need to merge main and fix it. I don't think we need that file. It isn't in main

EricB-ADI avatar Jan 06 '25 20:01 EricB-ADI

@EricB-ADI @crsz20 hey! Looks like I'm still getting pings for this :)

It's on feat/unity (https://github.com/analogdevicesinc/msdk/blob/feat/unity/Libraries/CMSIS/Device/Maxim/GCC/detect_os.mk)

IIRC I added it to avoid code duplication.

That error looks like MAXIM_PATH is not set. Note '/Libraries/CMSIS/Device/Maxim/GCC/detect_os.mk' vs:

https://github.com/analogdevicesinc/msdk/blob/6262318fca61a022e749c92adb54dbd80ba8a7a2/Libraries/CMSIS/Device/Maxim/GCC/gcc.mk#L114

Jake-Carter avatar Jan 06 '25 21:01 Jake-Carter

@Jake-Carter Thanks for clearing this up! Hope Nvidia is treating you well

EricB-ADI avatar Jan 06 '25 22:01 EricB-ADI

Ok @crsz20. Updated README and it is building again

EricB-ADI avatar Jan 06 '25 22:01 EricB-ADI