测试code为嵌入式应用 [英] Testing Code for Embedded Application

查看:196
本文介绍了测试code为嵌入式应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

我正在开发使用爱特梅尔AVR atmega2560一个相当大的项目。这个项目包含了大量的基于硬件功能(7 SPI器件,2 I2C,2个RS485 MODBUS口,大量的模拟和数字I / O的)。我所研制的驱动程序为所有这些设备提供了哪些主要应用循环与访问所需数据的接口。

I am developing a largish project using at Atmel AVR atmega2560. This project contains a lot of hardware based functions (7 SPI devices, 2 I2C, 2 RS485 MODBUS ports, lots of Analogue and Digital I/O). I have developed "drivers" for all of these devices which provide the main application loop with an interface to access the required data.

问:

我开发该项目最终将必须符合SIL标准。

The project I am developing will eventually have to meet SIL standards.

我想是能够测试code和提供code覆盖一个良好的水平。但是我无法找到任何信息,让我开始在这样一个测试框架应该如何设置。

I would like to be able to test the code and provide a good level of code coverage. However I am unable to find any information to get me started on how such a testing framework should be set up.

的想法是,我可以拥有一套自动化测试,这将使未来的bug修复和新增功能进行测试,看看他们是否突破code。事情是,我不明白是怎么code可以在芯片上进行测试。

The idea is that I can have a suite of automated tests which will allow future bug fixes and feature additions to be tested to see if they break the code. The thing is I don't understand how the code can be tested on chip.

我是否需要硬件监控设备上的I / O和模拟外部连接的设备?可以提供的任何指针将是非常美联社preciated。

Do I require hardware to monitor the I/O on the device and emulate externally connected devices? Any pointers that could be provided would be highly appreciated.

- 史蒂夫

推荐答案

这是一个很好的问题 - 为嵌入式开发人员共同关注的问题。不幸的是,大多数嵌入式开发人员并不像关心你的,只有测试在真实硬件的code。但正如另一种答案指出,这基本上可以测试只是code的标称功能,而不是边角/错误情况。

This is a very good question - a common concern for embedded developers. Unfortunately, most embedded developers aren't as concerned as you are and only test the code on real hardware. But as another answer pointed out, this can basically test just the nominal functionality of the code and not the corner/error cases.

有没有单一的,简单地解决这个问题。一些准则和技术存在,但是,做一个比较好的工作。

There is no single and simple solution to this problem. Some guidelines and techniques exist, however, to do a relatively good job.

首先,你的code分层。一层应该是硬件不可知 - 即函数调用。不要问用户写入HW直接注册。其他(下部)层处理的硬件。为了测试上级该层可以被嘲笑。在较低的水平离不开硬件得到真正的测试,但它不会经常更换,需要深HW整合,所以它不是一个问题。

First, separate your code into layers. One layer should be "hardware agnostic" - i.e. function calls. Do not ask the user to write into HW registers directly. The other (lower) layer deals with the HW. This layer can be "mocked" in order to test the higher level. The lower level can not be really tested without the HW, but it's not going to change often and needs deep HW integration, so it's not an issue.

一个测试工具将是您所有的高层硬件无关code与假下专门用于测试的水平。它可以仿真的正确和不正确的功能的硬件设备,从而让你在PC上运行自动化测试。

A "test harness" will be all your high-level HW agnostic code with a "fake" lower level specifically for testing. This can simulate the HW devices for correct and incorrect functionality and thus allow you to run automated tests on the PC.

这篇关于测试code为嵌入式应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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