#!/bin/bash
CODE_PATH=$1
if [ ! -d $CODE_PATH ];then
echo "[ERROR] \"$CODE_PATH\" 目录不存在!"
exit 1
fi
LOG_PATH=$CODE_PATH/log_ut
export ASCEND_GLOBAL_LOG_LEVEL=3
TIMEOUT=30m
TEST_LIST=""
TEST_LIST+="host "
TEST_LIST+="api "
TEST_LIST+="kernel "
OP_REPO_LIST=""
OP_REPO_LIST+="moe "
OP_REPO_LIST+="attention "
OP_REPO_LIST+="gmm "
OP_REPO_LIST+="ffn "
OP_REPO_LIST+="posembedding "
OP_REPO_LIST+="mc2 "
OP_REPO_LIST+="mhc "
SOC_LIST=""
SOC_LIST+="ascend310p "
SOC_LIST+="ascend910b "
SOC_LIST+="ascend910_93 "
SOC_LIST+="ascend950 "
op_config_yaml="$CODE_PATH/tests/test_config.yaml"
op_temp_dir="$CODE_PATH/log_ut/op_content/"
function get_op_option()
{
op_name=$1
op_content_file=$op_temp_dir$op_name".txt"
sed -n "/^ $op_name:/,/^$/p" $op_config_yaml > $op_content_file
op_option="option"
option_list=`sed -n "/$op_option/,/^$/p" $op_content_file | grep -v '#' | grep ' - ' | awk -F'-' '{print $2}'`
op_option_content=""
for op in ${option_list[@]};
do
if [ -z "$op_option_content" ]
then
op_option_content+=$op
else
op_option_content+=","
op_option_content+=$op
fi
done
if [ -z "$op_option_content" ]
then
echo $op_name
else
echo $op_option_content
fi
}
mkdir -p $LOG_PATH
mkdir -p $op_temp_dir
echo -n "repo,op,fwk," &> $LOG_PATH/results.csv
mkdir -p $LOG_PATH/op_test
echo -n "op_test," &>> $LOG_PATH/results.csv
echo "" &>> $LOG_PATH/results.csv
export ASCEND_SLOG_PRINT_TO_STDOUT=1
for OP_REPO in $OP_REPO_LIST; do
printf "%-50s" "[$OP_REPO]" | tr ' ' '-'
printf "%-50s" "[op_test]" | tr ' ' '-'
echo ""
cd $CODE_PATH/$OP_REPO
OP_LIST=$(ls -d */ | sed 's/\///g' | grep -v "3rd" | grep -v "common")" "
for OP in $OP_LIST; do
echo -n "$OP_REPO,$OP," &>> $LOG_PATH/results.csv
printf "%-50s" $OP
op_option_list=$(get_op_option $OP)
if [ -z "$op_option_list" ]
then
echo "$OP_REPO $OP could not find option!" &>> $LOG_PATH/ut_error.log
echo -ne "\033[33mNA\033[0m"
echo ""
continue
else
echo "$OP_REPO $OP option is:"$op_option_list &>> $LOG_PATH/ut.log
fi
cd $CODE_PATH
if [ "$OP_REPO" = "mc2" ]; then
run_mc2_ut_case() {
local test_type=$1
local soc_param=$2
if [ $test_type = "host" ]; then
timeout $TIMEOUT bash build.sh -u --ophost --ops=$op_option_list --cov --soc=$soc_param &>> $LOG_PATH/op_test/$OP.log
elif [ $test_type = "api" ]; then
timeout $TIMEOUT bash build.sh -u --opapi --ops=$op_option_list --cov &>> $LOG_PATH/op_test/$OP.log
fi
if [ $? -ne 0 ]; then
echo -ne "\033[31m$test_type $soc_param FAIL\033[0m "
echo -n "$test_type $SOC FAIL," &>> $LOG_PATH/results.csv
else
echo -ne "\033[32m$test_type $soc_param PASS\033[0m "
echo -n "$test_type $SOC PASS," &>> $LOG_PATH/results.csv
fi
if [ -f build/cov_result/coverage.info ]; then
echo "$OP $test_type $soc_param ut coverage file info is:" >> $LOG_PATH/ut.log
ls -sh build/cov_result/coverage.info &>> $LOG_PATH/ut.log
cat build/cov_result/coverage.info >> ./coverage.info
else
echo "$OP $test_type $soc_param ut do not generate!" >> $LOG_PATH/ut.log
fi
}
for TEST in $TEST_LIST; do
if [ "$TEST" = "host" ]; then
for SOC in $SOC_LIST; do
run_mc2_ut_case "host" "$SOC"
done
elif [ "$TEST" = "api" ]; then
run_mc2_ut_case "api" ""
else
echo "host cannot be executed temporarily" &>> $LOG_PATH/op_test/$OP.log
fi
done
else
timeout $TIMEOUT bash build.sh -u --ops=$op_option_list --cov --soc=ascend310p,ascend910b,ascend910_93,ascend950 &> $LOG_PATH/op_test/$OP.log
if [ $? -ne 0 ]; then
echo -ne "\033[31mFAIL\033[0m "
echo -n "FAIL," &>> $LOG_PATH/results.csv
else
echo -ne "\033[32mPASS\033[0m "
echo -n "PASS," &>> $LOG_PATH/results.csv
fi
if [ -f build/cov_result/coverage.info ]; then
echo "$OP ut coverage file info is:" >> $LOG_PATH/ut.log
ls -sh build/cov_result/coverage.info &>> $LOG_PATH/ut.log
cat build/cov_result/coverage.info >> ./coverage.info
else
echo "$OP ut do not generate!" >> $LOG_PATH/ut.log
fi
fi
echo ""
echo "" &>> $LOG_PATH/results.csv
done
done
rm -r $CODE_PATH/build/cov_result