如何解决在具有 FreeRTOS 依赖项的项目中取消单元测试
我正在尝试借助 cmock (Learn more about Unity) 在 Unity (Learn more about CMock) 中实现单元测试。为此,我使用了 Ceedling 工具,该工具将所有 Unity 组件组合到一个框架 (Learn more about Ceedling) 中。
一切正常,直到我将 FreeRTOS 添加到我的项目/测试中。添加后,Ceedling 难以为 FreeRTOS 组件生成模拟,例如 queue.c 或 list.c。它给出以下错误:
Generating include list for queue.h...
build/temp/_queue.h:32:6: error: #error "include FreeRTOS.h" must appear in source files before "include queue.h"
32 | #error "include FreeRTOS.h" must appear in source files before "include queue.h"
| ^~~~~
In file included from build/temp/_queue.h:40:
../build/_deps/rtos.freertos-src/include/task.h:32:6: error: #error "include FreeRTOS.h must appear in source files before include task.h"
32 | #error "include FreeRTOS.h must appear in source files before include task.h"
| ^~~~~
In file included from ../build/_deps/rtos.freertos-src/include/task.h:35,from build/temp/_queue.h:40:
../build/_deps/rtos.freertos-src/include/list.h:60:6: error: #error "FreeRTOS.h must be included before list.h"
60 | #error "FreeRTOS.h must be included before list.h"
| ^~~~~
对我来说,它看起来像是编译 queue.c 文件来找出应该被模拟的函数列表。没关系,但我不知道强制它在检查 queue.c 或 list.c 文件时添加 FreeRTOS.h 包含。
我修改了我的 project.yml 文件,因此添加了 FreeRTOS 的路径,并将 FreeRTOS.h 标头添加到包含:
:paths:
:test:
- +:test/**
- -:test/support
- ../
- ../build/_deps/rtos.freertos-src/portable/GCC/ARM_CM4F
- ../build/_deps/rtos.freertos-src/include
- ../debug/
:source:
- src/**
- ../build/_deps/rtos.freertos-src/portable/GCC/ARM_CM4F/**
- ../build/_deps/rtos.freertos-src/include/**
- ../build/_deps/rtos.freertos-src/**
:support:
- test/support
:libraries: []
... skipped lines ...
... skipped lines ...
... skipped lines ...
:cmock:
:mock_prefix: mock_
:when_no_prototypes: :warn
:enforce_strict_ordering: TRUE
:plugins:
- :ignore
- :callback
:treat_as:
uint8: HEX8
uint16: HEX16
uint32: UINT32
int8: INT8
bool: UINT8
:includes_h_pre_orig_header:
- FreeRTOS.h
:includes_c_pre_header:
- FreeRTOS.h
:includes:
- ../debug/assert.h
- FreeRTOS.h
即使添加了 includes_h_pre_orig_header、includes_c_pre_header 和 includes,它仍然像 FreeRTOS.h 一样失败。不会在 queue.h 和 list.h 标头之前添加。
我找到了 similar problem,解决方案是在测试脚本中添加对 SetUp 和 Teardown 方法的初始化和验证调用,并为与 FreeRTOS 相关的调用添加 Expect。我没有运气就试过了。
我的测试脚本很简单:
#include "unity.h"
#include "cmock.h"
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "mock_queue.h"
#include "test.h"
void setUp(void) {
mock_queue_Init();
mock_list_Init();
mock_task_Init();
}
void tearDown(void) {
mock_queue_Verify();
mock_list_Verify();
mock_task_Verify();
}
void test_Rtos(void)
{
xQueueCreate_Expect(8,16);
TestRtos();
}
源文件也很简单,只是为了检查 Ceedling 是否适用于 FreeRTOS:
#include "test.h"
#include "FreeRTOSConfig.h"
#include "FreeRTOS.h"
#include "queue.h"
void TestRtos(void)
{
QueueHandle_t someQueue = xQueueCreate(8,16);
uxQueueMessagesWaiting(someQueue);
}
我也查看了 some examples from Amazon,但他们的 project.yml 甚至没有提到一些与 FreeRTOS 相关的路径或头文件。我在这里错过了什么?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。