你如何测试你的中断处理模块?
我有一个中断处理模块,它控制嵌入式处理器上的中断控制器硬件。 现在我想为其添加更多测试。 目前,测试仅通过在 ISR 中发出两个软件中断(一个具有低优先级,一个具有高优先级)来测试中断嵌套是否有效。 我如何进一步测试这个模块?
I've got an interrupt handling module which controls the interrupt controller hardware on an embedded processor. Now I want to add more tests to it. Currently, the tests only tests if nesting of interrupts works by making two software interrupts from within an ISR, one with low priority and one with high priority. How can I test this module further?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我建议你也尝试创造其他刺激。
通常,硬件中断也可以由软件(自动测试)或调试器通过设置标志来触发。 或者通过 I/O 作为中断。 或者定时器中断。 或者,您可以在单步执行时通过调试器在中断控制器中设置中断位。
您可以对不应该发生的事情添加一些运行时检查。 有时我选择设置输出引脚以进行外部监视(如果您有示波器或逻辑分析仪,那就太好了......)
软件中断的缺点是时刻是固定的; 总是相同的指令。 我相信您希望看到它总是有效的证据; 无死锁。
对于中断服务例程,我发现代码审查非常有价值。 最后你只能测试你想象的情况,并且在某些时候测试的工作量会非常高。 ISR 是出了名的难以调试。
我认为提供以下测试很有用:
- isr 不会因较低优先级中断而中断
- isr 不会因相同优先级中断而被中断
- isr 因更高优先级中断而被中断
- 堆栈限制内的最大嵌套计数。
你的一些测试可能会作为工具保留在代码中(这样你就可以监控例如最大嵌套级别。
哦,还有一件事:我通常设法使 ISR 如此短,以至于我可以避免嵌套......如果这将为您带来额外的简单性和更高的性能
。
当然,ISR也需要在系统的硬件上进行测试。 除了一点一点、一步一步的方法之外,您可能还想证明:
- 最大中断负载下系统的稳定性(最好是预测最大负载的几倍;如果您的 115kbps 串行驱动程序也可以处理 2MBps,那就没问题了!)
- 启用/禁用ISR的正确时刻,特别是当系统也进入睡眠模式时
- 中断数量。 如果添加机械开关、机械旋转(在达到稳定状态之前数百次断开/接触时刻),可能会令人惊讶
I suggest that you try to create other stimuli as well.
Often, also hardware interrupts can be triggered by software (automatic testing) or the debugger by setting a flag. Or as an interrupt via I/O. Or a timer interrupt. Or you can just set the interrupt bit in an interrupt controller via the debugger while you are single stepping.
You can add some runtime checks on things which are not supposed to happen. Sometimes I elect to set output pins to monitor externally (nice if you have an oscilloscope or logic analyser...)
The disadvantage of the software interrupt is that the moment is fixed; always the same instruction. I believe you would like to see evidence that it always works; deadlock free.
For interrupt service routines I find code reviews very valuable. In the end you can only test the situations you've imagined and at some point the effort of testing will be very high. ISRs are notoriously difficult to debug.
I think it is useful to provide tests for the following:
- isr is not interrupted for lower priority interrupt
- isr is not interrupted for same priority interrupt
- isr is interrupted for higher priority interrupt
- maximum nesting count within stack limitations.
Some of your tests may stay in the code as instrumentation (so you can monitor for instance maximum nesting level.
Oh, and one more thing: I've generally managed to keep ISRs so short that I can refrain from nesting.... if you can this will gain you additional simplicity and more performance.
[EDIT]
Of course, ISRs need to be tested on hardware in system too. Apart from the bit-by-bit, step-by-step approach you may want to prove:
- stability of system at maximum interrupt load (preferably several times the predicted maximum load; if your 115kbps serial driver can also handle 2MBps you'll be ok!)
- correct moment of enabling / disabling isr, especially if system also enters a sleep mode
- # of interrupts. Can be surprising if you add mechanical switches, mechanical rotary (hundreds of break/contact moments before reaching steady situation)
我建议进行真实的硬件测试。 中断处理本质上是随机且不可预测的。
使用信号发生器并将方波馈入适当的中断引脚。 使用多个生成器(或一个具有多个输出的生成器)来测试多个 IRQ 线并验证优先级处理。
尝试调高频率并降低频率。 关闭信号发生器(改变它们之间的速率),看看会发生什么。 有大量的诊断代码来验证中断控制器在各种状态下的状态。
替代方案:如果您的平台具有可以触发中断的计时器,您可以使用它们而不是外部硬件。
I recommend real-hardware testing. Interrupt handling is inherently random and unpredictable.
Use a signal generator and feed a square wave into the appropriate interrupt pin. Use multiple generators (or one with multiple outputs) to test multiple IRQ lines and verify priority handling.
Experiment with dialing the frequency up & down on the signal generators (vary the rates between them), and see what happens. Have lots of diagnostic code to verify the state of the interrupt controller in the various states.
Alternative: If your platform has timers that can trigger interrupts, you can use them instead of external hardware.
我不是嵌入式开发人员,所以我不知道这是否可行,但是如何将处理中断的代码与回调注册机制解耦呢? 这将允许您编写模拟器代码来触发中断事件,就像您喜欢的那样......
I'm not an embedded developer, so I don't know if this is possible, but how about decoupling the code that handles the interrupts from the callback-registration mechanism? This would allow you to write simulator code fireing interrupt-events as you like it...
对于这样的东西,我强烈推荐诸如 SPIN 模型检查器之类的东西。 您最终测试的是算法,而不是代码,但测试是详尽的。 回到过去,我在
gdb< 中发现了一个错误/code>
使用这种技术。
For stuff like this I highly recommend something like the SPIN model checker. You wind up testing the algorithm, not the code, but the testing is exhaustive. Back in the day, I found a bug in
gdb
using this technique.