我正在尝试为嵌入式应用程序开发一项新功能,并且我想使用测试驱动的方法来做到这一点。
该项目是用纯 C 编写的,正在使用 IAR Embedded Workbench 6.60.1.5104 进行开发。我的目标是 LPC1788,它是一个 Cortex-M3 设备,所有开发都是在 64 位 Windows 7 机器上完成的。现在我更倾向于让单元测试在 PC 上而不是在目标硬件上运行(RAM 非常有限)。
我遇到了一本有用的书,名为Test Driven Development for Embedded C,它向我介绍了 Unity、CppUTest、Ceedling 等工具。在研究了这些东西之后,我认为我最好的选择是配置 Ceedling(它使用 Unity ) 对于我的项目。但是,我不确定需要采取哪些步骤来配置 Ceedling 以使用我当前的 IAR 工具链。
我已经安装了 Ceedling 并创建了“blinky”示例项目,我正在尝试使用 IAR 工具链构建和测试它。我已添加iccarm.exe
到我的路径并进行blinky/project.yml
了如下编辑:
---
# Notes:
# This is a fully tested project that demonstrates the use
# of a timer ISR to blink the on board LED of an Arduino UNO
:project:
:use_exceptions: FALSE
:use_test_preprocessor: TRUE
:use_auxiliary_dependencies: TRUE
:build_root: build
:release_build: TRUE
:test_file_prefix: test_
#You'll have to specify these
:environment:
- :mcu: atmega328p
- :f_cpu: 16000000UL
- :serial_port: COM8 #change this to the serial port you are using!!!
- :objcopy: avr-objcopy
# Uncomment these lines if you are using windows and don't have these tools in your path
# - :path:
# - C:\mingw\bin
# - C:\WinAVR-20100110\bin
# - C:\WinAVR-20100110\utils\bin
# - #{ENV['PATH']}
:extension:
:executable: .bin
:release_build:
:output: blinky
:paths:
:test:
- +:test/**
- -:test/support
:source:
- src/**
:support:
- test/support
: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)
:commmon: &common_defines []
:test:
- *common_defines
- TEST
:test_preprocess:
- *common_defines
- TEST
:tools:
:release_compiler:
:executable: avr-gcc
:arguments:
- ${1}
- -DTARGET
- -DF_CPU=#{ENV['F_CPU']}
- -mmcu=#{ENV['MCU']}
- -Iinclude/
- -Wall
- -Os
- -c
- -o ${2}
:release_linker:
:executable: avr-gcc
:arguments:
- -mmcu=#{ENV['MCU']}
- ${1}
- -o ${2}.bin
:cmock:
:mock_prefix: mock_
:when_no_prototypes: :warn
:enforce_strict_ordering: TRUE
:plugins:
- :ignore
:treat_as:
uint8: HEX8
uint16: HEX16
uint32: UINT32
int8: INT8
bool: UINT8
:tools:
:test_file_preprocessor:
:executable: iccarm
:name: 'IAR test file preprocessor'
:test_includes_preprocessor:
:executable: iccarm
:name: 'IAR test includes preprocessor'
:test_compiler:
:executable: iccarm
:name: 'IAR test compiler'
:test_linker:
:executable: iccarm
:name: 'IAR test linker'
:release_compiler:
:executable: iccarm
:name: 'IAR release compiler'
:release_linker:
:executable: iccarm
:name: 'IAR release linker'
:plugins:
:load_paths:
- vendor/ceedling/plugins
:enabled:
- stdout_pretty_tests_report
- module_generator
...
这和默认的唯一区别project.yml
是第二:tools
部分下的内容。
我的猜测是我正朝着正确的方向前进,但我不确定是否iccarm.exe
是用于工具链所有这些部分的正确可执行文件以及我需要传递哪些参数。
如果我可以配置 Ceedling 以使用 IAR 工具链构建和测试闪烁项目,我希望我应该能够为我的实际项目应用相同的配置。如果我现在尝试运行rake
,我会得到以下输出:
$ rake
Test 'test_BlinkTask.c'
-----------------------
rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - build/test/preprocess/files/test_BlinkTask.c
C:/Users/davidfallah/Documents/IAR Projects/blinky/vendor/ceedling/lib/ceedling/preprocessinator_extractor.rb:18:in `readlines'
C:/Users/davidfallah/Documents/IAR Projects/blinky/vendor/ceedling/lib/ceedling/preprocessinator_extractor.rb:18:in `extract_base_file_from_preprocessed_expansion'
C:/Users/davidfallah/Documents/IAR Projects/blinky/vendor/ceedling/lib/ceedling/preprocessinator_file_handler.rb:14:in `preprocess_file'
C:/Users/davidfallah/Documents/IAR Projects/blinky/vendor/ceedling/lib/ceedling/preprocessinator.rb:40:in `preprocess_file'
C:/Users/davidfallah/Documents/IAR Projects/blinky/vendor/ceedling/lib/ceedling/preprocessinator.rb:12:in `block in setup'
C:/Users/davidfallah/Documents/IAR Projects/blinky/vendor/ceedling/lib/ceedling/preprocessinator_helper.rb:33:in `preprocess_test_file'
C:/Users/davidfallah/Documents/IAR Projects/blinky/vendor/ceedling/lib/ceedling/preprocessinator.rb:25:in `preprocess_test_and_invoke_test_mocks'
C:/Users/davidfallah/Documents/IAR Projects/blinky/vendor/ceedling/lib/ceedling/test_invoker.rb:42:in `block in setup_and_invoke'
C:/Users/davidfallah/Documents/IAR Projects/blinky/vendor/ceedling/lib/ceedling/test_invoker.rb:32:in `setup_and_invoke'
C:/Users/davidfallah/Documents/IAR Projects/blinky/vendor/ceedling/lib/ceedling/tasks_tests.rake:11:in `block (2 levels) in <top (required)>'
Tasks: TOP => default => test:all
(See full trace by running task with --trace)
--------------------
OVERALL TEST SUMMARY
--------------------
No tests executed.
我认为这是因为测试文件预处理器应该在build/test/preprocess/files
目录下复制测试文件,这目前不会发生。
经过一番挖掘后,我发现这个Unity 示例配置文件看起来可能会有所帮助。它面向 IAR EW/Cortex M3 环境,就像我正在使用的那样。这可能会表明我需要在我的 Ceedling 中指定哪些配置选项project.yml
:
如果我可以让 Ceedlingblinky
使用 IAR 工具链构建和测试项目,我希望我可以调整它以适应我的实际项目。任何帮助,将不胜感激。