未验证 提交 3e8cec85 编写于 作者: Z zhangbo9674 提交者: GitHub

[CI-Precision] Optimize precision test logic (#49441)

* speedup getFNDAFile

* add fnda_base for c++ ut cc file

* fix bug

* fix bug

* fix bug

* fix bug
上级 69c7edcf
......@@ -1843,6 +1843,11 @@ function precise_card_test_single {
for case in $(echo $testcases | tr "$|^" "\n" | awk '!/^$/')
do
cd ${PADDLE_ROOT}/build
find paddle/fluid -name *.gcda | xargs rm -f
find paddle/phi -name *.gcda | xargs rm -f
find paddle/utils -name *.gcda | xargs rm -f
precise_card_test "^${case}$" $num
#if test failed,continue,if test succeed ,go on
......@@ -1876,9 +1881,6 @@ function precise_card_test_single {
fi
mv python-coverage.data.* ${PADDLE_ROOT}/build/pytest/$case
fi
find paddle/fluid -name *.gcda | xargs rm -f
find paddle/phi -name *.gcda | xargs rm -f
find paddle/utils -name *.gcda | xargs rm -f
done
}
......@@ -1988,6 +1990,10 @@ set +x
fi
read testcase <<< $(echo "$line"|grep -oEi "\w+$")
if [[ "$testcase" == "simple_precision_test" ]]; then
continue
fi
if [[ "$is_multicard" == "" ]]; then
# trick: treat all test case with prefix "test_dist" as dist case, and would run on 2 GPUs
read is_multicard <<< $(echo "$testcase"|grep -oEi "test_dist_")
......@@ -2032,6 +2038,8 @@ set -x
mkdir -p ${PADDLE_ROOT}/build/ut_map
mkdir -p ${PADDLE_ROOT}/build/pytest
#run all unittest to get the coverage information of .c and .h files
precise_card_test_single "^simple_precision_test$" 1
wait;
precise_card_test_single "$single_card_tests" 1
precise_card_test_single "$single_card_tests_1" 1
precise_card_test_single "$multiple_card_tests" 2
......
......@@ -12,12 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import os
import re
import sys
def getFNDAFile(rootPath, test):
# load base fnda
fnda_base_dict = {}
find_file_cmd = os.popen("find %s -name %s.cc" % (rootPath, test))
if find_file_cmd.read() != "":
print("%s is a c++ unittest" % test)
with open(
"%s/build/ut_map/simple_precision_test/base_fnda.json" % rootPath,
'r',
) as load_f:
fnda_base_dict = json.load(load_f)
# analyse fnda
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)
......@@ -27,15 +39,28 @@ def getFNDAFile(rootPath, test):
except FileNotFoundError:
print("%s is not found." % filename)
return
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))
all_data = f.read().split('TN:')
del all_data[0]
for gcov_data in all_data:
message_list = gcov_data.split('\n')
os.system('echo %s >> %s' % (message_list[1], fn_filename))
if 'FNH:0' not in gcov_data:
for message in message_list:
if message.startswith(('FNDA:')) and (
not message.startswith(('FNDA:0,'))
):
tmp_data = message.split('FNDA:')[1].split(',')
hit = int(tmp_data[0])
symbol = tmp_data[1]
if symbol in fnda_base_dict:
if (hit - fnda_base_dict[symbol]) > 0:
fnda_str = 'FNDA:%s,%s' % (
str(hit - fnda_base_dict[symbol]),
symbol,
)
os.system('echo %s >> %s' % (fnda_str, fn_filename))
else:
os.system('echo %s >> %s' % (message, fn_filename))
f.close()
......@@ -112,6 +137,32 @@ def analysisFNDAFile(rootPath, test):
f.close()
def getBaseFnda(rootPath, test):
filename = '%s/build/ut_map/%s/coverage.info.tmp' % (rootPath, test)
try:
f = open(filename)
print("oepn %s succesfully" % filename)
except FileNotFoundError:
print("%s is not found." % filename)
symbol_fnda = {}
all_data = f.read().split('TN:')
del all_data[0]
for gcov_data in all_data:
message_list = gcov_data.split('\n')
# only for cc file
if ".cc" in message_list[1]:
for message in message_list:
if message.startswith(('FNDA:')) and (
not message.startswith(('FNDA:0,'))
):
tmp_data = message.split('FNDA:')[1].split(',')
symbol_fnda[tmp_data[1]] = int(tmp_data[0])
f.close()
with open("%s/build/ut_map/%s/base_fnda.json" % (rootPath, test), "w") as f:
json.dump(symbol_fnda, f, indent=4)
def getCovinfo(rootPath, test):
ut_map_path = '%s/build/ut_map/%s' % (rootPath, test)
os.system(
......@@ -139,8 +190,11 @@ def getCovinfo(rootPath, test):
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 test == "simple_precision_test":
getBaseFnda(rootPath, test)
else:
getFNDAFile(rootPath, test)
analysisFNDAFile(rootPath, test)
os.system('rm -rf %s/coverage.info.tmp' % ut_map_path)
......
......@@ -72,6 +72,31 @@ def insert_pile_to_h_file(rootPath):
os.system('echo "\n#endif" >> %s' % line)
def add_simple_cxx_test(rootPath):
variant_test_path = '%s/paddle/utils/variant_test.cc' % rootPath
variant_test_cmakeflie_path = '%s/paddle/utils/CMakeLists.txt' % rootPath
if os.path.exists(variant_test_path) and os.path.exists(
variant_test_cmakeflie_path
):
simple_test_path = '%s/paddle/utils/simple_precision_test.cc' % rootPath
os.system('touch %s' % simple_test_path)
os.system(
"echo '#include \"gtest/gtest.h\"\n' >> %s" % simple_test_path
)
os.system(
'echo "TEST(interface_test, type) { }\n" >> %s' % simple_test_path
)
os.system('echo "cc_test(" >> %s' % variant_test_cmakeflie_path)
os.system(
'echo " simple_precision_test" >> %s' % variant_test_cmakeflie_path
)
os.system(
'echo " SRCS simple_precision_test.cc" >> %s'
% variant_test_cmakeflie_path
)
os.system('echo " DEPS gtest)\n" >> %s' % variant_test_cmakeflie_path)
def remove_pile_from_h_file(rootPath):
h_cu_files = '%s/tools/h_cu_files.log' % rootPath
f = open(h_cu_files)
......@@ -130,6 +155,7 @@ if __name__ == "__main__":
elif func == 'insert_pile_to_h_file':
rootPath = sys.argv[2]
insert_pile_to_h_file(rootPath)
add_simple_cxx_test(rootPath)
elif func == 'analy_h_cu_file':
dir_path = sys.argv[2]
rootPath = sys.argv[3]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册