单元测试模式为单片机C code [英] Unit testing patterns for microcontroller C code

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

问题描述

虽然有大量的单元测试框架,支持C,我对如何写微控制器code单元测试(PIC在我的情况有点难倒了,但我认为这个问题是比这更普遍)。

Although there are plenty of unit test frameworks that support C, I'm a little stumped on how to write unit tests for micro controller code (PIC in my case, but I think the question is more general than that).

对于许多微控制器写入code都是围绕着写的配置和数据值寄存器,读取寄存器输入数据和响应中断事件。我想知道如果任何人都可以提供最有效的方法来一些这方面的指针。

Much of the code written for micro controllers revolves around Writing configuration and data values to registers, reading incoming data from registers and responding to interrupt events. I'm wondering if anyone can provide some pointers on the most effective way to this.

推荐答案

您写;

对于许多微控制器写入code都是围绕着写的配置和数据值寄存器,读取寄存器输入数据和响应中断事件。

"Much of the code written for micro controllers revolves around Writing configuration and data values to registers, reading incoming data from registers and responding to interrupt events".

我同意这是在实践中经常的情况,但我真的不认为这是一件好事,我认为重新考虑事情有点会帮助你与你的测试目标。

I agree that this is often the case in practice, but I don't actually think this is a good thing, and I think rethinking things a little will help you with your test goals.

也许是因为微控制器编程的可以的伸手触摸硬件任何他们喜欢的时候,许多(大多数?)的人都陷入正是这样做的,在他们的code的习惯。通常,这种习惯是毫无疑问的后面,也许是因为如此多的人在做这样的工作是电子工程师不是计算机科学家通过培训和倾斜度。我知道,我开始了这样喽。

Perhaps because microcontroller programmers can reach out and touch the hardware any time they like, many (most?) of them have got into the habit of doing just that, throughout their code. Often this habit is followed unquestioningly, maybe because so many people doing this sort of work are EEs not computer scientists by training and inclination. I know, I started out that way myself.

我想指出的一点是,微控制器项目,可以而且应该精心设计像任何其他软件项目。好的设计一个非常重要的组成部分是限制硬件驱动程序的硬件访问!分区关闭所有code写入寄存器,响应中断等进入提供您的软件与漂亮的,干净的,抽象访问硬件的其他模块。使用逻辑分析仪,示波器,自定义的测试平台或任何其他有意义的测试目标的驱动模块。

The point I am trying to make, is that microcontroller projects can and should be well designed like any other software project. A really important part of good design is to restrict the hardware access to hardware drivers! Partition off all the code that writes registers, responds to interrupts etc. into modules that provide the rest of your software with nice, clean, abstracted access to the hardware. Test those driver modules on the target using logic analyzers, oscilloscopes, custom test rigs or whatever else makes sense.

有一个很重要的一点是,现在你的其它软件,希望绝大多数的它,现在只是C code,它可以在主机系统上运行和测试。在主机系统中的硬件模块在提供可视性什么被测code做的方式灭掉。你可以使用这个code主流的单元测试方法。这需要一些preparations和工作,但如果你有良好的组织,你可以创建适用于所有项目的可重复使用的系统。的潜在好处是巨大的。我写了一个小此处详细了解这些想法;

A really important point is that now the rest of your software, hopefully the great majority of it, is now just C code that you can run and test on a host system. On the host system the hardware modules are stubbed out in a way that provides visibility into what the code under test is doing. You can use mainstream unit testing approaches on this code. This needs some preparations and work, but if you are well organized you can create a reusable system that can apply to all your projects. The potential benefits are enormous. I wrote a little more about these ideas here;

[<一个href=\"http://discuss.joelonsoftware.com/default.asp?joel.3.530964.12\">http://discuss.joelonsoftware.com/default.asp?joel.3.530964.12][1]

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

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