Unit testing and system initialisation code
I am currently working on testing of some code using a testing tool. As nearly all of the code interacts with the hardware, it is easiest for me to do this on the target. The tool automatically builds the test environment and allows files and/or functions to be tested as a whole or in isolation. In my case, I include all of the project's files in the test builds (so the functionality is available), selecting one of them at a time for white box testing.
The only real problem I have is the startup code that exists within main() - this needs to be run to set up the clock tree, initialise the HAL, etc. The testing environment renames main() and adds its own main() so that it can control how the test cases I specify are executed and to allow the results to be captured.
At the moment, I have to duplicate the code in the supplied main() so that I can initialise the system before any tests are executed. This is a manual process, which means that the behaviour of this "clone" can diverge from what is provided by the IDE (when code is regenerated after editing the .ioc, for example).
I cannot simply call the renamed main() function to perform initialisation as it makes calls into the project code and does not return.
It would be really helpful if all of the calls within the IDE-provided main() that are related to system startup (everything between USER CODE END 1 and USER CODE BEGIN 2) could be encapsulated within a single function (that can be made extern) so that test environments could include a call to it to perform system initialisation. I do not think it is possible to get the IDE to do this at the moment. Would this be a feature that would be useful to the community? If so, how do I submit a feature request?
