Obotcha已经写了快4年的,大约有44K行,4K个接口。对应的单元测试集(GitHub - wangsun1983/ObotchaTestSuite)目前已经基本涵盖了大多数的模块,但是一直没办法确定有多少接口没有被测到。所以写了个简单的python脚本去做了一个统计。方法如下:
1.首先通过Objdump解析libobothca.so(obotcha的编译输出),获得所有obotcha的接口数据,存入functionMap中。
def analyseObjdump():
for line in fileinput.input("../Report/CoverageReport/obotchadump.txt"):
if line.find("g ") > 0 and line.find("obotcha") >0 and line.find(".text") > 0:
#print(line)
index = line.rfind(" ")
function = line[index+1:len(line) - 1]
#print("add function [",function,"]")
functionMap[function] = 1
2.在ObotchaTestSuit中,逐个文件夹编译,
然后用objdump去解析编译产物(一般就是测试的bin)
3.将步骤2中统计到的obotcha接口函数从mapA中移除
def scan(path):
print("path is ",path)
isMakeFileExist = False
for filename in os.listdir(path):
if filename == "makefile":
print("i find makefile:",path)
isMakeFileExist = True
break
print("isMakeFileExist is ",isMakeFileExist)
if isMakeFileExist:
print("start make")
makeret = os.popen("cd " + path + " && make 2>&1").read()
if makeret.find("Error") > 0:
buildFailedList.append(path)
else:
#make first
cmd = "objdump -t " + path + "mytest"
print("objdump cmd is ",cmd)
objanalysis = os.popen("objdump -t " + path + "mytest").read()
for line in objanalysis.splitlines():
if line.find("*UND*") > 0 and line.find("obotcha") >0:
index = line.rfind(" ")
function = line[index+1:len(line)]
if function in functionMap:
#print("i find the function")
functionMap[function] = 0
4.待ObotchaTestSuit中所有的测试模块都编译完成,且检测完成,
functionMap中剩余的就是没有被测试到的接口
详细脚本见:
GitHub - wangsun1983/ObotchaTestSuiteObotchaTestSuite/script at master · wangsun1983/ObotchaTestSuite · GitHub