简体   繁体   English

如何在已安装的Cocoa应用程序上运行Gcov?

[英]How can I run Gcov over an installed Cocoa application?

I have a Cocoa application which uses an installer. 我有一个使用安装程序的Cocoa应用程序。 I want to be able to run code coverage over the code (after it has been installed). 我希望能够在代码上运行代码覆盖率(安装后)。

This is not the usual unit-test scenario where a single binary will run a suite of tests. 这不是通常的单元测试方案,其中单个二进制文件将运行一组测试。 Rather, the tests in question will interact with the UI and the app back-end whilst it is running, so I ideally want to be able to start the application knowing that Gcov is profiling it and then run tests against it. 相反,有问题的测试将在运行时与UI和应用程序后端交互,因此,理想情况下,我希望能够在知道Gcov对它进行性能分析的情况下启动应用程序,然后对其进行测试。

Any ideas? 有任何想法吗?

Update 更新资料

Thanks to mustISignUp. 感谢mustISignUp。 To clarify why I asked the question: 为了澄清为什么我问这个问题:

The mistake I made was thinking that the object, .gcno and .gcda files had to be installed alongside the binaries (thus making the installer difficult). 我犯的错误是认为对象,.gcno和.gcda文件必须与二进制文件一起安装(因此使安装程序很困难)。 As it happens, the original location of the files is hard-wired into the code along with the instrumentation code. 碰巧的是,文件的原始位置与检测代码一起硬连接到代码中。

The solution I went with is zipping up the code on the build machine and putting it on disk on the test machine. 我使用的解决方案是将代码压缩在构建计算机上,然后将其放在测试计算机的磁盘上。 lcov (or just gcov ) can be run from there. lcov (或只是gcov )可以从那里运行。 Alternatively, the .gcda files will be created on disk and they must be copied back up to the machine containing the source code. 或者,.gcda文件将在磁盘上创建,并且必须将它们复制回到包含源代码的计算机上。

Either way, the source code doesn't have to be present at install and run time, but if you want to get your results back lcov-style, the coverage counter files produced must be reconciled with the source code. 无论哪种方式,都不必在安装和运行时提供源代码,但是如果您想将结果恢复为lcov风格,则必须将生成的coverage计数器文件与源代码进行协调。

The app needs to be compiled with the correct GCC flags which will insert the profiling instructions into the code. 该应用程序需要使用正确的GCC标志进行编译,这些标志会将性能分析指令插入代码中。 It isn't something you can turn on and off. 您不能打开和关闭它。 ie your code is modified at compile time to output the coverage info. 即您的代码在编译时被修改以输出coverage信息。

So, if you compiled the app with the correct flags it will emit coverage data, if you didn't, it won't (and you certainly wouldn't want it to for an app you were going to distribute). 因此,如果您使用正确的标志编译应用程序,它将发出覆盖率数据,如果没有,则不会发出覆盖率数据(并且您当然不希望将其分发给要分发的应用程序)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM