#!/bin/bash
current_dir=$(pwd)
variables_cmake="cmake/variables.cmake"
op_category_list=$(perl -0777 -ne 'if (/set\(OPS_CATEGORY_LIST\s*(.*?)\)/s) { print $1 }' "$current_dir/$variables_cmake" | grep -oP '"[^"]+"' | sed 's/"//g' | xargs)
IFS=' ' read -r -a op_categories <<< "$op_category_list"
valid_dirs=()
pr_file=$(realpath "${1:-pr_filelist.txt}")
for category in "${op_categories[@]}"
do
first_level="$current_dir/$category"
if [ -d "$first_level" ]; then
for second_level in "$first_level"/*/
do
examples_dir="$second_level""examples"
if [ -d "$examples_dir" ]; then
if ls "$examples_dir"/test_aclnn_* 1> /dev/null 2> /dev/null; then
dir_name=$(basename "$second_level")
valid_dirs+=("$dir_name")
fi
fi
done
fi
done
ops_name=()
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 [[ ! " ${ops_name[@]} " =~ " $dir " ]]; then
ops_name+=("$dir")
fi
break
fi
done
done
echo "Building add_example pkg"
bash build.sh --pkg --ops=add_example -j16
status=$?
if [ $status -ne 0 ]; then
echo "add_example build failed"
exit 1
fi
echo "Installing add_example pkg"
installer=$(ls ./build_out/cann-ops-math-*.run 2>/dev/null)
if [ -z "$installer" ]; then
echo "add_example installer not found"
exit 1
fi
$installer
status=$?
if [ $status -ne 0 ]; then
echo "add_example installation failed"
exit 1
fi
bash build.sh --make_clean
echo "Running add_example aclnn example"
bash build.sh --run_example add_example eager cust
status=$?
if [ $status -ne 0 ]; then
echo "add_example aclnn example fail"
exit 1
fi
echo "Running add_example graph example"
bash build.sh --run_example add_example graph
status=$?
if [ $status -ne 0 ]; then
echo "add_example graph example fail"
exit 1
fi
for name in "${ops_name[@]}"
do
./single/cann-ops-math-${name}_linux*.run
echo "[EXECUTE_COMMAND] bash build.sh --run_example $name eager cust --vendor_name=$name"
bash build.sh --run_example $name eager cust --vendor_name=$name
status=$?
if [ $status -ne 0 ]; then
echo "${name} example fail"
exit 1
fi
done