chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:40:42 +08:00
commit e25996e7db
15472 changed files with 3536181 additions and 0 deletions
+124
View File
@@ -0,0 +1,124 @@
#!/usr/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.
"""
usage: coverage_diff.py info_file diff_file > > coverage-diff.info
"""
import sys
def get_diff_file_lines(diff_file):
"""
Args:
diff_file (str): File to get modified lines.
Returns:
dict: The diff lines of files.
"""
diff_file_lines = {}
current_file = None
current_line = -1
with open(diff_file) as diff_file:
for line in diff_file:
line = line.strip()
if line.startswith('+++ '):
current_file = line.removeprefix('+++ ')
diff_file_lines[current_file] = []
continue
elif line.startswith('@@ '):
current_line = line.split()[2]
current_line = current_line.lstrip('+').split(',')[0]
current_line = int(current_line)
continue
elif line.startswith('-'):
continue
elif line.startswith('+'):
diff_file_lines[current_file].append(current_line)
current_line += 1
return diff_file_lines
def get_info_file_lines(info_file, diff_file):
"""
Args:
info_file (str): File generated by lcov.
diff_file (str): File to get modified lines.
Returns:
None
"""
diff_file_lines = get_diff_file_lines(diff_file)
current_lines = []
current_lf = 0
current_lh = 0
with open(info_file) as info_file:
for line in info_file:
line = line.strip()
if line.startswith('SF:'):
current_file = line.lstrip('SF:')
current_file = current_file.removeprefix('/paddle/')
current_lines = diff_file_lines.get(current_file, [])
elif line.startswith('DA:'):
da = line.lstrip('DA:').split(',')
if int(da[0]) in current_lines:
current_lf += 1
if not line.endswith(',0'):
current_lh += 1
print(line)
continue
elif line.startswith('LF:'):
print(f'LF:{current_lf}')
continue
elif line.startswith('LH:'):
print(f'LH:{current_lh}')
continue
print(line)
if __name__ == '__main__':
if len(sys.argv) < 3:
sys.exit()
info_file = sys.argv[1]
diff_file = sys.argv[2]
get_info_file_lines(info_file, diff_file)
+65
View File
@@ -0,0 +1,65 @@
#!/usr/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.
"""
usage: coverage_diff_list.py list_file max_rate > coverage-diff-list-90.out
"""
import sys
def filter_by(list_file, max_rate):
"""
Args:
list_file (str): File of list.
max_rate (float): Max rate.
Returns:
tuple: File and coverage rate.
"""
with open(list_file) as list_file:
for line in list_file:
line = line.strip()
split = line.split('|')
# name
name = split[0].strip()
name = name.removeprefix('/paddle/')
# rate
try:
rate = split[1].split()[0].strip('%')
rate = float(rate)
if rate >= max_rate:
continue
except:
pass
print(name, rate)
if __name__ == '__main__':
if len(sys.argv) < 2:
sys.exit()
list_file = sys.argv[1]
max_rate = float(sys.argv[2])
filter_by(list_file, max_rate)
+79
View File
@@ -0,0 +1,79 @@
#!/usr/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.
"""
usage: coverage_lines.py info_file expected
"""
import os
import sys
def get_lines(info_file):
"""
Args:
info_file (str): File generated by lcov.
Returns:
float: Coverage rate.
"""
hits = 0.0
total = 0.0
with open(info_file) as info_file:
for line in info_file:
line = line.strip()
if not line.startswith('DA:'):
continue
line = line[3:]
total += 1
if int(line.split(',')[1]) > 0:
hits += 1
if total == 0:
print('no data found')
sys.exit()
return hits / total
if __name__ == '__main__':
if len(sys.argv) < 3:
sys.exit()
info_file = sys.argv[1]
expected = float(sys.argv[2])
if not os.path.isfile(info_file):
print(f'info file {info_file} is not exists, ignored')
sys.exit()
actual = get_lines(info_file)
actual = round(actual, 3)
if actual < expected:
print(
f'expected >= {round(expected * 100, 1)} %, actual {round(actual * 100, 1)} %, failed'
)
sys.exit(1)
print(
f'expected >= {round(expected * 100, 1)} %, actual {round(actual * 100, 1)} %, passed'
)
+93
View File
@@ -0,0 +1,93 @@
#!/usr/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.
"""usage: cuda_clean.py pull_id."""
import os
import sys
from github import Github
def get_pull(pull_id):
"""
Args:
pull_id (int): Pull id.
Returns:
github.PullRequest.PullRequest: The pull request.
"""
token = os.getenv('GITHUB_API_TOKEN')
github = Github(token, timeout=60)
repo = github.get_repo('PaddlePaddle/Paddle')
pull = repo.get_pull(pull_id)
return pull
def get_files(pull_id):
"""
Args:
pull_id (int): Pull id.
Returns:
iterable: The generator will yield every filename.
"""
pull = get_pull(pull_id)
for file in pull.get_files():
yield file.filename
def clean(pull_id):
"""
Args:
pull_id (int): Pull id.
Returns:
None.
"""
changed = []
for file in get_files(pull_id):
# changed.append('/paddle/build/{}.gcda'.format(file))
changed.append(file)
for parent, dirs, files in os.walk('/paddle/build/'):
for gcda in files:
if gcda.endswith('.gcda'):
file_name = gcda.replace('.gcda', '')
dir_name_list = parent.replace('/paddle/build/', '').split('/')
dir_name_list = dir_name_list[:-2]
dir_name = '/'.join(dir_name_list)
src_name = dir_name + '/' + file_name
# remove no changed gcda
if src_name not in changed:
unused_file = parent + '/' + gcda
# print unused_file
os.remove(gcda)
else:
print(src_name)
if __name__ == '__main__':
pull_id = sys.argv[1]
pull_id = int(pull_id)
clean(pull_id)
+109
View File
@@ -0,0 +1,109 @@
#!/usr/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.
"""usage: gcda_clean.py pull_id."""
import os
import sys
import time
from github import Github
def get_pull(pull_id):
"""Get pull.
Args:
pull_id (int): Pull id.
Returns:
github.PullRequest.PullRequest
"""
token = os.getenv('GITHUB_API_TOKEN')
github = Github(token, timeout=60)
idx = 1
while idx < 4:
try:
repo = github.get_repo('PaddlePaddle/Paddle')
except Exception as e:
print(e)
print(f"get_repo error, retry {idx} times after {idx * 10} secs.")
else:
break
idx += 1
time.sleep(idx * 10)
pull = repo.get_pull(pull_id)
return pull
def get_files(pull_id):
"""Get files.
Args:
pull_id (int): Pull id.
Returns:
iterable: The generator will yield every filename.
"""
pull = get_pull(pull_id)
for file in pull.get_files():
yield file.filename
def clean(pull_id):
"""Clean.
Args:
pull_id (int): Pull id.
Returns:
None.
"""
changed = []
for file in get_files(pull_id):
changed.append(f'/paddle/build/{file}.gcda')
for parent, dirs, files in os.walk('/paddle/build/'):
for gcda in files:
if gcda.endswith('.gcda'):
trimmed = parent
# convert paddle/fluid/imperative/CMakeFiles/layer.dir/layer.cc.gcda
# to paddle/fluid/imperative/layer.cc.gcda
# modified to make it more robust
# convert /paddle/build/paddle/phi/backends/CMakeFiles/phi_backends.dir/gpu/cuda/cuda_info.cc.gcda
# to /paddle/build/paddle/phi/backends/gpu/cuda/cuda_info.cc.gcda
trimmed_tmp = []
for p in trimmed.split('/'):
if p.endswith('.dir') or p.endswith('CMakeFiles'):
continue
trimmed_tmp.append(p)
trimmed = '/'.join(trimmed_tmp)
# remove no changed gcda
if os.path.join(trimmed, gcda) not in changed:
gcda = os.path.join(parent, gcda)
os.remove(gcda)
if __name__ == '__main__':
pull_id = sys.argv[1]
pull_id = int(pull_id)
clean(pull_id)
+253
View File
@@ -0,0 +1,253 @@
#!/usr/bin/env bash
# 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.
set -xe
PADDLE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/../../" && pwd )"
# install lcov
if [ ! -f "/root/.cache/lcov-1.16.tar.gz" ];then
wget -P /home https://paddle-ci.cdn.bcebos.com/coverage/lcov-1.16.tar.gz --no-proxy --no-check-certificate || exit 101
cp /home/lcov-1.16.tar.gz /root/.cache/lcov-1.16.tar.gz
else
cp /root/.cache/lcov-1.16.tar.gz /home/lcov-1.16.tar.gz
fi
tar -xf /home/lcov-1.16.tar.gz -C /
cd /lcov-1.16
make install
# run paddle coverage
cd /paddle/build
python ${PADDLE_ROOT}/tools/coverage/gcda_clean.py ${GIT_PR_ID} || exit 101
lcov --ignore-errors gcov --capture -d ./ -o coverage.info --rc lcov_branch_coverage=0
# full html report
function gen_full_html_report_cinn(){
lcov --extract coverage.info \
'/paddle/paddle/cinn/adt/*' \
'/paddle/paddle/cinn/api/*' \
'/paddle/paddle/cinn/ast_gen_ius/*' \
'/paddle/paddle/cinn/backends/*' \
'/paddle/paddle/cinn/common/*' \
'/paddle/paddle/cinn/frontend/*' \
'/paddle/paddle/cinn/hlir/*' \
'/paddle/paddle/cinn/ir/*' \
'/paddle/paddle/cinn/lang/*' \
'/paddle/paddle/cinn/operator_fusion/*' \
'/paddle/paddle/cinn/optim/*' \
'/paddle/paddle/cinn/poly/*' \
'/paddle/paddle/cinn/runtime/*' \
'/paddle/paddle/cinn/utils/*' \
-o coverage-full.tmp \
--rc lcov_branch_coverage=0
}
function gen_full_html_report() {
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/eager/*' \
'/paddle/paddle/fluid/pir/*' \
'/paddle/paddle/fluid/ir_adaptor/*' \
'/paddle/paddle/phi/*' \
'/paddle/paddle/pir/*' \
'/paddle/paddle/utils/*' \
-o coverage-full.tmp \
--rc lcov_branch_coverage=0
mv -f coverage-full.tmp coverage-full.info
lcov --remove coverage-full.info \
'/paddle/paddle/fluid/framework/*_test*' \
'/paddle/paddle/fluid/*/*test*' \
'/paddle/paddle/fluid/*/*/*test*' \
'/paddle/paddle/fluid/inference/tests/*' \
'/paddle/paddle/fluid/inference/api/demo_ci/*' \
-o coverage-full.tmp \
--rc lcov_branch_coverage=0
mv -f coverage-full.tmp coverage-full.info
}
function gen_full_html_report_xpu() {
lcov --extract coverage.info \
'/paddle/paddle/phi/kernels/xpu/*' \
-o coverage-full.tmp \
--rc lcov_branch_coverage=0
mv -f coverage-full.tmp coverage-full.info
lcov --remove coverage-full.info \
'/paddle/paddle/fluid/framework/*_test*' \
'/paddle/paddle/fluid/*/*test*' \
'/paddle/paddle/fluid/*/*/*test*' \
'/paddle/paddle/fluid/inference/tests/*' \
'/paddle/paddle/fluid/inference/api/demo_ci/*' \
-o coverage-full.tmp \
--rc lcov_branch_coverage=0
mv -f coverage-full.tmp coverage-full.info
}
function gen_full_html_report_npu() {
lcov --extract coverage.info \
'/paddle/paddle/fluid/operators/*npu*' \
-o coverage-full.tmp \
--rc lcov_branch_coverage=0
mv -f coverage-full.tmp coverage-full.info
lcov --remove coverage-full.info \
'/paddle/paddle/fluid/framework/*_test*' \
'/paddle/paddle/fluid/*/*test*' \
'/paddle/paddle/fluid/*/*/*test*' \
'/paddle/paddle/fluid/inference/tests/*' \
'/paddle/paddle/fluid/inference/api/demo_ci/*' \
-o coverage-full.tmp \
--rc lcov_branch_coverage=0
mv -f coverage-full.tmp coverage-full.info
}
if [ ${WITH_XPU:-OFF} == "ON" ]; then
gen_full_html_report_xpu || true
else
gen_full_html_report || true
fi
if [ ${WITH_CINN:-OFF} == "ON" ]; then
gen_full_html_report_cinn || true
else
gen_full_html_report || true
fi
# diff html report
function gen_diff_html_report() {
if [ "${GIT_PR_ID}" != "" ]; then
COVERAGE_DIFF_PATTERN="`python ${PADDLE_ROOT}/tools/coverage/pull_request.py files ${GIT_PR_ID}`"
python ${PADDLE_ROOT}/tools/coverage/pull_request.py diff ${GIT_PR_ID} > git-diff.out
fi
lcov --extract coverage-full.info \
${COVERAGE_DIFF_PATTERN} \
-o coverage-diff.info \
--rc lcov_branch_coverage=0
python ${PADDLE_ROOT}/tools/coverage/coverage_diff.py coverage-diff.info git-diff.out > coverage-diff.tmp
mv -f coverage-diff.tmp coverage-diff.info
genhtml -o coverage-diff -t 'Diff Coverage' --no-function-coverage --no-branch-coverage coverage-diff.info
}
gen_diff_html_report || true
# python coverage
export COVERAGE_FILE=/paddle/build/python-coverage.data
coverage combine `$(ls python-coverage.data.*)` || NO_PYTHON_COVERAGE_DATA=1
`$(coverage xml -i -o python-coverage.xml)` || [[ "${NO_PYTHON_COVERAGE_DATA}" == "1" ]]
sed -i 's/mnt\/paddle/paddle/g' python-coverage.xml
`$(python ${PADDLE_ROOT}/tools/coverage/python_coverage.py > python-coverage.info)` || [[ "${NO_PYTHON_COVERAGE_DATA}" == "1" ]]
# python full html report
#
function gen_python_full_html_report() {
lcov --extract python-coverage.info \
'/paddle/python/*' \
-o python-coverage-full.tmp \
--rc lcov_branch_coverage=0
mv -f python-coverage-full.tmp python-coverage-full.info
lcov --remove python-coverage-full.info \
'/*/tests/*' \
-o python-coverage-full.tmp \
--rc lcov_branch_coverage=0
mv -f python-coverage-full.tmp python-coverage-full.info
}
gen_python_full_html_report || true
# python diff html report
function gen_python_diff_html_report() {
if [ "${GIT_PR_ID}" != "" ]; then
COVERAGE_DIFF_PATTERN="`python ${PADDLE_ROOT}/tools/coverage/pull_request.py files ${GIT_PR_ID}`"
python ${PADDLE_ROOT}/tools/coverage/pull_request.py diff ${GIT_PR_ID} > python-git-diff.out
fi
lcov --extract python-coverage-full.info \
${COVERAGE_DIFF_PATTERN} \
-o python-coverage-diff.info \
--rc lcov_branch_coverage=0
python ${PADDLE_ROOT}/tools/coverage/coverage_diff.py python-coverage-diff.info python-git-diff.out > python-coverage-diff.tmp
mv -f python-coverage-diff.tmp python-coverage-diff.info
genhtml -o python-coverage-diff \
-t 'Python Diff Coverage' \
--no-function-coverage \
--no-branch-coverage \
--ignore-errors source \
python-coverage-diff.info
}
gen_python_diff_html_report || true
# assert coverage lines
echo "Assert Diff Coverage"
python ${PADDLE_ROOT}/tools/coverage/coverage_lines.py coverage-diff.info 0.9 || COVERAGE_LINES_ASSERT=1
echo "Assert Python Diff Coverage"
if [ ${WITH_XPU:-OFF} == "ON" ]; then
echo "XPU has no python coverage!"
else
if [[ "${NO_PYTHON_COVERAGE_DATA}" != "1" ]];then
python ${PADDLE_ROOT}/tools/coverage/coverage_lines.py python-coverage-diff.info 0.9 || PYTHON_COVERAGE_LINES_ASSERT=1
fi
fi
if [ "$COVERAGE_LINES_ASSERT" = "1" ] || [ "$PYTHON_COVERAGE_LINES_ASSERT" = "1" ]; then
echo "exit 9" > /tmp/paddle_coverage.result
python ${PADDLE_ROOT}/tools/get_pr_title.py skip_coverage_check && NOT_CHECK_COVERAGE_PR=1
if [[ "${NOT_CHECK_COVERAGE_PR}" = "1" ]];then
echo "Skip coverage check in the PR-CI-Coverage pipeline."
exit 0
fi
exit 9
fi
+281
View File
@@ -0,0 +1,281 @@
#!/usr/bin/env bash
# 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.
set -xe
PADDLE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/../../" && pwd )"
function lcov_init(){
# install lcov
if [ ! -f "/root/.cache/lcov-1.14.tar.gz" ];then
wget -P /home https://paddle-ci.gz.bcebos.com/coverage/lcov-1.14.tar.gz --no-proxy --no-check-certificate || exit 101
cp /home/lcov-1.14.tar.gz /root/.cache/lcov-1.14.tar.gz
else
cp /root/.cache/lcov-1.14.tar.gz /home/lcov-1.14.tar.gz
fi
tar -xf /home/lcov-1.14.tar.gz -C /
cd /lcov-1.14
make install
cd -
}
function gen_cpp_covinfo(){
# run paddle coverage
cd /paddle/build
python ${PADDLE_ROOT}/tools/coverage/gcda_clean.py ${GIT_PR_ID} || exit 101
lcov --capture -d ./ -o coverage.info --rc lcov_branch_coverage=0
}
# full html report
function gen_full_html_report() {
lcov --extract coverage.info \
'/paddle/paddle/fluid/framework/*' \
'/paddle/paddle/fluid/imperative/*' \
'/paddle/paddle/fluid/inference/*' \
'/paddle/paddle/fluid/operators/*' \
'/paddle/paddle/fluid/eager/*' \
'/paddle/paddle/phi/*' \
'/paddle/paddle/utils/*' \
-o coverage-full.tmp \
--rc lcov_branch_coverage=0
mv -f coverage-full.tmp coverage-full.info
lcov --remove coverage-full.info \
'/paddle/paddle/fluid/framework/*_test*' \
'/paddle/paddle/fluid/*/*test*' \
'/paddle/paddle/fluid/*/*/*test*' \
'/paddle/paddle/fluid/inference/tests/*' \
'/paddle/paddle/fluid/inference/api/demo_ci/*' \
-o coverage-full.tmp \
--rc lcov_branch_coverage=0
mv -f coverage-full.tmp coverage-full.info
}
function gen_full_html_report_xpu() {
lcov --extract coverage.info \
'/paddle/paddle/fluid/operators/*xpu*' \
'/paddle/paddle/phi/kernels/xpu/*' \
-o coverage-full.tmp \
--rc lcov_branch_coverage=0
mv -f coverage-full.tmp coverage-full.info
lcov --remove coverage-full.info \
'/paddle/paddle/fluid/framework/*_test*' \
'/paddle/paddle/fluid/*/*test*' \
'/paddle/paddle/fluid/*/*/*test*' \
'/paddle/paddle/fluid/inference/tests/*' \
'/paddle/paddle/fluid/inference/api/demo_ci/*' \
-o coverage-full.tmp \
--rc lcov_branch_coverage=0
mv -f coverage-full.tmp coverage-full.info
}
function gen_full_html_report_npu() {
lcov --extract coverage.info \
'/paddle/paddle/fluid/operators/*npu*' \
-o coverage-full.tmp \
--rc lcov_branch_coverage=0
mv -f coverage-full.tmp coverage-full.info
lcov --remove coverage-full.info \
'/paddle/paddle/fluid/framework/*_test*' \
'/paddle/paddle/fluid/*/*test*' \
'/paddle/paddle/fluid/*/*/*test*' \
'/paddle/paddle/fluid/inference/tests/*' \
'/paddle/paddle/fluid/inference/api/demo_ci/*' \
-o coverage-full.tmp \
--rc lcov_branch_coverage=0
mv -f coverage-full.tmp coverage-full.info
}
# if [ ${WITH_XPU:-OFF} == "ON" ]; then
# gen_full_html_report_xpu || true
# else
# gen_full_html_report || true
# fi
# diff html report
function gen_diff_html_report() {
if [ "${GIT_PR_ID}" != "" ]; then
COVERAGE_DIFF_PATTERN="`python ${PADDLE_ROOT}/tools/coverage/pull_request.py files ${GIT_PR_ID}`"
python ${PADDLE_ROOT}/tools/coverage/pull_request.py diff ${GIT_PR_ID} > git-diff.out
fi
lcov --extract coverage-full.info \
${COVERAGE_DIFF_PATTERN} \
-o coverage-diff.info \
--rc lcov_branch_coverage=0
python ${PADDLE_ROOT}/tools/coverage/coverage_diff.py coverage-diff.info git-diff.out > coverage-diff.tmp
mv -f coverage-diff.tmp coverage-diff.info
genhtml -o coverage-diff -t 'Diff Coverage' --no-function-coverage --no-branch-coverage coverage-diff.info
}
# gen_diff_html_report || true
function gen_py_covinfo(){
# python coverage
export COVERAGE_FILE=/paddle/build/python-coverage.data
coverage combine $(ls python-coverage.data.*) || NO_PYTHON_COVERAGE_DATA=1
$(coverage xml -i -o python-coverage.xml) || [[ "${NO_PYTHON_COVERAGE_DATA}" == "1" ]]
sed -i 's/mnt\/paddle/paddle/g' python-coverage.xml
$(python ${PADDLE_ROOT}/tools/coverage/python_coverage.py > python-coverage.info) || [[ "${NO_PYTHON_COVERAGE_DATA}" == "1" ]]
}
# python full html report
#
function gen_python_full_html_report() {
lcov --extract python-coverage.info \
'/paddle/python/*' \
-o python-coverage-full.tmp \
--rc lcov_branch_coverage=0
mv -f python-coverage-full.tmp python-coverage-full.info
lcov --remove python-coverage-full.info \
'/*/tests/*' \
-o python-coverage-full.tmp \
--rc lcov_branch_coverage=0
mv -f python-coverage-full.tmp python-coverage-full.info
}
# gen_python_full_html_report || true
# python diff html report
function gen_python_diff_html_report() {
if [ "${GIT_PR_ID}" != "" ]; then
COVERAGE_DIFF_PATTERN="`python ${PADDLE_ROOT}/tools/coverage/pull_request.py files ${GIT_PR_ID}`"
python ${PADDLE_ROOT}/tools/coverage/pull_request.py diff ${GIT_PR_ID} > python-git-diff.out
fi
lcov --extract python-coverage-full.info \
${COVERAGE_DIFF_PATTERN} \
-o python-coverage-diff.info \
--rc lcov_branch_coverage=0
python ${PADDLE_ROOT}/tools/coverage/coverage_diff.py python-coverage-diff.info python-git-diff.out > python-coverage-diff.tmp
mv -f python-coverage-diff.tmp python-coverage-diff.info
genhtml -o python-coverage-diff \
-t 'Python Diff Coverage' \
--no-function-coverage \
--no-branch-coverage \
--ignore-errors source \
python-coverage-diff.info
}
# gen_python_diff_html_report || true
# assert coverage lines
function covinfo_combine_full(){
if [ -f "other-coverage.info" ] && [ -s "other-coverage.info" ];then
if [ -f "infer-coverage.info" ] && [ -s "infer-coverage.info" ];then
lcov -a other-coverage.info -a infer-coverage.info -o coverage.info
else
mv other-coverage.info coverage.info
fi
elif [ -f "infer-coverage.info" ] && [ -s "infer-coverage.info" ];then
mv infer-coverage.info coverage.info
else
echo "Cannot found coverage.info"
fi
if [ -f "other-python-coverage.info" ] && [ -s "other-python-coverage.info" ];then
if [ -f "infer-python-coverage.info" ] && [ -s "other-python-coverage.info" ];then
lcov -a other-python-coverage.info -a infer-python-coverage.info -o python-coverage.info
else
mv other-python-coverage.info python-coverage.info
fi
elif [ -f "infer-python-coverage.info" ] && [ -s "infer-python-coverage.info" ];then
mv infer-python-coverage.info python-coverage.info
else
echo "Cannot found python coverage.info"
fi
gen_python_full_html_report || true
gen_full_html_report || true
}
function cov_rate_judge(){
echo "Assert CPP Diff Coverage"
python ${PADDLE_ROOT}/tools/coverage/coverage_lines.py coverage-diff.info 0.9 || COVERAGE_LINES_ASSERT=1
echo "Assert Python Diff Coverage"
if [ ${WITH_XPU:-OFF} == "ON" ]; then
echo "XPU has no python coverage!"
else
if [[ python-coverage-diff.info ]];then
python ${PADDLE_ROOT}/tools/coverage/coverage_lines.py python-coverage-diff.info 0.9 || PYTHON_COVERAGE_LINES_ASSERT=1
fi
fi
if [ "$COVERAGE_LINES_ASSERT" = "1" ] || [ "$PYTHON_COVERAGE_LINES_ASSERT" = "1" ]; then
echo "exit 9" > /tmp/paddle_coverage.result
exit 9
fi
}
function print_usage() {
echo -e "\n${RED}Usage${NONE}:
${BOLD}${SCRIPT_NAME}${NONE} [OPTION]"
echo -e "\n${RED}Options${NONE}:
${BLUE}gen_cov_info${NONE}: generate coverage info
${BLUE}test${NONE}: coverage info combine
"
}
function main () {
local CMD=$1
lcov_init
case $CMD in
gen_cov_info)
gen_cpp_covinfo
gen_py_covinfo
;;
combine_cov_info)
covinfo_combine_full
gen_diff_html_report || true
gen_python_diff_html_report || true
cov_rate_judge
;;
*)
print_usage
exit 1
;;
esac
}
main $@
+88
View File
@@ -0,0 +1,88 @@
#!/usr/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.
"""
usage: pull_request.py files pull_id
pull_request.py diff pull_id
"""
import argparse
import os
from github import Github
token = os.getenv('GITHUB_API_TOKEN')
def get_pull(pull_id):
"""
Args:
pull_id (int): Pull id.
Returns:
github.PullRequest.PullRequest
"""
github = Github(token, timeout=60)
repo = github.get_repo('PaddlePaddle/Paddle')
pull = repo.get_pull(pull_id)
return pull
def get_files(args):
"""
Args:
args (argparse.ArgumentParser().parse_args()): Arguments.
Returns:
None.
"""
pull = get_pull(args.pull_id)
for file in pull.get_files():
print(f'/paddle/{file.filename}')
def diff(args):
"""
Args:
args (argparse.ArgumentParser().parse_args()): Arguments.
Returns:
None.
"""
pull = get_pull(args.pull_id)
for file in pull.get_files():
print(f'+++ {file.filename}')
print(file.patch)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
files_parser = subparsers.add_parser('files')
files_parser.add_argument('pull_id', type=int)
files_parser.set_defaults(func=get_files)
diff_parser = subparsers.add_parser('diff')
diff_parser.add_argument('pull_id', type=int)
diff_parser.set_defaults(func=diff)
args = parser.parse_args()
args.func(args)
+74
View File
@@ -0,0 +1,74 @@
#!/usr/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.
"""
usage: python_coverage.py > python-coverage.info
"""
from os import path
from xml.etree import ElementTree
tree = ElementTree.parse('python-coverage.xml')
root = tree.getroot()
sources = root.findall('sources/source')
source = sources[-1].text
for clazz in root.findall('packages/package/classes/class'):
clazz_filename = clazz.attrib.get('filename')
clazz_filename = path.join(source, clazz_filename)
if clazz_filename.startswith('/paddle/build/python/'):
clazz_filename = (
'/paddle/python/' + clazz_filename[len('/paddle/build/python/') :]
)
if not path.exists(clazz_filename):
continue
print('TN:')
print(f'SF:{clazz_filename}')
branch_index = 0
for line in clazz.findall('lines/line'):
line_hits = line.attrib.get('hits')
line_number = line.attrib.get('number')
line_branch = line.attrib.get('branch')
line_condition_coverage = line.attrib.get('condition-coverage')
line_missing_branches = line.attrib.get('missing-branches')
if line_branch == 'true':
line_condition_coverage = line_condition_coverage.split()
line_condition_coverage = line_condition_coverage[1].strip('()')
line_condition_coverage = line_condition_coverage.split('/')
taken = line_condition_coverage[0]
taken = int(taken)
for _ in range(taken):
print(f'BRDA:{line_number},{0},{branch_index},{line_hits}')
branch_index += 1
if line_missing_branches:
for missing_branch in line_missing_branches.split(','):
print(f'BRDA:{line_number},{0},{branch_index},{0}')
branch_index += 1
print(f'DA:{line_number},{line_hits}')
print('end_of_record')