如何从 ctest 强制运行禁用的测试?

问题描述 投票:0回答:3

我有一个利用 cmake、ctest 和 gtest 的 C++ 项目。

出于回归目的,需要禁用我的一个测试,但我想手动运行它。

我通过使用命名测试的 gtest 技巧来禁用它

DISABLED_test_name

当我尝试运行它时,我看到以下内容:

$ ctest -R aie2_210a_ddr_2kernel_ddr_gmio_bd_api.maize_xrt --verbose
UpdateCTestConfiguration  from :/scratch/bryanloz/aie_controller_hax/test/build/DartConfiguration.tcl
Parse Config file:/scratch/bryanloz/aie_controller_hax/test/build/DartConfiguration.tcl
UpdateCTestConfiguration  from :/scratch/bryanloz/aie_controller_hax/test/build/DartConfiguration.tcl
Parse Config file:/scratch/bryanloz/aie_controller_hax/test/build/DartConfiguration.tcl
Test project /scratch/bryanloz/aie_controller_hax/test/build
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 8
    Start 8: aie2_210a_ddr_2kernel_ddr_gmio_bd_api.maize_xrt
1/1 Test #8: aie2_210a_ddr_2kernel_ddr_gmio_bd_api.maize_xrt ...***Not Run (Disabled)   0.00 sec
No tests were found!!!

如何覆盖此行为?

cmake googletest ctest
3个回答
3
投票

您可以使用

--gtest_also_run_disabled_tests
。此命令行标志强制运行所有 DISABLED_ 测试。

请注意,如果您有多个禁用的测试,并且只想使用命令行启用其中一个,则可以将此标志与

--gtest_filter
结合使用。

编辑 CTest

我不熟悉

CTest
,但显然没有一种简单的方法可以在运行时在 CTest 中传递命令行参数。也许您可以使用此解决方法来执行此操作,或者找到可执行文件并直接将参数传递给它查看此答案

作为传递命令行参数的替代方法,您可以将

GTEST_ALSO_RUN_DISABLED_TESTS
环境变量设置为 0 以外的值。请参阅 this


1
投票

对此没有好的解决方案。当我需要在本地测试时,我只会重建测试可执行文件。我还可以直接从适当的工作目录调用 gtest 可执行文件。

即使是建议的 ENV 在 CTest 场景中也没有得到尊重:

GTEST_ALSO_RUN_DISABLED_TESTS=1 ctest --verbose -R aie2_210a_ddr_2kernel_ddr_gmio_bd_api.maize_xrt
UpdateCTestConfiguration  from :/scratch/bryanloz/aie_controller_hax/test/build/DartConfiguration.tcl
Parse Config file:/scratch/bryanloz/aie_controller_hax/test/build/DartConfiguration.tcl
UpdateCTestConfiguration  from :/scratch/bryanloz/aie_controller_hax/test/build/DartConfiguration.tcl
Parse Config file:/scratch/bryanloz/aie_controller_hax/test/build/DartConfiguration.tcl
Test project /scratch/bryanloz/aie_controller_hax/test/build
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 9
    Start 9: aie2_210a_ddr_2kernel_ddr_gmio_bd_api.maize_xrt
1/1 Test #9: aie2_210a_ddr_2kernel_ddr_gmio_bd_api.maize_xrt ...***Not Run (Disabled)   0.00 sec
No tests were found!!!

0
投票

这个问题是 ctest 的问题,而不是 gtest 的问题。事实上,ctest 会很乐意为 gtest 提供正确的参数,但随后拒绝实际调用它。

我的解决方法:使用您选择的参数(即

ctest
-R
)运行
-E
,然后添加
-V -N
选项以获取它运行的命令的详细列表(如果可以的话)。然后复制并粘贴该命令行并运行它。

例如,

ctest -R MyClass -V -N

UpdateCTestConfiguration  from :/home/me/build/DartConfiguration.tcl
UpdateCTestConfiguration  from :/home/me/build/DartConfiguration.tcl
Test project /home/me/build
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements

198: Test command: /home/me/build/test/testMyClass "--gtest_filter=MyTest.DISABLED_SpeedTest" "--gtest_also_run_disabled_tests"
  Test #198: testMyClass.MyClass.SpeedTest (Disabled)

Total Tests: 1

然后复制并粘贴测试命令:

/home/me/build/test/testMyClass "--gtest_filter=MyTest.DISABLED_SpeedTest" "--gtest_also_run_disabled_tests"
© www.soinside.com 2019 - 2024. All rights reserved.