单元测试的实时/并行软件 [英] Unit testing real-time / concurrent software

查看:97
本文介绍了单元测试的实时/并行软件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  我应该如何单元测试线程code?

经典的单元测试,基本上只是把x和期待ÿ出来,自动化这一进程。所以这是很好的测试任何的不涉及时间的。不过,大部分的非平凡的错误我遇到的有是与时间。螺纹损坏的对方的数据,或者导致死锁。不确定的行为发生 - 在一个用完万元。硬的东西。

The classical unit testing is basically just putting x in and expecting y out, and automating that process. So it's good for testing anything that doesn't involve time. But then, most of the nontrivial bugs I've come across have had something to do with timing. Threads corrupt each others' data, or cause deadlocks. Nondeterministic behavior happens – in one run out of million. Hard stuff.

有没有多线程,并发系统的单元测试部分有用的东西了吗?如何这样的测试工作?是不是有必要运行这样的测试很长一段时间的主题并改变一些巧妙的方式对环境,成为有理由相信,它工作正常?

Is there anything useful out there for "unit testing" parts of multithreaded, concurrent systems? How do such tests work? Isn't it necessary to run the subject of such test for a long time and vary the environment in some clever manner, to become reasonably confident that it works correctly?

推荐答案

大部分的工作我做的这些天涉及到多线程和/或分布式系统。大多数的bug涉及发生 - 前式的错误,其中开发的假设的(错误地)事件A总是会活动B.但在此之前发生的程序正在运行的每一次第一百万,事件B发生的第一,这将导致未predictable行为。

Most of the work I do these days involves multi-threaded and/or distributed systems. The majority of bugs involve "happens-before" type errors, where the developer assumes (wrongly) that event A will always happen before event B. But every 1000000th time the program is run, event B happens first, and this causes unpredictable behavior.

此外,有没有真正检测时序问题的好工具,或由竞争条件甚至数据损坏。像Helgrind工具和从Valgrind的工具DRD为琐碎的程序工作的伟大,但他们不是在诊断大型复杂系统非常有用。一方面,他们报告误报相当频繁(特别是Helgrind)。对于另一件事,很难真正发现某些错误而下Helgrind / DRD运行,只是因为Helgrind下运行的程序运行近1000倍的速度较慢,而且你经常需要相当长的时间,即使运行一个程序的重现比赛状态。另外,由于Helgrind下运行完全改变程序的定时,有可能成为<青霉>不可能的重现某一定时问题。这是与微妙的时序问题的问题;他们在某种意义上几乎Heisenbergian,改变一个程序来检测时序问题可能掩盖了原来的问题。

Additionally, there aren't really any good tools to detect timing issues, or even data corruption caused by race conditions. Tools like Helgrind and drd from the Valgrind toolkit work great for trivial programs, but they are not very useful in diagnosing large, complex systems. For one thing, they report false positives quite frequently (Helgrind especially). For another thing, it's difficult to actually detect certain errors while running under Helgrind/drd simply because programs running under Helgrind run almost 1000x slower, and you often need to run a program for quite a long time to even reproduce the race condition. Additionally, since running under Helgrind totally changes the timing of the program, it may become impossible to reproduce a certain timing issue. That's the problem with subtle timing issues; they're almost Heisenbergian in the sense that altering a program to detect timing issues may obscure the original issue.

可悲的事实是,人类仍然没有充分prepared处理复杂,并发软件。所以,不幸的是,有没有简单的方法来单元测试。对于分布式系统,尤其是,你应该计划你的程序仔细使用<一个href=\"http://www.google.com/#hl=en&ei=apj-SvqpO4a9lAe1kfWNCw&sa=X&oi=spell&resnum=0&ct=result&cd=1&ved=0CAYQBSgA&q=lamport%27s+happens+before&spell=1&fp=94f5bc3d92523f1a\">Lamport's碰巧,前图,以帮助您识别程序事件的必要秩序。但最终,你真的不能与随机变化的投入获得强力的单元测试了。它还有助于,例如改变你的单元测试过程中的线程上下文切换的频率运行的另一个后台过程,只是占用的CPU周期。另外,如果你有机会获得一个集群,可以并行运行多个单元测试,从而可以更快地检测到错误,并为您节省大量的时间。

The sad fact is, the human race still isn't adequately prepared to deal with complex, concurrent software. So unfortunately, there's no easy way to unit-test it. For distributed systems especially, you should plan your program carefully using Lamport's happens-before diagrams to help you identify the necessary order of events in your program. But ultimately, you can't really get away from brute-force unit testing with randomly varying inputs. It also helps to vary the frequency of thread context-switching during your unit-test by, e.g. running another background process which just takes up CPU cycles. Also, if you have access to a cluster, you can run multiple unit-tests in parallel, which can detect bugs much quicker and save you a lot of time.

这篇关于单元测试的实时/并行软件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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