How do I make ctest run a program with valgrind without dart?

后端 未结 4 2056
生来不讨喜
生来不讨喜 2021-01-31 09:16

I want to write a CMakeLists.txt so that I can run my tests normally or with valgrind. I have seen much on integrating ctest with valgrind but all with the assumption that you w

4条回答
  •  醉梦人生
    2021-01-31 10:20

    You can generate a minimal 'DartConfiguration.tcl' configuration file using add_custom_target(). Then you can add a valgrind custom target that calls ctest with the appropriate args. This is how I usually do it:

    find_program(VALGRIND "valgrind")
    if (VALGRIND)
        set(DART_CONFIG DartConfiguration.tcl)
        add_custom_target(${DART_CONFIG}
            COMMAND echo "MemoryCheckCommand: ${VALGRIND}" >> ${DART_CONFIG}
            COMMENT "Generating ${DART_CONFIG}"
        )
        set(VALGRIND_ARGS
            --leak-check=full
            --error-exitcode=255
        )
        set(LOGFILE memcheck.log)
        add_custom_target(valgrind        
            COMMAND ctest -O ${LOGFILE} -D ExperimentalMemCheck --overwrite MemoryCheckCommandOptions="${VALGRIND_ARGS}"
            COMMAND tail -n1 ${LOGFILE} | grep 'Memory checking results:' > /dev/null
            COMMAND rm -f ${LOGFILE}
            DEPENDS ${DART_CONFIG}
        )
    endif()
    

    Hope this helps! :-)

    Credit: https://github.com/ARMmbed/mbedtls/blob/development/CMakeLists.txt#L237

提交回复
热议问题