如何做嵌入式代码覆盖 [英] How to do code coverage on embedded

查看:178
本文介绍了如何做嵌入式代码覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为非POSIX嵌入式系统编写了一个项目,所以我不能使用gcc选项 - 覆盖(我没有读或写)。还可以如何产生像gcov一样的输出。我有一个输出函数。

I write a project for a non POSIX embedded system so I cannot use gcc option --coverage (i don't have read or write). What else can I do to produce gcov like output. I do have an output function.

推荐答案

可以通过嵌入式跟踪处理器来最容易地完成,一个板设计暴露跟踪端口,以及合适的硬件调试器和关联软件。例如,许多基于Cortex-M的设备包括ARM的嵌入式跟踪宏单元(ETM),Keil的uVision IDE和ULINK-Pro调试器支持这一点,以提供代码覆盖和指令/源级跟踪以及实时分析。硬件跟踪具有非侵入性的优点 - 代码可以实时运行。

It can be most easily done with by a processor with embedded trace, a board design that exposes the trace port, and a suitable hardware debugger and associate software. For example, many Cortex-M based devices include ARM's embedded trace macrocell (ETM), and this is supported by Keil's uVision IDE and ULINK-Pro debugger to provide code coverage and instruction/source level trace as well as real-time profiling. Hardware trace has the advantage that it is non-intrusive - the code runs in real-time.

如果您没有硬件支持,您可能需要诉诸模拟。许多工具链包括执行跟踪,代码覆盖和分析的指令级别模拟器,但您可能必须创建调试脚本或代码存根来模拟硬件以强制执行所有路径。

If you do not have the hardware support, you may have to resort to simulation. Many tool-chains include an instruction level simulator that will perform trace, code-coverage, and profiling, but you may have to create debug scripts or code stubs to simulate hardware to coerce the execution of all paths.

第三种替代方法是在具有存根的桌面平台上构建代码,以替换目标硬件依赖关系,并执行测试和代码覆盖。您必须相信,目标C编译器和测试系统编译器都会使用相同的语义来翻译源代码。这里的优点是可用的调试工具通常优于嵌入式系统的调试工具。您还可以在任何硬件可用之前测试大部分代码,并且在大多数情况下,可以更快地执行代码,从而允许更广泛的测试。

A third alternative is to build the code on a desktop platform with stubs to replace target hardware dependencies, and perform testing and code coverage on that. You have to trust that the target C compiler and the test system compiler both translate the source with identical semantics. The advantage here is that the debug tools available are often superior to those available to embedded systems. You can also test much of your code before any hardware is available, and in most cases execute code much faster, possibly allowing more extensive testing.

没有POSIX API不排除使用GCC,它只是排除了使用GNU C库。在没有POSIX的嵌入式系统中,使用了诸如Newlib的替代C库。 Newlib具有实现I / O和基本堆管理的系统移植层。

Not having a POSIX API does not preclude using GCC, it merely precludes using the GNU C library. On embedded systems without POSIX, alternative C libraries are used such as Newlib. Newlib has a system porting layer where I/O and basic heap management are implemented.

这篇关于如何做嵌入式代码覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆