forked from PaddlePaddle/Paddle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_single_test_cov.py
101 lines (92 loc) · 4.22 KB
/
get_single_test_cov.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import json
import time
import sys
import re
def getFNDAFile(rootPath, test):
filename = '%s/build/ut_map/%s/coverage.info.tmp' % (rootPath, test)
fn_filename = '%s/build/ut_map/%s/fnda.tmp' % (rootPath, test)
os.system('touch %s' % fn_filename)
f = open(filename)
lines = f.readlines()
for line in lines:
line = line.replace('\n', '')
if line.startswith(('SF:')):
os.system('echo %s >> %s' % (line, fn_filename))
elif line.startswith(('FNDA:')):
hit = int(line.split('FNDA:')[1].split(',')[0])
if hit != 0:
os.system('echo %s >> %s' % (line, fn_filename))
f.close()
def analysisFNDAFile(rootPath, test):
related_ut_map_file = '%s/build/ut_map/%s/related_%s.txt' % (rootPath, test,
test)
notrelated_ut_map_file = '%s/build/ut_map/%s/notrelated_%s.txt' % (
rootPath, test, test)
os.system('touch %s' % related_ut_map_file)
os.system('touch %s' % notrelated_ut_map_file)
fn_filename = '%s/build/ut_map/%s/fnda.tmp' % (rootPath, test)
f = open(fn_filename)
data = f.read().split('SF:')
related_file_list = []
for message in data:
message_list = message.split('\n')
clazz_filename = message_list[0]
if '/build/' in clazz_filename:
clazz_filename = clazz_filename.replace('/build', '')
if '.pb.h' in clazz_filename:
clazz_filename = clazz_filename.replace('.pb.h', '.proto')
if '.pb.cc' in clazz_filename:
clazz_filename = clazz_filename.replace('.pb.cc', '.proto')
if 'FNDA:' in message:
OP_REGIST = True
for i in range(1, len(message_list) - 1):
fn = message_list[i]
matchObj = re.match(
r'(.*)Maker(.*)|(.*)Touch(.*)Regist(.*)|(.*)Touch(.*)JitKernel(.*)|(.*)converterC2Ev(.*)',
fn, re.I)
if matchObj == None:
OP_REGIST = False
break
if OP_REGIST == False:
related_file_list.append(clazz_filename)
os.system('echo %s >> %s' %
(clazz_filename, related_ut_map_file))
else:
os.system('echo %s >> %s' %
(clazz_filename, notrelated_ut_map_file))
else:
if clazz_filename != '':
if clazz_filename not in related_file_list: # xx.pb.cc in RELATED xx.pb.h not in RELATED
os.system('echo %s >> %s' %
(clazz_filename, notrelated_ut_map_file))
f.close()
def getCovinfo(rootPath, test):
ut_map_path = '%s/build/ut_map/%s' % (rootPath, test)
os.system(
'cd %s && lcov --capture -d . -o coverage.info --rc lcov_branch_coverage=0 > /dev/null 2>&1'
% ut_map_path)
os.system(
"cd %s && lcov --extract coverage.info '/paddle/paddle/fluid/framework/*' '/paddle/paddle/fluid/imperative/*' '/paddle/paddle/fluid/inference/*' '/paddle/paddle/fluid/memory/*' '/paddle/paddle/fluid/operators/*' '/paddle/paddle/fluid/string/*' '/paddle/paddle/fluid/distributed/*' '/paddle/paddle/fluid/platform/*' '/paddle/paddle/fluid/pybind/*' '/paddle/build/*' -o coverage.info.tmp --rc lcov_branch_coverage=0 > /dev/null 2>&1"
% ut_map_path)
os.system('rm -rf %s/paddle' % ut_map_path)
os.system('rm -rf %s/coverage.info' % ut_map_path)
getFNDAFile(rootPath, test)
analysisFNDAFile(rootPath, test)
if __name__ == "__main__":
rootPath = sys.argv[1]
case = sys.argv[2]
getCovinfo(rootPath, case)