-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add tests for and debug mqtt_agent_task.c #85
Merged
urutva
merged 7 commits into
FreeRTOS:main
from
RC-Repositories:add-mqtt-agent-unit-tests
Sep 10, 2024
Merged
Add tests for and debug mqtt_agent_task.c #85
urutva
merged 7 commits into
FreeRTOS:main
from
RC-Repositories:add-mqtt-agent-unit-tests
Sep 10, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some files were used in mqtt_agent_task.c but were not directly included. Additionally makes includes explicit in freertos_command_pool.c and freertos_agent_message.c. Signed-off-by: Reuben Cartwright <[email protected]>
This commit expands mock coverage across the repo in order to test core_mqtt_agent.c and freertos-command-pool.c. Mock support is in the form of modifying CMakeLists.txt in connectivity, aws_iot, and security components. All .h and .c files needed by core-mqtt are also added. This commit renames the mock directories. Now mocks for libraries are contained in `library_mocks` subdirectories, and mocks for integration code in `integration_mocks` subdirectories. Only these folder names have changed, they are still in the same parent directories. This decision was made to improve clarity of what each folder contains. This commit also fixes missing `BUILD_TESTING` usages in `CMakeLists.txt`. This commit moves mocks for `applications/helpers` from the test subdirectories into `applications/helpers//mocks`. Updates mocks: freertos_kernel. Adds (from scratch) mock support for: security/mbedtls, security/trusted_firmware-m, connectivity/iot_vsocket, connectivity/freertos_plus_tcp, connectivity/backoff_algorithms, coremqtt_agent aws_iot module. Additionally, mocks application-specific config files for testing core_mqtt_agent. Store application-specific config files in `tests/mocks` directory to avoid cluttering the `tests/` directory with non-test files. Also adds a CMakeLists.txt file for this directory. Also adds build_unit_test directory to .gitignore. Signed-off-by: Reuben Cartwright <[email protected]>
This commit makes the static functions in mqtt_agent_task.c visible if the UNIT_TESTING macro is defined. This is done by: 1. Define the `STATIC` macro in the header. ``` \#ifdef UNIT_TESTING #define STATIC /* as nothing */ \#else #define STATIC static \#endif /* UNIT_TESTING */ ``` 2. Add prototypes to the header. ``` STATIC int foo(void); ``` 3. Remove all other function prototypes in the .c file. This is justified because: - These functions need to be tested. - Functions other than `vStartMqttAgentTask` cannot be refactored to be non-static, as only `vStartMqttAgentTask` should be called in another file. Signed-off-by: Reuben Cartwright <[email protected]>
Adds 44 unit tests. The CMakeLists.txt includes the mocks of header files of files belonging to this component so they can be mocked. This needs to be done before including ../inc. Signed-off-by: Reuben Cartwright <[email protected]>
fix: prvGetRandomNumber does not use tick count if library function succeeds. fix: prvSocketDisconnect checks return value of Transport_Disconnect. fix: prvSocketDisconnect only sets mqtt as closed in system flags if closed successfully. fix: prvDisconnectFromMqttBroker errors on failure to disconnect socket. fix: when printing warning in prvIncomingPublishCallback, use buffer instead of writing to potentially read-only string. fix: transport_interface_api.h is only included in mqtt_agent_task.h if unit testing. The file is not findable from mqtt_agent_task.h outside of unit testing mode, but is needed to declare some of the functions tested. fix-style: include ordering in mqtt_agent_task.h. Signed-off-by: Reuben Cartwright <[email protected]>
Provides additional details on how the directory structure is laid out for unit testing. Namely, the three types of `mocks` subdirectories and what each contains. Also fixes broken links due to mock subdirectory renaming. Signed-off-by: Reuben Cartwright <[email protected]>
The only public function declared in `mqtt_agent_task.c` is `vStartMqttAgentTask` as other functions were extracted to separate files in previous work. The prototypes for these other functions were left behind in `mqtt_agent_task.h`. This commit removes them. Also change `ota_agent_task.c` to include `events.h`, which is where these function prototypes were placed in previous work. Signed-off-by: Reuben Cartwright <[email protected]>
RC-Repositories
force-pushed
the
add-mqtt-agent-unit-tests
branch
from
September 10, 2024 08:22
99313b7
to
e3e44d2
Compare
urutva
approved these changes
Sep 10, 2024
aggarg
approved these changes
Sep 10, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This MR also adds a substantial number (>40) of FFF fakes to be used in future unit testing.
Test Steps
Run the following from the project's root directory:
rm -rf build_unit_test && cmake -S . -B build_unit_test -GNinja && cmake --build build_unit_test && ctest --test-dir build_unit_test --output-on-failure
Checklist:
Related Issue
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.