赞
踩
在做前端精准测试的时候,对于iOS端,通常会做如下操作:
(1)合并覆盖率数据
如下操作:
xcrun llvm-profdata merge coverage_file1657885040728.profraw coverage_file1657885829980.profraw test.profraw -output merged.profraw
(2)翻译覆盖率数据
xcrun llvm-profdata merge -sparse test.profraw -o test.profdata
(3)生成info文件
xcrun llvm-cov export ./shoppingCart --instr-profile=test.profdata -use-color --format=lcov > ./newreport.info
(4)生成html报告
./lcov-1.14/bin/genhtml -o html ./newreport.info
其中这个info文件非常重要,我们可以根据需求的diff代码,对其进行过滤,进行生成增量报告。同时在合并覆盖率报告的时候,也会处理这个info文件。但是在网上很难找到完整的info文件信息解读,经过我多方查找,不断测试,总结出info文件各个信息段的含义。
一个Swift 项目的覆盖率报告Info文件,具体的内容如下:
- SF:/Users/sxf/Documents/精准测试/KimCode/iOSSDKInject/kim-ios/packages/kim-ios/Kim/DataHelper/KImPinYin.swift
- FN:16,$s4Kima9KimPinYinC7preloadyyFZ
- FN:20,$s4Kima9KimPinYinCACycfc
- FN:24,$s4Kima9KimPinYinCfD
- FN:28,$s4Kima9KimPinYinC12pinyinLoadedyyF
- FN:33,$s4Kima9KimPinYinC7convertyS2SF
- FN:42,$sSa4Kima8KimModel0B12SelectMemberCRszlE23sortByDisplayNamePinyinSayADGyF
- FN:49,$sSa4Kima8KimModel0B12SelectMemberCRszlE23sortByDisplayNamePinyinSayADGyFSbSS_Sit_SS_SittXEfU_
- FN:52,$sSa4Kima8KimModel0B12SelectMemberCRszlE23sortByDisplayNamePinyinSayADGyFADSgSS_SitXEfU0_
- FN:60,$sSa4Kima8KimModel0B4UserVRszlE23sortByDisplayNamePinyinSayADGyF
- FN:67,$sSa4Kima8KimModel0B4UserVRszlE23sortByDisplayNamePinyinSayADGyFSbSS_Sit_SS_SittXEfU_
- FN:70,$sSa4Kima8KimModel0B4UserVRszlE23sortByDisplayNamePinyinSayADGyFADSgSS_SitXEfU0_
- FN:78,$sSa4Kima8KimModel0b18GroupMemberContactC0CRszlE23sortByDisplayNamePinyin15moveAdminToFistSayADGSb_tF
- FN:85,$sSa4Kima8KimModel0b18GroupMemberContactC0CRszlE23sortByDisplayNamePinyin15moveAdminToFistSayADGSb_tFSbSS_Sit_SS_SittXEfU_
- FN:88,$sSa4Kima8KimModel0b18GroupMemberContactC0CRszlE23sortByDisplayNamePinyin15moveAdminToFistSayADGSb_tFADSgSS_SitXEfU0_
- FNDA:2,$s4Kima9KimPinYinC7preloadyyFZ
- FNDA:0,$s4Kima9KimPinYinCACycfc
- FNDA:0,$s4Kima9KimPinYinCfD
- FNDA:0,$s4Kima9KimPinYinC12pinyinLoadedyyF
- FNDA:0,$s4Kima9KimPinYinC7convertyS2SF
- FNDA:0,$sSa4Kima8KimModel0B12SelectMemberCRszlE23sortByDisplayNamePinyinSayADGyF
- FNDA:0,$sSa4Kima8KimModel0B12SelectMemberCRszlE23sortByDisplayNamePinyinSayADGyFSbSS_Sit_SS_SittXEfU_
- FNDA:0,$sSa4Kima8KimModel0B12SelectMemberCRszlE23sortByDisplayNamePinyinSayADGyFADSgSS_SitXEfU0_
- FNDA:0,$sSa4Kima8KimModel0B4UserVRszlE23sortByDisplayNamePinyinSayADGyF
- FNDA:0,$sSa4Kima8KimModel0B4UserVRszlE23sortByDisplayNamePinyinSayADGyFSbSS_Sit_SS_SittXEfU_
- FNDA:0,$sSa4Kima8KimModel0B4UserVRszlE23sortByDisplayNamePinyinSayADGyFADSgSS_SitXEfU0_
- FNDA:0,$sSa4Kima8KimModel0b18GroupMemberContactC0CRszlE23sortByDisplayNamePinyin15moveAdminToFistSayADGSb_tF
- FNDA:0,$sSa4Kima8KimModel0b18GroupMemberContactC0CRszlE23sortByDisplayNamePinyin15moveAdminToFistSayADGSb_tFSbSS_Sit_SS_SittXEfU_
- FNDA:0,$sSa4Kima8KimModel0b18GroupMemberContactC0CRszlE23sortByDisplayNamePinyin15moveAdminToFistSayADGSb_tFADSgSS_SitXEfU0_
- FNF:14
- FNH:1
- DA:16,2
- DA:17,2
- DA:18,2
- DA:20,0
- DA:21,0
- DA:22,0
- DA:23,0
- DA:24,0
- DA:25,0
- DA:26,0
- DA:28,0
- DA:29,0
- DA:30,0
- DA:31,0
- DA:33,0
- DA:34,0
- DA:35,0
- DA:36,0
- DA:37,0
- DA:38,0
- DA:42,0
- DA:43,0
- DA:44,0
- DA:45,0
- DA:46,0
- DA:47,0
- DA:48,0
- DA:49,0
- DA:50,0
- DA:51,0
- DA:52,0
- DA:53,0
- DA:54,0
- DA:55,0
- DA:56,0
- DA:60,0
- DA:61,0
- DA:62,0
- DA:63,0
- DA:64,0
- DA:65,0
- DA:66,0
- DA:67,0
- DA:68,0
- DA:69,0
- DA:70,0
- DA:71,0
- DA:72,0
- DA:73,0
- DA:74,0
- DA:78,0
- DA:79,0
- DA:80,0
- DA:81,0
- DA:82,0
- DA:83,0
- DA:84,0
- DA:85,0
- DA:86,0
- DA:87,0
- DA:88,0
- DA:89,0
- DA:90,0
- DA:91,0
- DA:92,0
- DA:93,0
- DA:94,0
- DA:95,0
- DA:96,0
- DA:97,0
- DA:98,0
- DA:99,0
- DA:100,0
- BRF:0
- BRH:0
- LF:91
- LH:3
- end_of_record
文件中有多个这样的数据块组成,现在需要对这个数据块进行分析,以便进行跨版本的覆盖率合并。但是,从网上搜索相关介绍的时候,几乎是没有的。于是我们只能借助于其他的数据进行比对,比如说,生成html报告,使用如下命令:
xcrun llvm-cov show ./Kima --instr-profile=./commitA/coverage_mergedA.profdata --format=html -use-color --output-dir=./commitA/checkreport
打开报告,内容如下:
然后对照着这两份数据,就可以大概了解一下相关的内容了:
(1)类相关的信息
- SF:/Users/sxf/Documents/精准测试/KimCode/iOSSDKInject/kim-ios/packages/kim-ios/Kim/DataHelper/KImPinYin.swift
- FN:16,$s4Kima9KimPinYinC7preloadyyFZ
- FN:20,$s4Kima9KimPinYinCACycfc
- FN:24,$s4Kima9KimPinYinCfD
- FN:28,$s4Kima9KimPinYinC12pinyinLoadedyyF
- FN:33,$s4Kima9KimPinYinC7convertyS2SF
- FN:42,$sSa4Kima8KimModel0B12SelectMemberCRszlE23sortByDisplayNamePinyinSayADGyF
- FN:49,$sSa4Kima8KimModel0B12SelectMemberCRszlE23sortByDisplayNamePinyinSayADGyFSbSS_Sit_SS_SittXEfU_
- FN:52,$sSa4Kima8KimModel0B12SelectMemberCRszlE23sortByDisplayNamePinyinSayADGyFADSgSS_SitXEfU0_
- FN:60,$sSa4Kima8KimModel0B4UserVRszlE23sortByDisplayNamePinyinSayADGyF
- FN:67,$sSa4Kima8KimModel0B4UserVRszlE23sortByDisplayNamePinyinSayADGyFSbSS_Sit_SS_SittXEfU_
- FN:70,$sSa4Kima8KimModel0B4UserVRszlE23sortByDisplayNamePinyinSayADGyFADSgSS_SitXEfU0_
- FN:78,$sSa4Kima8KimModel0b18GroupMemberContactC0CRszlE23sortByDisplayNamePinyin15moveAdminToFistSayADGSb_tF
- FN:85,$sSa4Kima8KimModel0b18GroupMemberContactC0CRszlE23sortByDisplayNamePinyin15moveAdminToFistSayADGSb_tFSbSS_Sit_SS_SittXEfU_
- FN:88,$sSa4Kima8KimModel0b18GroupMemberContactC0CRszlE23sortByDisplayNamePinyin15moveAdminToFistSayADGSb_tFADSgSS_SitXEfU0_
- FNDA:2,$s4Kima9KimPinYinC7preloadyyFZ
- FNDA:0,$s4Kima9KimPinYinCACycfc
- FNDA:0,$s4Kima9KimPinYinCfD
- FNDA:0,$s4Kima9KimPinYinC12pinyinLoadedyyF
- FNDA:0,$s4Kima9KimPinYinC7convertyS2SF
- FNDA:0,$sSa4Kima8KimModel0B12SelectMemberCRszlE23sortByDisplayNamePinyinSayADGyF
- FNDA:0,$sSa4Kima8KimModel0B12SelectMemberCRszlE23sortByDisplayNamePinyinSayADGyFSbSS_Sit_SS_SittXEfU_
- FNDA:0,$sSa4Kima8KimModel0B12SelectMemberCRszlE23sortByDisplayNamePinyinSayADGyFADSgSS_SitXEfU0_
- FNDA:0,$sSa4Kima8KimModel0B4UserVRszlE23sortByDisplayNamePinyinSayADGyF
- FNDA:0,$sSa4Kima8KimModel0B4UserVRszlE23sortByDisplayNamePinyinSayADGyFSbSS_Sit_SS_SittXEfU_
- FNDA:0,$sSa4Kima8KimModel0B4UserVRszlE23sortByDisplayNamePinyinSayADGyFADSgSS_SitXEfU0_
- FNDA:0,$sSa4Kima8KimModel0b18GroupMemberContactC0CRszlE23sortByDisplayNamePinyin15moveAdminToFistSayADGSb_tF
- FNDA:0,$sSa4Kima8KimModel0b18GroupMemberContactC0CRszlE23sortByDisplayNamePinyin15moveAdminToFistSayADGSb_tFSbSS_Sit_SS_SittXEfU_
- FNDA:0,$sSa4Kima8KimModel0b18GroupMemberContactC0CRszlE23sortByDisplayNamePinyin15moveAdminToFistSayADGSb_tFADSgSS_SitXEfU0_
- FN:16,$s4Kima9KimPinYinC7preloadyyFZ
FN:代表方法
16:代表开始行号
后面的是方法名以及模块相关的信息。
FNDA:2,$s4Kima9KimPinYinC7preloadyyFZ
FNDA:代码方法的覆盖情况
2:代表方法中的代码可能执行的次数,但不一定是所有的行都执行了,需要具体分析;
后面的是方法信息,与FN相照应。
(2)方法覆盖率信息
FNF:14 FNH:1
通过对比html报告,可以看出:
FNF:代码这个文件中的总方法数;
FNH:为覆盖的方法数
而我们合并覆盖率报告的时候,可以先对比一下总方法数是否一样,如果相同,再去考虑如何处理覆盖的方法数;如果不同,则选择最新版本的方法数;
(3)行覆盖率信息
LF:91 LH:3
LF: 代码这个文件的总行数,总行数以最新的版本为准;
LH:为覆盖的行数,合并覆盖率后,需要统计一下合并后的覆盖行号,更新一下这个数;
(4)分支覆盖
BRF:0 BRH:0
BRF:为总分支数
BRH:为覆盖的分支数,一般的Swift文件都是0
在跨版本覆盖率报告合并的时候,早期就是通过处理两个info文件的不断源码文件覆盖率数据进行合并的,这个方法也适合更加精细化的合并策略,比如行级别的覆盖率处理等。
后来又找到了快速的合并方法lcov -a参数进行合并。
通过两次详细搜索,合并方法如下
lcov -a test1.info -a test2.info -o allreport.info
经过验证,合并结果达到了预期.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。