You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Unity Ceedling测试框架生成IAR编译器的test.out文件

集成Unity Ceedling与IAR编译器:单测试文件.out生成问题解决

问题描述

我正尝试在IAR编译器中集成Unity Ceedling测试框架,但Ceedling要求为每个测试文件生成对应的.out文件,而IAR默认仅生成项目级.out文件,请问如何解决该问题或为单个测试文件生成对应的.out文件?

当前工具配置

:test_compiler:
    :executable: IarBuild.exe
    :name: 'IAR test compiler'
    :arguments:
      - path to the project.ewp                
      - '-build'              # 执行构建命令
      - 'Build configuration name '               # 构建配置名称

# 该命令可生成.out文件,曾尝试其他IAR命令但运行报错,故移除
:test_linker:
    :executable: ilinkarm.exe
    :name: 'IAR test linker'
    :arguments:
      - --vfe  # 极速可执行文件模式
      - --redirect _Printf=_PrintfFull
      - --redirect _Scanf=_ScanfFull
      - --config "path to generic_cortex.icf"
      - --map "path to project.map"
      # 未来可添加额外参数
      # - -o "path to the project.out folder"
        
:test_fixture:
    :executable: CSpyBat.exe
    :name: 'CSpyBat test runner'
    :arguments:
      - --backend
      - simulator
      - --plugin
      - '"path to armproc.dll"'
      - '"path to jlinkarm.dll"'
      - '"path to armsim2.dll"'
      - --plugin "path to armbat.dll"

错误信息

Error[Li005]: no definition for "__iar_program_start" [program entry]
Fatal error[Li010]: no modules to link
Fatal error detected, aborting.
ERROR: Shell command failed.

执行的Shell命令:
ilinkarm.exe --vfe --redirect _Printf=_PrintfFull --redirect _Scanf=_ScanfFull --config "generic_cortex.icf" --map "project_name.map"
输出内容:
IAR ELF Linker V8.50.9.278/W32 for ARM
Copyright 2007-2020 IAR Systems AB.
退出状态:[3].

rake aborted!
C:/Ruby27-x64/bin/ceedling:23:in `load' C:/Ruby27-x64/bin/ceedling:23:in `<main>'

原因:
ShellExecutionException: ShellExecutionException
C:/Ruby27-x64/bin/ceedling:23:in `load' C:/Ruby27-x64/bin/ceedling:23:in `<main>'
任务:TOP => build/test/results/test_file.pass => build/test/out/test_file.out
(运行任务时添加--trace查看完整追踪信息)
ERROR: Ceedling Failed

提示给出的可能原因:

  • 测试代码缺少对应所需源文件的#include语句。
  • 项目搜索路径不包含测试代码#include语句对应的源文件。
  • 测试代码未#include所需的mock文件。

解决方案

1. 替换测试编译器为IAR单文件编译器(iccarm.exe)

放弃使用IarBuild.exe编译整个项目,改用IAR的C编译器iccarm.exe单独编译每个测试文件、被测试源文件及Unity框架文件,让Ceedling独立控制每个测试单元的编译流程。调整后的配置示例:

:test_compiler:
  :executable: iccarm.exe
  :name: 'IAR test compiler'
  :arguments:
    - --cpu Cortex-M4  # 根据目标CPU调整
    - -I"${PROJECT_ROOT}/src/include"  # 项目头文件路径
    - -I"${CEEDLING_ROOT}/vendor/unity/src"  # Unity框架头文件路径
    - -D__ICCARM__
    - -DDEBUG
    - -o "${OBJECT_FILE}"  # Ceedling自动替换的目标文件路径
    - "${SOURCE_FILE}"  # Ceedling自动替换的源文件路径

2. 修复链接器配置,补充必要依赖

链接器报错的核心是未传入待链接模块,且缺少IAR启动代码和运行时库。调整链接器配置,添加启动文件、目标文件列表及运行时库:

:test_linker:
  :executable: ilinkarm.exe
  :name: 'IAR test linker'
  :arguments:
    - --vfe
    - --redirect _Printf=_PrintfFull
    - --redirect _Scanf=_ScanfFull
    - --config "${PROJECT_ROOT}/config/generic_cortex.icf"  # 你的ICF配置文件路径
    - --map "${MAP_FILE}"  # Ceedling自动替换的map文件路径
    - -o "${OUTPUT_FILE}"  # Ceedling自动替换的.out文件路径
    - "${PROJECT_ROOT}/src/startup_cortexm4.s"  # 对应CPU的启动文件
    - "${TEST_OBJECT_FILES}"  # Ceedling自动收集的测试目标文件
    - "${SOURCE_OBJECT_FILES}"  # Ceedling自动收集的被测试代码目标文件
    - --library rdimon.lib  # 根据CPU选择对应的运行时库
    - --library libc.a

3. 验证Ceedling路径配置

确保在project.yml中正确配置:sources:和:includes:,让Ceedling能找到被测试的源文件和头文件:

:paths:
  :test:
    - +:test/**
    - -:test/support
  :source:
    - src/**
  :include:
    - include/**

4. 检查测试文件完整性

  • 确保测试文件中包含#include "unity.h"
  • 确认已正确包含被测试模块的头文件
  • 如果使用Mock,确保包含对应的Mock头文件

错误根源说明

之前使用IarBuild.exe编译整个项目,Ceedling无法将单个测试文件的编译流程独立出来,导致链接器未收到任何需要链接的目标文件(对应no modules to link错误);同时缺少IAR启动代码的链接,引发__iar_program_start符号缺失。

内容的提问来源于stack exchange,提问作者Iox

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 08:58:15