#!/bin/bash
current_dir=$(pwd)
variables_cmake="cmake/variables.cmake"
pr_file=$(realpath "${1:-pr_filelist.txt}")
op_category_list=$(grep -oP 'set\(OP_CATEGORY_LIST\s*\K".*"' $current_dir/$variables_cmake | sed 's/"//g')
IFS=' ' read -r -a op_categories <<< "$op_category_list"
valid_dirs=()
for category in "${op_categories[@]}"
do
category_path="$current_dir/$category"
if [ -d "$category_path" ]; then
for dir in "$category_path"/*/
do
if [ -d "$dir/tests/ut/op_kernel" ]; then
dir_name=$(basename "$dir")
if [[ "$dir_name" != *"common"* ]]; then
valid_dirs+=("$dir_name")
fi
fi
done
fi
done
ops_name=()
found_mirror_update=false
mapfile -t lines < ${pr_file}
for file_path in "${lines[@]}"
do
file_path=$(echo "$file_path" | xargs)
if [ -z "$file_path" ]; then
continue
fi
if [[ "$file_path" == *.md ]]; then
continue
fi
for dir in "${valid_dirs[@]}"
do
if [[ "$file_path" == *"/$dir/"* ]]; then
if [[ "$file_path" == *"op_kernel"* ]]; then
if [[ ! " ${ops_name[@]} " =~ " $dir " ]]; then
ops_name+=("$dir")
fi
fi
break
fi
done
if [[ "$file_path" == "scripts/ci/mirror_update_time.txt" ]]; then
found_mirror_update=true;
fi
done
supportedSocVersion=("ascend910b" "ascend310p" "ascend950")
for name in "${ops_name[@]}"
do
for soc_version in "${supportedSocVersion[@]}"
do
echo "[EXECUTE_COMMAND] bash build.sh -u --opkernel --ops=$name --cov --soc=$soc_version"
bash build.sh -u --opkernel --ops=$name --cov --soc=$soc_version --cann_3rd_lib_path=${ASCEND_3RD_LIB_PATH} -j16
status=$?
if [ $status -ne 0 ]; then
echo "${name} kernel ut fail"
exit 1
fi
done
done
if [[ "$found_mirror_update" == "true" ]]; then
calc_ops_950=("add" "sub" "mul" "div")
operator_list_950=("${calc_ops_950[@]}")
for name in "${operator_list_950[@]}"
do
echo "[EXECUTE_COMMAND] bash build.sh -u --opapi --ophost --ops=$name --soc=ascend950"
bash build.sh -u --opapi --ophost --ops=$name --soc=ascend950 --cann_3rd_lib_path=${ASCEND_3RD_LIB_PATH} -j16
status=$?
if [ $status -ne 0 ]; then
echo "${name} ascend950 api/host ut fail"
exit 1
fi
done
fi