From 2d3dd7fb27498c80809038d24033e86c6dea835c Mon Sep 17 00:00:00 2001 From: "meiyou.hr" Date: Tue, 4 Jun 2024 17:32:11 +0800 Subject: [PATCH 1/5] kabi test downgrade --- tests/anck-pack-and-boot/run.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/anck-pack-and-boot/run.sh b/tests/anck-pack-and-boot/run.sh index 766c509..2bc5d6a 100755 --- a/tests/anck-pack-and-boot/run.sh +++ b/tests/anck-pack-and-boot/run.sh @@ -96,16 +96,23 @@ check_kabi() return 1 } - diff_line=$(cat $kabi_test_log | wc -l) - [ "$diff_line" -gt 0 ] && { + log_file_content=$(cat "$kabi_test_log") + + if [ -s "$kabi_test_log" ]; then echo "========show kabi compare result =========" - cat $kabi_test_log - upload_archives $kabi_test_log - fail "check_kabi" - return 1 - } + echo "$log_file_content" + upload_archives "$kabi_test_log" + + # 检查是否包含特定的关键字 + if echo "$log_file_content" | grep -q -E "Symbol removed or moved: func--|Changes detected in: func--"; then + fail "check_kabi" + return 1 + fi + fi + pass "check_kabi" return 0 + } anck_boot_test() -- Gitee From 9fdd8c7af31ca5072714441cb1afea2791ae7c2f Mon Sep 17 00:00:00 2001 From: "meiyou.hr" Date: Tue, 4 Jun 2024 19:24:04 +0800 Subject: [PATCH 2/5] add retry for clone and wget --- tests/anck-pack-and-boot/anck_build.sh | 66 ++++++++++++++++++-------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/tests/anck-pack-and-boot/anck_build.sh b/tests/anck-pack-and-boot/anck_build.sh index bd3fe1f..ff16434 100644 --- a/tests/anck-pack-and-boot/anck_build.sh +++ b/tests/anck-pack-and-boot/anck_build.sh @@ -77,34 +77,58 @@ anck_repo=$(basename $KERNEL_CI_REPO_URL .git) } echo "===> Clone kernel repository..." -git clone --depth 1 -b $KERNEL_CI_REPO_BRANCH $KERNEL_CI_REPO_URL -if [ "X$KERNEL_CI_PR_ID" == "X" ]; then + +# 设置重试次数和延迟时间 +retry_count=3 +retry_delay=3 + +# 通用重试函数 +retry() { + local n=1 + local max=$1 + local delay=$2 + shift 2 + local cmd="$@" + echo "===> Executing command: $cmd" + while true; do + "$@" && break || { + if [[ $n -lt $max ]]; then + ((n++)) + echo "Command failed: $cmd. Attempt $n/$max:" + sleep $delay; + else + echo "The command has failed after $n attempts: $cmd" + return 1 + fi + } + done +} + +# 克隆仓库的重试逻辑 +if ! retry $retry_count $retry_delay git clone --depth 1 -b $KERNEL_CI_REPO_BRANCH $KERNEL_CI_REPO_URL; then + echo "Failed to clone the repository after $retry_count attempts." + exit 1 +fi + +# 检查是否设置KERNEL_CI_PR_ID +if [ -z "$KERNEL_CI_PR_ID" ]; then echo "===> KERNEL_CI_PR_ID not set, Skip apply patch" cd $anck_repo else + # 生成补丁URL patch_url="${KERNEL_CI_REPO_URL/\.git/}/pulls/${KERNEL_CI_PR_ID}.patch" echo "===> Get the patch from: $patch_url" patch_file=$(basename $patch_url) + [ -f "$patch_file" ] && rm -f "$patch_file" - retry_count=3 # 尝试下载次数 - retry_delay=3 # 每次尝试间隔秒数 - - for ((i=0; i Downloaded patch successfully" - break - else - echo "===> Failed to download patch (Attempt $((i+1))/$retry_count)" - if [ $i -lt $((retry_count-1)) ]; then - echo "Retrying in $retry_delay seconds..." - sleep $retry_delay - else - echo "Failed to download patch after $retry_count attempts." - exit 1 - fi - fi - done + + # 下载补丁的重试逻辑 + if ! retry $retry_count $retry_delay wget $patch_url; then + echo "Failed to download patch after $retry_count attempts." + exit 1 + else + echo "===> Downloaded patch successfully" + fi echo "===> Patch content:" cat "$patch_file" -- Gitee From 6711cb585e0febfdec1b8061f141d17fba62645e Mon Sep 17 00:00:00 2001 From: "meiyou.hr" Date: Tue, 4 Jun 2024 20:23:56 +0800 Subject: [PATCH 3/5] filter kabi output --- tests/anck-pack-and-boot/anck_build.sh | 10 +++++--- tests/anck-pack-and-boot/run.sh | 34 +++++++++++++++++++++----- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/tests/anck-pack-and-boot/anck_build.sh b/tests/anck-pack-and-boot/anck_build.sh index ff16434..0725c98 100644 --- a/tests/anck-pack-and-boot/anck_build.sh +++ b/tests/anck-pack-and-boot/anck_build.sh @@ -91,19 +91,23 @@ retry() { local cmd="$@" echo "===> Executing command: $cmd" while true; do - "$@" && break || { + if "$@"; then + echo "Command succeeded: $cmd" + break + else if [[ $n -lt $max ]]; then ((n++)) echo "Command failed: $cmd. Attempt $n/$max:" - sleep $delay; + sleep $delay else echo "The command has failed after $n attempts: $cmd" return 1 fi - } + fi done } + # 克隆仓库的重试逻辑 if ! retry $retry_count $retry_delay git clone --depth 1 -b $KERNEL_CI_REPO_BRANCH $KERNEL_CI_REPO_URL; then echo "Failed to clone the repository after $retry_count attempts." diff --git a/tests/anck-pack-and-boot/run.sh b/tests/anck-pack-and-boot/run.sh index 2bc5d6a..dbffab1 100755 --- a/tests/anck-pack-and-boot/run.sh +++ b/tests/anck-pack-and-boot/run.sh @@ -100,19 +100,41 @@ check_kabi() if [ -s "$kabi_test_log" ]; then echo "========show kabi compare result =========" - echo "$log_file_content" + + # 定义一个变量来存储筛选后的内容 + filtered_content="" + + # 使用flag标记是否收集代码块 + collect_block=false + + # 读取kabi_test_log文件逐行处理 + while IFS= read -r line; do + # 检查当前行是否包含关键字 + if echo "$line" | grep -q -E "Symbol removed or moved: func--|Changes detected in: func--"; then + # 关键字行开始收集 + collect_block=true + filtered_content+="$line\n" + elif $collect_block; then + # 收集关键字行之后的内容 + filtered_content+="$line\n" + # 遇到空行或结束行停止收集 + if [ -z "$line" ] || [[ "$line" =~ ^[[:space:]]*$ ]]; then + collect_block=false + fi + fi + done < "$kabi_test_log" + + echo -e "$filtered_content" + echo -e "$filtered_content" > "$kabi_test_log" upload_archives "$kabi_test_log" - - # 检查是否包含特定的关键字 - if echo "$log_file_content" | grep -q -E "Symbol removed or moved: func--|Changes detected in: func--"; then + + if [ -n "$filtered_content" ]; then fail "check_kabi" return 1 fi fi - pass "check_kabi" return 0 - } anck_boot_test() -- Gitee From 0721d5e552d304ad1ed285507174f6ebc3e991c9 Mon Sep 17 00:00:00 2001 From: "meiyou.hr" Date: Wed, 5 Jun 2024 11:09:40 +0800 Subject: [PATCH 4/5] kabi is replaced by kapi --- tests/anck-pack-and-boot/run.sh | 58 ++++++++++++++++----------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/anck-pack-and-boot/run.sh b/tests/anck-pack-and-boot/run.sh index dbffab1..3b11909 100755 --- a/tests/anck-pack-and-boot/run.sh +++ b/tests/anck-pack-and-boot/run.sh @@ -45,7 +45,7 @@ anck_build() return 0 } -kabi_install_dep_pkg() +kapi_install_dep_pkg() { dep_pkgs="elfutils elfutils-devel bison flex" for pkg in $dep_pkgs; do @@ -53,30 +53,30 @@ kabi_install_dep_pkg() done } -check_kabi() +check_kapi() { local reboot_kernel_ret=$1 if [ "$reboot_kernel_ret" != "0" ]; then - skip "check_kabi" + skip "check_kapi" return 1 fi if [ "$KERNEL_CI_REPO_BRANCH" != "devel-5.10" ]; then - skip "check_kabi" + skip "check_kapi" return 0 fi - kabi_test_dir="/tmp/kabi_test" - kabi_test_log="/tmp/kabi_test.log" + kapi_test_dir="/tmp/kapi_test" + kapi_test_log="/tmp/kapi_test.log" - kabi_install_dep_pkg + kapi_install_dep_pkg - rm -rf $kabi_test_log - remote_cmd "[ -d $kabi_test_dir ] && rm -rf $kabi_test_dir" - remote_cmd "mkdir -p $kabi_test_dir" - remote_cmd "git clone https://gitee.com/anolis/kabi-dw.git $kabi_test_dir/kabi-dw" - remote_cmd "\"cd $kabi_test_dir/kabi-dw;make\"" - remote_cmd "git clone https://gitee.com/anolis/kabi-whitelist.git $kabi_test_dir/kabi-whitelist" + rm -rf $kapi_test_log + remote_cmd "[ -d $kapi_test_dir ] && rm -rf $kapi_test_dir" + remote_cmd "mkdir -p $kapi_test_dir" + remote_cmd "git clone https://gitee.com/anolis/kapi-dw.git $kapi_test_dir/kapi-dw" + remote_cmd "\"cd $kapi_test_dir/kapi-dw;make\"" + remote_cmd "git clone https://gitee.com/anolis/kapi-whitelist.git $kapi_test_dir/kapi-whitelist" vmlinux_new=$(find /anck_build/ck-build/rpmbuild/BUILD/ -name "vmlinux" | grep -v compressed) [ -z "$vmlinux_new" ] && echo "Can not found kernel vmlinux" && return 1 @@ -86,20 +86,20 @@ check_kabi() vmlinuz_dir=$(dirname $vmlinuz_path) logger "scp ${vmlinux_new} root@${REMOTE_HOST}:${vmlinuz_dir}" - # kabi compare - remote_cmd "$kabi_test_dir/kabi-dw/kabi-dw generate -s ${kabi_test_dir}/kabi-whitelist/kabi_whitelist_$(uname -m) -o kabi_after_$(uname -m) ${vmlinuz_dir}" - remote_cmd "$kabi_test_dir/kabi-dw/kabi-dw compare -k ${kabi_test_dir}/kabi-whitelist/kabi_dw_output/kabi_pre_$(uname -m) kabi_after_$(uname -m) > $kabi_test_log" + # kapi compare + remote_cmd "$kapi_test_dir/kapi-dw/kapi-dw generate -s ${kapi_test_dir}/kapi-whitelist/kapi_whitelist_$(uname -m) -o kapi_after_$(uname -m) ${vmlinuz_dir}" + remote_cmd "$kapi_test_dir/kapi-dw/kapi-dw compare -k ${kapi_test_dir}/kapi-whitelist/kapi_dw_output/kapi_pre_$(uname -m) kapi_after_$(uname -m) > $kapi_test_log" - ls -l $kabi_test_log || { - echo "Can not found $kabi_test_log" - fail "check_kabi" + ls -l $kapi_test_log || { + echo "Can not found $kapi_test_log" + fail "check_kapi" return 1 } - log_file_content=$(cat "$kabi_test_log") + log_file_content=$(cat "$kapi_test_log") - if [ -s "$kabi_test_log" ]; then - echo "========show kabi compare result =========" + if [ -s "$kapi_test_log" ]; then + echo "========show kapi compare result =========" # 定义一个变量来存储筛选后的内容 filtered_content="" @@ -107,7 +107,7 @@ check_kabi() # 使用flag标记是否收集代码块 collect_block=false - # 读取kabi_test_log文件逐行处理 + # 读取kapi_test_log文件逐行处理 while IFS= read -r line; do # 检查当前行是否包含关键字 if echo "$line" | grep -q -E "Symbol removed or moved: func--|Changes detected in: func--"; then @@ -122,18 +122,18 @@ check_kabi() collect_block=false fi fi - done < "$kabi_test_log" + done < "$kapi_test_log" echo -e "$filtered_content" - echo -e "$filtered_content" > "$kabi_test_log" - upload_archives "$kabi_test_log" + echo -e "$filtered_content" > "$kapi_test_log" + upload_archives "$kapi_test_log" if [ -n "$filtered_content" ]; then - fail "check_kabi" + fail "check_kapi" return 1 fi fi - pass "check_kabi" + pass "check_kapi" return 0 } @@ -247,7 +247,7 @@ run() if [ "$case" == "anck_rpm_build" ]; then anck_boot_test $c_ret - check_kabi $? + check_kapi $? c_ret=$? fi [ "$case" != "check_Kconfig" ] && [ "$c_ret" != "0" ] && run_ret=1 -- Gitee From 84831835e7a41dfba2ce71e1d29a64896b717ea7 Mon Sep 17 00:00:00 2001 From: "meiyou.hr" Date: Wed, 5 Jun 2024 14:03:16 +0800 Subject: [PATCH 5/5] fix: keep kabi word in kabi-dw&kabi-whitelist --- tests/anck-pack-and-boot/run.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/anck-pack-and-boot/run.sh b/tests/anck-pack-and-boot/run.sh index 3b11909..df9cc55 100755 --- a/tests/anck-pack-and-boot/run.sh +++ b/tests/anck-pack-and-boot/run.sh @@ -74,9 +74,9 @@ check_kapi() rm -rf $kapi_test_log remote_cmd "[ -d $kapi_test_dir ] && rm -rf $kapi_test_dir" remote_cmd "mkdir -p $kapi_test_dir" - remote_cmd "git clone https://gitee.com/anolis/kapi-dw.git $kapi_test_dir/kapi-dw" - remote_cmd "\"cd $kapi_test_dir/kapi-dw;make\"" - remote_cmd "git clone https://gitee.com/anolis/kapi-whitelist.git $kapi_test_dir/kapi-whitelist" + remote_cmd "git clone https://gitee.com/anolis/kabi-dw.git $kapi_test_dir/kabi-dw" + remote_cmd "\"cd $kapi_test_dir/kabi-dw;make\"" + remote_cmd "git clone https://gitee.com/anolis/kabi-whitelist.git $kapi_test_dir/kabi-whitelist" vmlinux_new=$(find /anck_build/ck-build/rpmbuild/BUILD/ -name "vmlinux" | grep -v compressed) [ -z "$vmlinux_new" ] && echo "Can not found kernel vmlinux" && return 1 @@ -87,8 +87,8 @@ check_kapi() logger "scp ${vmlinux_new} root@${REMOTE_HOST}:${vmlinuz_dir}" # kapi compare - remote_cmd "$kapi_test_dir/kapi-dw/kapi-dw generate -s ${kapi_test_dir}/kapi-whitelist/kapi_whitelist_$(uname -m) -o kapi_after_$(uname -m) ${vmlinuz_dir}" - remote_cmd "$kapi_test_dir/kapi-dw/kapi-dw compare -k ${kapi_test_dir}/kapi-whitelist/kapi_dw_output/kapi_pre_$(uname -m) kapi_after_$(uname -m) > $kapi_test_log" + remote_cmd "$kapi_test_dir/kabi-dw/kabi-dw generate -s ${kapi_test_dir}/kabi-whitelist/kabi_whitelist_$(uname -m) -o kapi_after_$(uname -m) ${vmlinuz_dir}" + remote_cmd "$kapi_test_dir/kabi-dw/kabi-dw compare -k ${kapi_test_dir}/kabi-whitelist/kabi_dw_output/kabi_pre_$(uname -m) kapi_after_$(uname -m) > $kapi_test_log" ls -l $kapi_test_log || { echo "Can not found $kapi_test_log" @@ -101,7 +101,7 @@ check_kapi() if [ -s "$kapi_test_log" ]; then echo "========show kapi compare result =========" - # 定义一个变量来存储筛选后的内容 + # 存储筛选后的内容 filtered_content="" # 使用flag标记是否收集代码块 @@ -109,7 +109,7 @@ check_kapi() # 读取kapi_test_log文件逐行处理 while IFS= read -r line; do - # 检查当前行是否包含关键字 + # https://aliyuque.antfin.com/prt6me/web95p/yv4a8wzkpmg3qym5?singleDoc# if echo "$line" | grep -q -E "Symbol removed or moved: func--|Changes detected in: func--"; then # 关键字行开始收集 collect_block=true -- Gitee