-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add initial host based unittests #23
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
base: master
Are you sure you want to change the base?
Conversation
👋 Hello jedi7, we appreciate your contribution to this project! Click to see more instructions ...
Review and merge process you can expect ...
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM in general. Nice work!
Could you please also add a Github action which would build and run the unit tests at every push?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds initial host-based unit testing infrastructure using the Unity and CMock frameworks for the ESP flasher stub project. The setup enables testing C code on the host system before deploying to target hardware.
Key changes:
- Implementation of comprehensive SLIP protocol unit tests covering encoding, decoding, and error handling
- CMake-based build system with automated mock generation for external dependencies
- Shell scripts for automated test execution and mock file generation
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
unittests/tests/TestSlip.c | Comprehensive unit tests for SLIP protocol functions including frame delimiters, data encoding/escaping, and receive byte handling |
unittests/tests/CMakeLists.txt | CMake configuration for building the SLIP test executable with proper dependencies |
unittests/run-tests.sh | Main test runner script supporting both CMake and Rake build methods with dependency checking |
unittests/generate_mocks.sh | Script to generate CMock files for rom_wrappers header with proper error handling |
unittests/cmock_config.yml | CMock configuration file defining mock generation settings and behavior |
unittests/CMakeLists.txt | Root CMake configuration for the unit test framework with Unity/CMock integration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@dobairoland Thank you for the review! I will incorporate everything. This was meant as a preview to see if I should continue in this way. |
@jedi7 Yes, it look nice, please continue. Don't add new tests for now but make it easy for the guys to try. The instructions in the README will help. |
Nice job! After cloning the two repos, running this is very straightforward and easy. With some basic info in README, this is a great start, thank you. |
8a96916
to
5449ff2
Compare
the host based tests should be ok now. The target based tests are not currently running (they need to update ld scritps) |
Nice job! Took a look at how tests can be done a ran the prepared one and seems like really nice addition, thanks. |
5449ff2
to
a1c56d4
Compare
There target tests are still quite experimental and have issues. Like they are not compatible with stub for now. And is hard to gather the results of the tests. |
Are these initial tests ok for you? @Dzarda7 @dobairoland @radimkarnis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
a1c56d4
to
8715ce5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM in general. Nice progress, thank you!
cmake/esp-build-config.cmake
Outdated
@@ -0,0 +1,70 @@ | |||
# ESP Build Configuration | |||
# Common build settings shared across the esp-flasher-stub project |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these are just for unittests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently yes, but I believe, we can update also the main stub cmake to use that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do it in this PR? Duplicating part of the main Cmake file here is dangerous in terms of that they can diverge if the follow-up is not done immediately. I think this would belong here because during this process you might identify other modifications needed to be done in the current PR.
2035a34
to
9b39f2f
Compare
Hi all (@radimkarnis @Dzarda7 @dobairoland ), the target tests are now ready. The supported chip for the target tests is currently only ESP32-S3, but we can add another. |
Could this also be done in this PR? This shouldn't be too time consuming and ensures that these test don't broke just because someone forgot to run them locally before merging another PR. |
Could someone test the target tests please? I don't have an ESP32-S3 with me right now. |
@@ -0,0 +1,68 @@ | |||
# ESP Target Definitions and Utilities | |||
# Shared across the entire esp-flasher-stub project |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use this as well across the project, as the comment says.
project(esp-flasher-stub-host-tests C) | ||
|
||
# Host-specific configuration (native build) | ||
set(CMAKE_C_FLAGS "-std=gnu17 -Wall -Wextra -Werror -g -O0 -fprofile-arcs -ftest-coverage") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we take part from the project's C flags?
unittests/target/CMakeLists.txt
Outdated
configure_esp_tests(${ESP_TARGET}) | ||
|
||
# Check for Python and esptool module | ||
# First try ESP-IDF's Python environment if available |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't add dependency on ESP-IDF. Why would we want it here?
The main README suggests to create a venv. The tests could rely on this and extend if needed. Or for what else would we need the ESP-IDF environment? Toolchains? We are setting them up using the helper scripts.
We can assume that the usage for everyone is described in the main README. The unittests (host or target) are an extention to it. Not everyone will want to set up unit testing. But the unit testing setup should build on how the main project usage was set up.
unittests/target/CMakeLists.txt
Outdated
if(DEFINED ENV{IDF_PYTHON_ENV_PATH} AND EXISTS "$ENV{IDF_PYTHON_ENV_PATH}/bin/python") | ||
set(PYTHON3 "$ENV{IDF_PYTHON_ENV_PATH}/bin/python") | ||
else() | ||
find_program(PYTHON3 python3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python
is available as per instructions from the local venv. Esptool is already installed there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 18 out of 19 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
unittests/target/run-tests.sh:1
- Inconsistent default timeout values in usage help (10 seconds) versus actual default assignment (5 seconds on line 69). The help text should match the actual default value.
#!/bin/bash
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
e2c0c8a
to
73a4f23
Compare
@dobairoland tested now locally with Jarek, and after small changes, this works on MacOS ✅ |
5e589e2
to
0a54e43
Compare
Description
Propose for host based unittesting.
ThrowTheSwitch/Unity and CMock were selected because tests are also planned on the target hardware.
There target tests are still quite experimental and have issues. Like they are not compatible with stub for now. And is hard to gather the results of the tests.
Related
Testing
Checklist
Before submitting a Pull Request, please ensure the following: