如何在Linux平台上使用C ++中的gTest检测内存泄漏

时间:2022-06-06 09:00:51

I am new to gTest. I have to load of functions for which I already have the gTest unit test cases.

我是gTest的新手。我必须加载已经有gTest单元测试用例的函数。

I want to add functionality to detect memory leaks in my orginal functions inside the unit test cases already exist.

我想添加功能来检测我已经存在的单元测试用例中的原始函数中的内存泄漏。

Is there a way to perform this?

有办法执行此操作吗?

Regards, Mahendra

1 个解决方案

#1


1  

Googletest is not the sort of a tool for detecting memory leaks. Unit-testing tests the run-time functionality of software elements. Detecting memory leaks in a compiled application calls for dynamic analysis of its execution at binary level in conjunction with debugging information generated by the compiler and linker.

Googletest不是一种检测内存泄漏的工具。单元测试测试软件元素的运行时功能。检测已编译应用程序中的内存泄漏需要动态分析其在二进制级别的执行以及编译器和链接器生成的调试信息。

There are tools for detecting memory leaks, to be used independently of your unit-testing framework. For Linux, a commonplace choice is Valgrind. It will be provided in the package repositories of your distro and you will be able to install it with your package manager. If you use an IDE it may well support Valgrind integration via a plugin or other means.

有一些用于检测内存泄漏的工具,可以独立于您的单元测试框架使用。对于Linux,一个常见的选择是Valgrind。它将在您的发行版的软件包存储库中提供,您可以使用软件包管理器进行安装。如果您使用IDE,它可能会通过插件或其他方式支持Valgrind集成。

#1


1  

Googletest is not the sort of a tool for detecting memory leaks. Unit-testing tests the run-time functionality of software elements. Detecting memory leaks in a compiled application calls for dynamic analysis of its execution at binary level in conjunction with debugging information generated by the compiler and linker.

Googletest不是一种检测内存泄漏的工具。单元测试测试软件元素的运行时功能。检测已编译应用程序中的内存泄漏需要动态分析其在二进制级别的执行以及编译器和链接器生成的调试信息。

There are tools for detecting memory leaks, to be used independently of your unit-testing framework. For Linux, a commonplace choice is Valgrind. It will be provided in the package repositories of your distro and you will be able to install it with your package manager. If you use an IDE it may well support Valgrind integration via a plugin or other means.

有一些用于检测内存泄漏的工具,可以独立于您的单元测试框架使用。对于Linux,一个常见的选择是Valgrind。它将在您的发行版的软件包存储库中提供,您可以使用软件包管理器进行安装。如果您使用IDE,它可能会通过插件或其他方式支持Valgrind集成。