CppUnit 的多线程实现?
有人可以向我指出一个允许在单独的线程中启动测试的 CppUnit 版本吗?
我们的想法是,由于我们的许多测试都需要大量 CPU(但不是多线程,当然,它们是相互独立的),因此它将使我们能够在当今的多核上更快地运行测试机器。目前,运行所有测试大约需要 5 分钟。如果能够将其缩短到 1 或 2 分钟,那就太好了……
Could someone point me to a version of CppUnit that would allow to launch the tests in separate threads?
The idea is that, because many of our tests are quite CPU heavy (but are not multi-thread and, of course, are independant one from the other), it would allow us to run the tests much more quickly on today's multi-core machines. Currently, it takes around 5 minutes to run all the tests. It would be great to be able to reduce this to 1 or 2 minutes...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您认为等待测试完成五分钟是很长的时间!尝试几个小时。我有以下动机。
使用 Boost 线程,CppUnit 线程化非常简单。 CppUnit 已经有一些用于同步的钩子,因此以下内容应该使其线程安全:
有了这个,您可以修改测试运行器以使
TestResult
线程安全。只需编写类似CPPUNIT_NS::TestResult testResult(new Mutex);
的内容即可。现在这是一个线程测试套件:您可能很需要一个宏来轻松使用线程测试套件。您应该能够将 TestSuiteThreaded 套件用作顶级套件或包含同一文本固定装置的多个方法的套件。以下是执行后者的方法 - 将其替换
CPPUNIT_TEST_SUITE_END
。其中一些内容是从 CppUnit 粘贴的,因此请尊重许可证:现在有一个
ThreadPool
的小问题。我尝试使用各种公开的方法但没有成功。我的公司有一个,但我无法在这里发布。因此,您可以自己动手 - 在 Boost 的帮助下,制作线程池非常简单且有趣。这是 TestSuiteThreaded 所期望的接口:我将其作为练习留给读者。玩得开心!
You think five minutes is a long time to wait for tests to complete! Try several hours. I had motivation for the following.
Using Boost threads, CppUnit threading is pretty easy. CppUnit already has some hooks for synchronization so the following should make it thread safe:
With this, you can modify your test runner to make your
TestResult
thread safe. Just write something likeCPPUNIT_NS::TestResult testResult(new Mutex);
. Now here's a threaded test suite:You may well need a macro for easy use of the threaded test suite. You should be able to use
TestSuiteThreaded
suite either as a top level suite or a suite comprising multiple methods of the same text fixture. Here's how you do the latter - put this in place ofCPPUNIT_TEST_SUITE_END
. Some of this is pasted from CppUnit so please respect the license:Now there is the small matter of a
ThreadPool
. I tried using various publicly available ones with no success. My company has one but I'm unable to publish it here. So roll your own - thread pools are pretty easy and fun to make, with help from Boost. Here is the interface expected byTestSuiteThreaded
:I leave this as an exercise for the reader. Have fun!
考虑到这个问题你得到了多少答案,特别是与赞成票数相比,我怀疑有人已经做出了一个好的多线程单元测试框架,无论它是多么伟大的想法。对于某人来说,这似乎是一个绝佳的机会,可以通过开发一些非常有用的东西来扬名立万。
Given how many answers to this question you've gotten, especially as compared with the number of upvotes, I doubt anybody has made a good multi-threaded unit testing framework, no matter how great an idea it is. This looks like a great opportunity for someone to make a name for themselves developing something inordinately useful.