如何在已安装的 Cocoa 应用程序上运行 Gcov?
我有一个使用安装程序的 Cocoa 应用程序。我希望能够对代码运行代码覆盖率(在安装之后)。
这不是通常的单元测试场景,在通常的单元测试场景中,单个二进制文件将运行一组测试。相反,相关测试将在运行时与 UI 和应用程序后端进行交互,因此我理想情况下希望能够启动应用程序,知道 Gcov 正在对其进行分析,然后针对它运行测试。
有什么想法吗?
更新
感谢mustISignUp。为了澄清我问这个问题的原因:
我犯的错误是认为对象、.gcno 和 .gcda 文件必须与二进制文件一起安装(从而使安装程序变得困难)。碰巧的是,文件的原始位置与检测代码一起硬连接到代码中。
我采用的解决方案是将构建机器上的代码压缩并将其放在测试机器上的磁盘上。可以从那里运行 lcov
(或只是 gcov
)。或者,.gcda 文件将在磁盘上创建,并且必须将它们复制回包含源代码的计算机。
不管怎样,源代码不必在安装和运行时出现,但如果您想以 lcov 方式返回结果,则生成的覆盖计数器文件必须与源代码一致。
I have a Cocoa application which uses an installer. 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.
Any ideas?
Update
Thanks to 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). 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. Alternatively, the .gcda files will be created on disk and they must be copied back up to the machine containing the source code.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该应用程序需要使用正确的 GCC 标志进行编译,这会将分析指令插入到代码中。它不是你可以打开和关闭的东西。即您的代码在编译时被修改以输出覆盖率信息。
因此,如果您使用正确的标志编译应用程序,它将发出覆盖数据,如果没有,则不会(并且您肯定不希望它用于要分发的应用程序)。
The app needs to be compiled with the correct GCC flags which will insert the profiling instructions into the code. It isn't something you can turn on and off. ie your code is modified at compile time to output the coverage info.
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).