嵌入式系统上中断密集型代码的单元测试
我正在为 AVR 芯片编写 C 代码。该代码大量使用等待串行端口的中断服务例程 (ISR),ADC 和计时器。 ISR 写入缓冲区,主循环在到达缓冲区时会检查缓冲区。
我设计了缓冲区,以便 ISR 可以在主循环读取缓冲区时更新它们。我想验证这是否有效。我有单元测试来验证基本操作,但我不清楚如何测试在主循环读取缓冲区时触发中断会发生什么。
我的单元测试非常基础——main()
函数中的一些代码。我在我的 Linux 机器上运行测试。
I am writing C code for an AVR chip. The code is heavy on interrupt service routines (ISRs) which wait on serial ports, ADCs and timers. The ISRs write to buffers which the main loop examines when it gets to them.
I design the buffers so that ISRs can update them while the main loop is reading them. I want to verify that this works. I have unit tests to validate basic operation, but I'm not clear on how to test what happens if an interrupt fires while the main loop is reading a buffer.
My unit tests are really basic--some code in a main()
function. I run the tests on my Linux box.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
线程?
启动一个高优先级线程,该线程以类似于真实情况的某种速率调用 ISR。
然后在你的 main 中,在循环中一遍又一遍地读取缓冲区。验证缓冲区读取未损坏。
(也许这更像是集成测试而不是纯粹的单元测试。)
Threads?
Launch a high-priority thread which calls your ISR at some rate similar to the real thing.
Then in your main, do the buffer read over and over again in a loop. Validate that the buffer read is not corrupted.
(Maybe this is more of an integration test than a pure unit test.)