feat(ThirdParty): Unity unit test
Pull Request Template
Description
- Included 3rd party lib unity for unit testing
- Added unit test example
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.
/clang-format-run
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
https://github.com/ThrowTheSwitch/Unity
Just realized it got added as a submodule and none of the folders are there. Yes I did make a unity.mk.
This should make more sense now.
/clang-format-run
/clang-format-run
@Jake-Carter Everything is working as expected. I reran MSDKGen to update all the makefiles.
@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 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
Removed Unity from the linter.
@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.
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
setjmpcalls 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.
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
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
@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.
@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....
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 @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 Thanks for clearing this up! Hope Nvidia is treating you well
Ok @crsz20. Updated README and it is building again