XCode 5.1单元测试覆盖率分析对使用块的文件失败 [英] XCode 5.1 Unit Test Coverage Analysis Fails On Files Using Blocks

查看:208
本文介绍了XCode 5.1单元测试覆盖率分析对使用块的文件失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我的任务是将单元测试覆盖率分析添加到我们的代码库中.今天也是iOS 7.1与XCode 5.1一起发布的日子.从发行说明中:

Today I was tasked with adding unit test coverage analysis to our code base. Today is also the day iOS 7.1 is released along with XCode 5.1. From the release notes:

用于代码覆盖率测试的gcov工具已重新实现.新版本使用LLVM项目中的llvm-cov工具.对于所有重要功能,它在功能上均等效于旧版本. Xcode中gcov的位置也已移动,请使用xcrun调用它.如果发现问题,请提交错误报告.对于此发行版,您仍然可以使用GCC的gcov的旧版本,该版本可以作为gcov-4.2获得. 11919694更新

The gcov tool for code coverage testing has been reimplemented. The new version uses the llvm-cov tool from the LLVM project. It is functionally equivalent to the old version for all significant features. The location of gcov within Xcode has also moved, use xcrun to invoke it. If you find problems, please file bug reports. For this release, you can still use the old version of gcov from GCC, which is available as gcov-4.2. 11919694 updated

仅在遵循了几条说明后,我才意识到这一点 a> 博客 此处尝试将其解析为报告. (这是一个./getcov脚本,该脚本收集您的环境变量以传递给lcov-1.10脚本以生成报告)

I realized this only after following several instructional blog posts, getting my environment set up properly - generating .gcda/.gcno files in the simulator's build folders upon testing - and having the report generating tools here try to parse them into a report. (that is a ./getcov script which gathers your environment variables to pass to lcov-1.10 scripts to generate the report)

第一个障碍是新捆绑的gcov程序不支持-v参数来获取版本,这是lcov初始化的第一步.看起来像是一个初学者,但是阅读上面的发行说明后,我修改了lcov脚本以使用旧的gcov-4.2版本,并解决了该问题.

The first hurdle was that the new bundled gcov program doesn't support the -v argument to get the version, which is the first step of lcov's initialization. Seemed like a non-starter already, but reading the release notes above I modified the lcov script to use the old gcov-4.2 version and got that solved.

但是,lcov在处理我的coverage数据文件时很早就出错了.这样就生成了一个报告,其中可能包含我项目中按字母顺序排列的前10个左右文件.不是特别有用.错误输出很小,也无济于事:

However, lcov errored out very early in processing my coverage data files. This generated a report with maybe the first 10 or so files alphabetically in my project. Not particularly useful. The error output was minimal and unhelpful as well:

geninfo:错误:(build_artifacts)/(class_that_errored).gcda的GCOV失败!

geninfo: ERROR: GCOV failed for (build_artifacts)/(class_that_errored).gcda!

我修改了lcov脚本以打印所得到的错误(不幸的是,仅产生11,在gcov(-io).c代码中找不到任何引用),并继续操作而不是退出,因此报告中剩下的文件很多,但仍然有85%的源文件都出现了上述错误.

I modified the lcov script to print the error it was getting (which only yielded 11 unfortunately, couldn't find any reference in the gcov(-io).c code) and to continue operation instead of quitting, so I was left with a lot more files in the report, but still probably 85% of my source files had errored out as above.

我能辨别在报告中成功整理的文件和引发错误的文件的唯一模式是,任何使用嵌入式块声明的文件都失败了.传递的文件都没有以任何方式使用块,而我检查过的所有失败的文件都不包含块.奇怪.

The only pattern I could discern between the files that successfully wound up in the report and the ones that threw an error was that any file that used an in-line block declaration failed. None of the files that passed used blocks in any fashion, and all the files I've checked that failed contain blocks. Strange.

然后我发现我可以在 CoverStory 中打开各个.gcda文件,包括那些错误输入lcov脚本.在覆盖率报告下方的消息窗口中,所有出错的文件均带有警告消息:

Then I figured out I could open the individual .gcda files in CoverStory, including the ones that had errored in the lcov script. In the message window beneath the coverage report, all the files that had errored had the warning messages:

(class_that_errored).gcno:"__ copy_helper_block_"没有行

(class_that_errored).gcno:no lines for '__copy_helper_block_'

(class_that_errored).gcno:"__ destroy_helper_block_"没有行

(class_that_errored).gcno:no lines for '__destroy_helper_block_'

在这一点上,我最好的假设是新的XCode 5.1正在生成.gcda文件,而旧的gcov-4.2程序无法处理该文件.

My best hypothesis at this point is that the new XCode 5.1 is generating .gcda files that the old gcov-4.2 program isn't equipped to deal with regarding block declarations.

但是我已经尽力尝试了所有尝试,因此我在这里问是否有人了解我所缺少的知识,或者是否有任何想法可以进一步进行调试.或者,如果自从今天的XCode 5.1用新的gcov更新以来,已经有人成功地测量了测试的覆盖率,我很想知道您也必须进行任何更改.

But I've exhausted everything I can think to try, so I'm here to ask if anybody has a piece of knowledge that I've missed, or has any ideas to further the debugging effort. Or if anyone is successfully measuring test coverage since today's XCode 5.1 update with the new gcov, I'd love to hear about any changes you had to make as well.

推荐答案

问题出在LCOV 1.10 geninfo 脚本中.它测试gcov的当前版本.它通过解析版本字符串来做到这一点.由于gcov现在指向llvm-cov,因此版本字符串解析不正确.

The problem is in the LCOV 1.10 geninfo script. It tests for the current version of gcov. It does this by parsing the version string. Since gcov now points to llvm-cov, the version string is parsed incorrectly.

解决方案是修改 geninfo 的get_gcov_version()子例程.在 1868 行中,将-v更改为--version.然后将行 1874 替换为:

The solution is to modify geninfo’s get_gcov_version() subroutine. In line 1868, change -v to --version. Then replace line 1874 with:

if ($version_string =~ m/LLVM/)
{
    info("Found llvm-cov\n");
    $result = 0x40201;
}
elsif ($version_string =~ /(\d+)\.(\d+)(\.(\d+))?/)

 

修改后的子例程应如下所示:

The modified subroutine should look like this:

sub get_gcov_version()
{
    local *HANDLE;
    my $version_string;
    my $result;

    open(GCOV_PIPE, "-|", "$gcov_tool --version")
        or die("ERROR: cannot retrieve gcov version!\n");
    $version_string = <GCOV_PIPE>;
    close(GCOV_PIPE);

    $result = 0;
    if ($version_string =~ m/LLVM/)
    {
        info("Found llvm-cov\n");
        $result = 0x40201;
    }
    elsif ($version_string =~ /(\d+)\.(\d+)(\.(\d+))?/)
    {
        if (defined($4))
        {
            info("Found gcov version: $1.$2.$4\n");
            $result = $1 << 16 | $2 << 8 | $4;
        }
        else
        {
            info("Found gcov version: $1.$2\n");
            $result = $1 << 16 | $2 << 8;
        }
    }
    return ($result, $version_string);
}

 

 

注意::确保--gcov-tool设置为gcov-4.2.

这篇关于XCode 5.1单元测试覆盖率分析对使用块的文件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆