本文介绍了如何使用ctest将参数传递给memcheck?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从命令行使用ctest通过memcheck运行我的测试,并为memcheck命令传递参数.

I want to use ctest from the command line to run my tests with memcheck and pass in arguments for the memcheck command.

我可以运行ctest -R my_test来运行测试,甚至可以运行ctest -R my_test -T memcheck来通过memcheck运行它.

I can run ctest -R my_test to run my test, and I can even run ctest -R my_test -T memcheck to run it through memcheck.

但是我似乎找不到找到将参数传递给该memcheck命令的方法,例如--leak-check=full--suppressions=/path/to/file.

But I can't seem to find a way to pass arguments to that memcheck command, like --leak-check=full or --suppressions=/path/to/file.

阅读ctest的文档后,我尝试将-D选项与CTEST_MEMCHECK_COMMAND_OPTIONSMEMCHECK_COMMAND_OPTIONS结合使用.我还尝试将这些设置为环境变量.我的尝试均未产生任何不同的测试命令.总是这样:

After reading ctest's documentation I've tried using the -D option with CTEST_MEMCHECK_COMMAND_OPTIONS and MEMCHECK_COMMAND_OPTIONS. I also tried setting these as environment variables. None of my attempts produced any different test command. It's always:

Memory check command: /path/to/valgrind "--log-file=/path/to/build/Testing/Temporary/MemoryChecker.7.log" "-q" "--tool=memcheck" "--leak-check=yes" "--show-reachable=yes" "--num-callers=50"

如何从ctest命令行控制memcheck命令?

How can I control the memcheck command from the ctest command line?

推荐答案

TL; DR

ctest --overwrite MemoryCheckCommandOptions="--leak-check=full --error-exitcode=100" \
      --overwrite MemoryCheckSuppressionFile=/path/to/valgrind.suppressions \
      -T memcheck

说明

我终于找到了覆盖此类变量的正确方法,但是不幸的是,从文档中理解这一点并不容易.因此,为了帮助需要处理的下一个可怜的灵魂,这是我对memcheck设置选项的各种方式的理解.

Explanation

I finally found the right way to override such variables, but unfortunately it's not easy to understand this from the documentation.So, to help the next poor soul that needs to deal with this, here is my understanding of the various ways to set options for memcheck.

在顶级源目录的CTestConfig.cmake中或在CMakeLists.txt(调用include(CTest)之前)中,可以设置MEMORCHECK_COMMAND_OPTIONSMEMORYCHECK_SUPPRESSIONS_FILE.当您include(CTest)时,CMake将在您的构建目录中生成一个DartConfiguration.tcl,并且设置上述变量将分别在该文件中填充MemoryCheckCommandOptionsMemoryCheckSuppressionFile.这是ctest在构建目录中解析的文件,以填充其内部变量以运行memcheck步骤.因此,如果要在cmake配置期间设置项目的memcheck选项,这就是获得方法.

In a CTestConfig.cmake in you top-level source dir, or in a CMakeLists.txt (before calling include(CTest)), you can set MEMORCHECK_COMMAND_OPTIONS or MEMORYCHECK_SUPPRESSIONS_FILE.When you include(CTest), CMake will generate a DartConfiguration.tcl in your build directory and setting the aforementioned variables will populate MemoryCheckCommandOptions and MemoryCheckSuppressionFile respectively in this file.This is the file that ctest parses in your build directory to populate it's internal variables for running the memcheck step.So, if you'd like to set you project's options for memcheck during cmake configuration, this is the way to got.

相反,如果您想在已经正确配置了构建目录之后修改这些选项,则可以:

If instead you'd like to modify these options after you already have a properly configured build directory, you can:

  1. 直接修改DartConfiguration.tcl,但请注意,如果再次运行cmake,此内容将被覆盖,因为每次cmake运行时都会重新生成此文件.
  2. 使用ctest --overwrite命令行选项仅针对该运行设置这些memcheck选项.
  1. Modify the DartConfiguration.tcl directly, but note that this will be overwritten if cmake runs again, since this file is regenerated each time cmake runs.
  2. Use the ctest --overwrite command-line option to set these memcheck options just for that run.

注释

  1. 我在线上看到了CMAKE_MEMORYCHECK_COMMAND_OPTIONS变量的内容.我不知道这个变量是什么,我不认为cmake会以任何方式知道它.
  2. 设置CTEST_MEMORYCHECK_COMMAND_OPTIONS(实际上是已记录的变量在CTestConfig.cmakeCMakeLists.txt中的cmake文档中)无效.看来此变量仅在"CTest客户脚本" ,我从未使用过.
  3. 不幸的是,MEMORCHECK_COMMAND_OPTIONSMEMORYCHECK_SUPPRESSIONS_FILE都没有在 cmake ,仅间接地在 ctest 文档和使用CTest进行测试教程.
  1. I've seen mentions online of a CMAKE_MEMORYCHECK_COMMAND_OPTIONS variable. I have no idea what this variable is and I don't think cmake is aware of it in any way.
  2. Setting CTEST_MEMORYCHECK_COMMAND_OPTIONS (the variable that is actually documented in the cmake docs) in your CTestConfig.cmake or CMakeLists.txt has no effect. It seems this variable only works in "CTest Client Scripts", which I have never used.
  3. Unfortunately, both MEMORCHECK_COMMAND_OPTIONS and MEMORYCHECK_SUPPRESSIONS_FILE aren't documented explicitly in cmake, only indirectly, in ctest documentation and the Testing With CTest tutorial.

在构建中运行ctest时,它将解析文件以填充内部变量: https://cmake.org/cmake/help/latest/manual/ctest.1.html#dashboard-client-via-ctest-command-line 我不清楚它如何与

When ctest is run in the build, it parses the file to populate internal variables:https://cmake.org/cmake/help/latest/manual/ctest.1.html#dashboard-client-via-ctest-command-lineIt's not clear to me how this interacts with

这篇关于如何使用ctest将参数传递给memcheck?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 16:38