提交 5073ea3c 编写于 作者: C chalsliu

Support precision testing

上级 36868e84
...@@ -1031,6 +1031,38 @@ set -ex ...@@ -1031,6 +1031,38 @@ set -ex
fi fi
} }
function precision_test() {
if [ ${WITH_TESTING:-ON} == "ON" ] ; then
cat <<EOF
========================================
Running precision unit tests ...
========================================
EOF
set +x
EXIT_CODE=0
testcases=$1
if [[ "$testcases" == "" ]]; then
return 0
fi
card_test "$testcases"
collect_failed_tests
if [ -n "${failed_test_lists}" ];then
failed_test_lists_ult=`echo "${failed_test_lists}" |grep -Po '[^ ].*$'`
echo "========================================"
echo "Summary Failed Tests... "
echo "========================================"
echo "The following tests FAILED: "
echo "${failed_test_lists_ult}"
fi
rm -f $tmp_dir/*
if [[ "$EXIT_CODE" != "0" ]]; then
exit 8;
fi
set -ex
fi
}
function parallel_test_base_cpu() { function parallel_test_base_cpu() {
mkdir -p ${PADDLE_ROOT}/build mkdir -p ${PADDLE_ROOT}/build
cd ${PADDLE_ROOT}/build cd ${PADDLE_ROOT}/build
...@@ -1055,10 +1087,14 @@ function parallel_test() { ...@@ -1055,10 +1087,14 @@ function parallel_test() {
mkdir -p ${PADDLE_ROOT}/build mkdir -p ${PADDLE_ROOT}/build
cd ${PADDLE_ROOT}/build cd ${PADDLE_ROOT}/build
pip install ${PADDLE_ROOT}/build/python/dist/*whl pip install ${PADDLE_ROOT}/build/python/dist/*whl
if [ "$WITH_GPU" == "ON" ];then if [ "${CASES}" != "" ]; then
parallel_test_base_gpu precision_test $CASES
else else
parallel_test_base_cpu ${PROC_RUN:-1} if [ "$WITH_GPU" == "ON" ];then
parallel_test_base_gpu
else
parallel_test_base_cpu ${PROC_RUN:-1}
fi
fi fi
ut_total_endTime_s=`date +%s` ut_total_endTime_s=`date +%s`
echo "TestCases Total Time: $[ $ut_total_endTime_s - $ut_total_startTime_s ]s" echo "TestCases Total Time: $[ $ut_total_endTime_s - $ut_total_startTime_s ]s"
......
#!/bin/env python
# Copyright (c) 2020 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.
""" For the PR that only modified the unit test, get cases in pull request. """
import os
from github import Github
import ut_filter
PADDLE_ROOT = os.getenv('PADDLE_ROOT', '/paddle/')
class PRChecker(object):
""" PR Checker. """
def __init__(self):
self.github = Github(os.getenv('GITHUB_API_TOKEN'), timeout=60)
self.repo = self.github.get_repo('PaddlePaddle/Paddle')
self.pr = None
def init(self):
""" Get pull request. """
pr_id = os.getenv('GIT_PR_ID')
if not pr_id:
print('No PR ID')
exit(0)
self.pr = self.repo.get_pull(int(pr_id))
def get_pr_files(self):
""" Get files in pull request. """
page = 0
file_list = []
while True:
files = self.pr.get_files().get_page(page)
if not files:
break
for f in files:
file_list.append(PADDLE_ROOT + f.filename)
page += 1
return file_list
#return ['/paddle/paddle/fluid/memory/malloc_test.cu']
def get_pr_ut(self):
""" Get unit tests in pull request. """
ut_str = ''
ut_mapper = ut_filter.UTMapper()
file_ut_map = ut_mapper.get_src_ut_map()
for f in self.get_pr_files():
if f not in file_ut_map:
return ''
else:
ut_str = '{}^{}$|'.format(ut_str, file_ut_map[f])
return ut_str.rstrip('|')
if __name__ == '__main__':
pr_checker = PRChecker()
pr_checker.init()
print(pr_checker.get_pr_ut())
#!/bin/env python
# Copyright (c) 2020 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.
""" Build file and unit test mapping. """
import os
import re
import json
import time
import os.path
import subprocess
from github import Github
PADDLE_ROOT = os.getenv('PADDLE_ROOT', '/paddle/')
class UTMapper(object):
""" Unit test mapper. """
def __init__(self):
self.github = Github(os.getenv('GITHUB_API_TOKEN'), timeout=60)
self.repo = None
self.ut_list = []
self.src_ut_dict = {}
def load_ctest_ut_list(self):
""" Load ctest unit test list. """
ps = subprocess.Popen("ctest -N | awk -F ':' '{print $2}' | sed '/^$/d' | sed '$d' | sed 's/ //g'",
shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd='{}build'.format(PADDLE_ROOT))
uts = ps.communicate()[0]
self.ut_list = uts.rstrip('\n').split('\n')
def load_cpp_and_cuda_ut(self):
""" Load C++ and CUDA unit test list. """
data = None
cpp_cuda_ut_file = '{}build/compile_commands.json'.format(PADDLE_ROOT)
with open(cpp_cuda_ut_file) as f:
data = json.load(f)
for ut in data:
ut_name = re.search('-o .*\/(.*).dir\/.*', ut['command']).group(1)
if ut_name not in self.ut_list:
continue
self.src_ut_dict[ut['file']] = ut_name
def load_python_ut(self):
""" Load Python unit test list. """
pyut_files = subprocess.check_output('find {}python -name test*.py'.format(PADDLE_ROOT).split(' '))
pyut_list = pyut_files.rstrip('\n').split('\n')
for src_file in pyut_list:
self.src_ut_dict[src_file] = src_file.split('/')[-1].split('.py')[0]
def get_src_ut_map(self):
""" Get src file and unit test map. """
self.load_ctest_ut_list()
self.load_cpp_and_cuda_ut()
self.load_python_ut()
return self.src_ut_dict
if __name__ == '__main__':
ut_mapper = UTMapper()
ut_mapper.load_python_ut()
ut_mapper.load_ctest_ut_list()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册