强制在CMake中针对特定目标执行串行执行 [英] Force serial execution for specific targets in CMake
问题描述
在我的CMake项目中,我有几个目标,它们仅运行一组特定的单元测试(例如, runTestsForA
, runTestsForB
和 runTestsForC
)。
我还有一个目标 tests
,它取决于所有这些单元测试目标,因此我可以用一个命令运行它们。
我正在使用CLion是我的IDE,它默认尝试使用并行make构建(我想要并且也在Continuous Integration服务器上使用)。
但是,看起来这些测试现在也正在并行运行,并且还没有为此进行某些测试(它们使用本地环回对套接字进行了一些魔术处理),这导致它们失败。 p>
这就是为什么我要强制对 tests
目标的某些/所有依赖项执行串行执行的原因。
不幸的是,当我搜索有关如何执行此操作的信息时,CMake文档没有帮助我。
这使我想到了一个问题:这是否可能?如果可行,怎么办?
您可以使用CTest工具来代替手动 tests
目标声明。使用 add_test
命令创建测试目标,然后CMake将自动创建将运行所有测试的 tests
目标:
enable_testing()
add_test(NAME TestsForA COMMAND< command>)
add_test(NAME TestsForB COMMAND< command> ;)
set_tests_properties(TestsForA TestsForB PROPERTIES RUN_SERIAL TRUE)
之后,您可以运行进行测试
或 ctest
。测试将被序列化。
更多信息,请参见:
- http://www.cmake.org/cmake/help/v3 .2 / command / add_test.html
- http://www.cmake.org/cmake/help/v3.2/command/enable_testing.html
- http://www.cmake.org/cmake/help/v3.2/command /set_tests_properties.html
- http://www.cmake.org/cmake/help/v3.2/manual/cmake-properties.7.html#properties-on-tests
- http ://www.cmake.org/cmake/help/v3.2/manual/ctest.1.html
In my CMake project I have several targets which simply run a certain set of unit tests (for example, runTestsForA
, runTestsForB
and runTestsForC
).
I also have a target, tests
, that depends on all of these unit test targets, so I can run them with a single command.
I'm using CLion is my IDE, which tries to use parallel make builds by default (which I want and am also doing on the Continuous Integration server). However, it looks like the tests are running in parallel too now and some tests are not made for this (they use a local loopback to do some magic with sockets), which causes them to fail.. sometimes.
That is why I would like to force serial execution for some/all of the dependencies of my tests
target.
Unfortunately the CMake documentation did not help me, when I was searching information on how to do this.
Which brings me to my questions: is this at all possible and how can it be done if it is?
Instead of manual tests
target declaration you can use CTest tool. Use add_test
command to create test targets, then CMake will automatically create tests
target that will run all tests:
enable_testing()
add_test(NAME TestsForA COMMAND <command>)
add_test(NAME TestsForB COMMAND <command>)
set_tests_properties(TestsForA TestsForB PROPERTIES RUN_SERIAL TRUE)
After that you can run make tests
or ctest
in your build tree. The tests will be serialized.
More information can be found at:
- http://www.cmake.org/cmake/help/v3.2/command/add_test.html
- http://www.cmake.org/cmake/help/v3.2/command/enable_testing.html
- http://www.cmake.org/cmake/help/v3.2/command/set_tests_properties.html
- http://www.cmake.org/cmake/help/v3.2/manual/cmake-properties.7.html#properties-on-tests
- http://www.cmake.org/cmake/help/v3.2/manual/ctest.1.html
这篇关于强制在CMake中针对特定目标执行串行执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!