使用 gcov 进行共享库覆盖率测试 [Linux/Fortran]

发布于 2024-10-19 08:54:32 字数 513 浏览 9 评论 0原文

我正在尝试执行共享库的覆盖率测试。我选择 gcov/lcov 是因为它是免费和开源的,这意味着我可以立即尝试它(商业软件需要批准/购买,必须做出很多决定 - 它花费时间)。

情况如下 - 库 - 我们用 Fortran 编写的产品然后用于仿真软件(具体来说,来自 MSC.Software 的 ADAMS)。我可以使用 -fprofile-arcs -ftest-coverage 编译该库,如果 ADAMS 使用它,它可以正常工作。但是,不会创建 .gcda 文件。

有一个小的测试可执行文件来测试库的基本行为(方法的小子集)。如果我使用覆盖率测试开关编译此可执行文件,我会获得可执行文件本身和库的 .gcda 文件。

问题是:如果使用该库的可执行文件未使用覆盖率测试开关编译,是否可以调用该库的 gcov 测量?如果可以,如何调用?

可以编写大量测试,但这几乎就像复制 ADAMS(或任何其他模拟包)一样。或者我选择了错误的覆盖测试工具,我应该转向商业产品?

先感谢您。

麦克风

I am trying to perform a coverage test of a shared library. I have chosen for gcov/lcov due to the fact, that it is free and open source, which means, I can try it immediately (commercial software would need to be approved/purchased, a lot of decision would have to be made - it costs time).

The situation is as follows - the library - our product, written in Fortran is then used for simulation software (ADAMS from MSC.Software, to be specific). I can compile the library with -fprofile-arcs -ftest-coverage and it works properly if used by ADAMS. However, no .gcda files are created.

There is a small test executable to test basic behaviour of the library (small subset of the methods). If I compile this executable with coverage tests switches, I get .gcda files for both the executable itself and the library.

The question is: is it possible to invoke gcov measurements for the library if the executable using the library was not compiled with coverage test switches? And if yes, how?

It is possible to write extensive test, but it will be almost like replicating ADAMS (or any other simulation package). Or have I chosen wrong coverage test tool and I should move to commercial products?

Thank you in advance.

Mike

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫轩蝶泪 2024-10-26 08:54:32

看起来,专有软件调用的库的代码覆盖率测试没有任何问题。只需注意使用相同版本的编译器编译所有组件并使用相应的 gcov 版本即可。
就我而言,库(Fortran 语言)是用 f77 (gcc-3.4.6) 编译的,它的组件是用最新的 gcc (gcc-4.4) 编译的。 ADAMS 使用的库的包装器再次使用 gcc-3.4.6 进行编译,使用的 gcov 是 4.1。

对所有组件使用 gcc-3.4.6 提供了非常有吸引力的代码覆盖率测试结果。

考虑到这个话题已经结束,但如果有人有疑问,请询问。我很乐意分享我的经验。

It seems, there isn't any problem with code coverage test of the library that is invoked by proprietary software. One should only pay attention to compile all components with the same version of the compiler and use corresponding gcov version.
In my case the library (in Fortran) was compiled with f77 (gcc-3.4.6), the component of it was compiled with newest gcc (gcc-4.4). The wrapper for the library used by ADAMS was compiled again with gcc-3.4.6 and gcov used was 4.1.

Using gcc-3.4.6 for all components delivered very appealing code coverage test results.

Consider the topic closed, but should anyone have questions, please ask. I'll gladly share my experience.

梦在深巷 2024-10-26 08:54:32

我编译程序的方式通常是为所有模块的编译器提供完全相同的开关,所以,不,我不知道当可执行文件未使用覆盖开关编译时是否可以让 gcov 工作。

但是,我接下来要做的是对 gcov 的输出文件进行后处理,仅忽略与测试代码相关的文件,但保留与测试代码直接调用的代码以及调用的库代码相关的所有文件靠它自己。

The way I compile my programs is usually to supply exactly the same switches to the compiler for ALL modules, so, no, I don't know if its possible to get gcov working when the executable was not compiled with the coverage switches.

However, what I then do is to post-process the output files from gcov, ignoring files relating to test code only, but keeping all files relating to code directly called by test code as well as library code called by itself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文