具有 FreeRTOS 依赖项的项目中的 Ceedling 单元测试问题

问题描述 投票:0回答:1

我目前正在开发一个项目,涉及使用 Ceedling、Unity 和 CMock 进行单元测试。我的项目依赖于 FreeRTOS,特别是使用 FreeRTOS.h 中的 xTaskNotifyWait() 等函数。

问题: 我遇到了一个问题,即 Ceedling 由于缺少 reent.h 文件(包含在 FreeRTOS.h 中)而无法构建测试。我收到的错误消息是:

FreeRTOS/Source/include/FreeRTOS.h:84:14:致命错误:reent.h:没有这样的文件或目录 84 | 84 #包括

我的设置:

reent.h 文件位于我的 STM32CubeIDE 工具链目录中: C:/ST/STM32CubeIDE_1.9.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127/tools/arm-none-eabi /包括

我的project.yml配置为Ceedling、Unity和CMock。

这是我的项目.yml 的片段:

---

# Notes:
# Sample project C code is not presently written to produce a release artifact.
# As such, release build options are disabled.
# This sample, therefore, only demonstrates running a collection of unit tests.

:project:
  :use_exceptions: FALSE
  :use_test_preprocessor: TRUE
  :use_auxiliary_dependencies: TRUE
  :build_root: build
#  :release_build: TRUE
  :test_file_prefix: test_
  :which_ceedling: gem
  :ceedling_version: 0.31.1
  :default_tasks:
    - test:all

#:test_build:
#  :use_assembly: TRUE

#:release_build:
#  :output: MyApp.out
#  :use_assembly: FALSE

:environment:

:extension:
  :executable: .out

:paths:
  :test:
    - +:TDD_Tests/**
    - -:TDD_Tests/support
  :source:
    - Core/App
    - Core/App/EEPROM
    - Core/App/Executor
    - Core/App/FrequencyInvestigation
    - Core/App/VoltageInvestigation
    - Core/App/LWIP
    - Core/App/ModbusTCP
    - Core/App/OPCUA
    - Core/App/RegisterData
    - Core/App/SPI1
    - Core/App/SPI3
    - Core/App/System
    - Core/App/USART2
    - Core/App/USART3
    - Core/App/HourCounter
    - Core/Inc
    - Core/Src
    - FreeRTOS/Source
    - FreeRTOS/Source/portable/GCC/ARM_CM4F
    - FreeRTOS/Source/portable/GCC/MemMang
    - FreeRTOS/Source
    - FreeRTOS/Source/CMSIS_RTOS
    - FreeRTOS/Source/include
    - Drivers/STM32F4xx_HAL_Driver/Inc
    - Drivers/STM32F4xx_HAL_Driver/Src
    - Drivers/CMSIS/Include
    - Drivers/CMSIS/Device/ST/STM32F4xx/Include
    
  :support:
    - TDD_Tests/support
  :libraries: []

:defines:
  # in order to add common defines:
  #  1) remove the trailing [] from the :common: section
  #  2) add entries to the :common: section (e.g. :test: has TEST defined)
  :common: [] #&common_defines []
  :test:
    #- *common_defines
    - STM32F407xx
    - TDD_TEST_ACTIVE
    - USE_HAL_DRIVER
    - UA_ARCHITECTURE_FREERTOSLWIP
    - USE_FULL_LL_DRIVER
  :test_preprocess:
    #- *common_defines
    - TDD_TEST_ACTIVE

:cmock:
  :mock_prefix: mock_
  :when_no_prototypes: :warn
  :enforce_strict_ordering: TRUE
  :includes:
    - stm32f4xx.h
  :plugins:
    - :ignore
    - :expect_any_args
    - :array
    - :callback
    - :return_thru_ptr
  :strippables:
    - ['(?:WRITE_REG\s*\(+.*?\)+)']
  :treat_as:
    uint8:    HEX8
    uint16:   HEX16
    uint32:   UINT32
    uint32:   long unsigned int
    int8:     INT8
    int16:    INT16
    bool:     UINT8

# Add -gcov to the plugins list to make sure of the gcov plugin
# You will need to have gcov and gcovr both installed to make it work.
# For more information on these options, see docs in plugins/gcov
#:gcov:
#  :reports:
#    - HtmlDetailed
#  :gcovr:
#    :html_medium_threshold: 75
#    :html_high_threshold: 90

:gcov:
    :html_report: TRUE
    :html_report_type: detailed
    :html_medium_threshold: 75
    :html_high_threshold: 90
    :xml_report: TRUE

    :gcovr:
        :abort_on_uncovered: false

#:tools:
# Ceedling defaults to using gcc for compiling, linking, etc.
# As [:tools] is blank, gcc will be used (so long as it's in your system path)
# See documentation to configure a given toolchain for use

:flags:
  :test:
    :compile:
      :*:
        - -Wall
        - -Wextra
        # Extra flags to avoid cast warnings in the HAL library
        - -Wno-int-to-pointer-cast 
        - -Wno-pointer-to-int-cast
        - -Wno-error=address

# LIBRARIES
# These libraries are automatically injected into the build process. Those specified as
# common will be used in all types of builds. Otherwise, libraries can be injected in just
# tests or releases. These options are MERGED with the options in supplemental yaml files.
:libraries:
  :placement: :end
  :flag: "-l${1}"
  :path_flag: "-L ${1}"
  :system: []    # for example, you might list 'm' to grab the math library
  :test: []
  :release: []

:plugins:
  :load_paths:
    - "#{Ceedling.load_path}"
  :enabled:
    - stdout_pretty_tests_report
    - xml_tests_report
    - module_generator
    - gcov
...

我尝试过的:

  1. 直接在project.yml中添加include路径。
  2. 使用环境变量来管理包含路径。
  3. 创建本地包含目录并在那里复制必要的标头。
  4. 尽管做出了这些努力,我仍然遇到了 Ceedling 识别 reent.h 文件的问题。

要求: 有人可以指导我如何正确配置 Ceedling 来处理这种依赖性吗? Ceedling 项目中是否有管理此类依赖关系的最佳实践?任何帮助或建议将不胜感激!

unit-testing freertos ceedling
1个回答
0
投票

你试过这样吗:

:paths:
  :test:
    - +:path/to/test/
    - -:path/to/test/support
  :source:
    - +:path/to/source/**
  :include:
    - +:path/to/source/**
    - +:path/to/reent/**
  :support:
    - path/to/test/support/

所以在你的情况下:

:paths:
  ...
  :include:
    - +:C:/ST/STM32CubeIDE_1.9.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127/tools/arm-none-eabi/include/**

在不相关的注释中,如果可能的话,我会尝试修改该路径。

如果这不起作用,你可以像这样尝试教程在部分包括我们的模拟中的其他头文件

中描述了它
:cmock:
  ...
  :includes:
    - <reent.h>
  :treat_externs: :include
© www.soinside.com 2019 - 2024. All rights reserved.