@@ -5,6 +5,10 @@ CONDA_ENV_NAME="unittest_cuda"
55PYTHON_VERSION=" 3.10"
66REPO_PATH=$( git rev-parse --show-toplevel)
77LOG_DIR=${REPO_PATH} /ut_log_dir
8+ SUMMARY_LOG=${LOG_DIR} /results_summary.log
9+
10+ rm -rf ${LOG_DIR} && mkdir -p ${LOG_DIR}
11+ touch ${SUMMARY_LOG}
812[[ -z " $CUDA_VISIBLE_DEVICES " ]] && export CUDA_VISIBLE_DEVICES=0
913
1014function create_conda_env() {
@@ -34,6 +38,55 @@ function create_conda_env() {
3438 uv pip install pytest-cov pytest-html cmake==4.0.2
3539}
3640
41+ function print_test_results_table() {
42+ local log_pattern=$1
43+ local test_type=$2
44+
45+ echo " "
46+ echo " ==========================================" >> ${SUMMARY_LOG}
47+ echo " Test Results Summary - ${test_type} " >> ${SUMMARY_LOG}
48+ echo " ==========================================" >> ${SUMMARY_LOG}
49+ printf " %-30s %-10s %-50s\n" " Test Case" " Result" " Log File" >> ${SUMMARY_LOG}
50+ printf " %-30s %-10s %-50s\n" " ----------" " ------" " --------" >> ${SUMMARY_LOG}
51+
52+ local total_tests=0
53+ local passed_tests=0
54+ local failed_tests=0
55+
56+ for log_file in ${LOG_DIR} /${log_pattern} ; do
57+ if [ -f " ${log_file} " ]; then
58+ local test_name=$( basename " ${log_file} " .log)
59+ # Remove prefix to get clean test case name
60+ test_name=${test_name# unittest_cuda_}
61+ test_name=${test_name# unittest_cuda_vlm_}
62+
63+ local result=" UNKNOWN"
64+ local failure_count=$( grep -c ' == FAILURES ==' " ${log_file} " 2> /dev/null || echo 0)
65+ local error_count=$( grep -c ' == ERRORS ==' " ${log_file} " 2> /dev/null || echo 0)
66+ local passed_count=$( grep -c ' passed' " ${log_file} " 2> /dev/null || echo 0)
67+
68+ if [ ${failure_count} -gt 0 ] || [ ${error_count} -gt 0 ]; then
69+ result=" FAILED"
70+ failed_tests=$(( failed_tests + 1 ))
71+ elif [ ${passed_count} -gt 0 ]; then
72+ result=" PASSED"
73+ passed_tests=$(( passed_tests + 1 ))
74+ else
75+ result=" NO_TESTS"
76+ fi
77+
78+ total_tests=$(( total_tests + 1 ))
79+ local log_filename=$( basename " ${log_file} " )
80+ printf " %-30s %-10s %-50s\n" " ${test_name} " " ${result} " " ${log_filename} " >> ${SUMMARY_LOG}
81+ fi
82+ done
83+
84+ echo " ==========================================" >> ${SUMMARY_LOG}
85+ printf " Total: %d, Passed: %d, Failed: %d\n" ${total_tests} ${passed_tests} ${failed_tests} >> ${SUMMARY_LOG}
86+ echo " ==========================================" >> ${SUMMARY_LOG}
87+ echo " " >> ${SUMMARY_LOG}
88+ }
89+
3790function run_unit_test() {
3891 # install unit test dependencies
3992 create_conda_env
@@ -49,24 +102,25 @@ function run_unit_test() {
49102 uv pip install -r requirements.txt
50103 uv pip install -r requirements_diffusion.txt
51104
52- uv pip list
105+ pip list > ${LOG_DIR} /ut_pip_list.txt
53106 export COVERAGE_RCFILE=${REPO_PATH} /.azure-pipelines/scripts/ut/.coverage
54107 local auto_round_path=$( python -c ' import auto_round; print(auto_round.__path__[0])' )
55-
56- # setup test env
57- mkdir -p ${LOG_DIR}
58- local ut_log_name=${LOG_DIR} /unittest_cuda.log
59- find . -name " test_*.py" | sed " s,\.\/,python -m pytest --cov=\" ${auto_round_path} \" --cov-report term --html=report.html --self-contained-html --cov-report xml:coverage.xml --cov-append -vs --disable-warnings ,g" > run.sh
60- cat run.sh
61-
62- # run unit test
63- bash run.sh 2>&1 | tee ${ut_log_name}
64-
65- cp report.html ${LOG_DIR} /
66- cp coverage.xml ${LOG_DIR} /
67-
68- if [ $( grep -c ' == FAILURES ==' ${ut_log_name} ) != 0 ] || [ $( grep -c ' == ERRORS ==' ${ut_log_name} ) != 0 ] || [ $( grep -c ' passed' ${ut_log_name} ) == 0 ]; then
69- echo " Find errors in pytest case, please check the output..."
108+
109+ # run unit tests individually with separate logs
110+ for test_file in $( find . -name " test_*.py" ) ; do
111+ local test_basename=$( basename ${test_file} .py)
112+ local ut_log_name=${LOG_DIR} /unittest_cuda_${test_basename} .log
113+ echo " Running ${test_file} ..."
114+
115+ python -m pytest --cov=" ${auto_round_path} " --cov-report term --html=report.html --self-contained-html --cov-report xml:coverage.xml --cov-append -vs --disable-warnings ${test_file} 2>&1 | tee ${ut_log_name}
116+ done
117+
118+ mv report.html ${LOG_DIR} /
119+ mv coverage.xml ${LOG_DIR} /
120+
121+ # Print test results table and check for failures
122+ if ! print_test_results_table " unittest_cuda_test_*.log" " CUDA Unit Tests" ; then
123+ echo " Some CUDA unit tests failed. Please check the individual log files for details."
70124 fi
71125}
72126
@@ -85,30 +139,32 @@ function run_unit_test_vlm() {
85139 uv pip install flash-attn==2.7.4.post1 --no-build-isolation
86140 uv pip install -r requirements_vlm.txt
87141
88- uv pip list
142+ pip list > ${LOG_DIR} /vlm_ut_pip_list.txt
89143 export COVERAGE_RCFILE=${REPO_PATH} /.azure-pipelines/scripts/ut/.coverage
90144 local auto_round_path=$( python -c ' import auto_round; print(auto_round.__path__[0])' )
91145
92- # setup test env
93- mkdir -p ${LOG_DIR}
94- local ut_log_name= ${LOG_DIR} /unittest_cuda_vlm.log
95- find . -name " test*vlms.py " | sed " s,\.\/,python -m pytest --cov= \" ${auto_round_path} \" --cov-report term --html=report_vlms.html --self-contained-html --cov-report xml:coverage_vlms.xml --cov-append -vs --disable-warnings ,g " > run_vlms.sh
96- cat run_vlms.sh
146+ # run VLM unit tests individually with separate logs
147+ for test_file in $( find . -name " test*vlms.py " ) ; do
148+ local test_basename= $( basename ${test_file} .py )
149+ local ut_log_name= ${LOG_DIR} /unittest_cuda_vlm_ ${test_basename} .log
150+ echo " Running ${test_file} ... "
97151
98- # run unit test
99- bash run_vlms.sh 2>&1 | tee ${ut_log_name}
152+ python -m pytest --cov= " ${auto_round_path} " --cov-report term --html=report_vlms.html --self-contained-html --cov-report xml:coverage_vlms.xml --cov-append -vs --disable-warnings ${test_file} 2>&1 | tee ${ut_log_name}
153+ done
100154
101- cp report_vlms.html ${LOG_DIR} /
102- cp coverage_vlms.xml ${LOG_DIR} /
155+ mv report_vlms.html ${LOG_DIR} /
156+ mv coverage_vlms.xml ${LOG_DIR} /
103157
104- if [ $( grep -c ' == FAILURES ==' ${ut_log_name} ) != 0 ] || [ $( grep -c ' == ERRORS ==' ${ut_log_name} ) != 0 ] || [ $( grep -c ' passed' ${ut_log_name} ) == 0 ]; then
105- echo " Find errors in pytest case, please check the output..."
158+ # Print test results table and check for failures
159+ if ! print_test_results_table " unittest_cuda_vlm_test*.log" " CUDA VLM Tests" ; then
160+ echo " Some CUDA VLM tests failed. Please check the individual log files for details."
106161 fi
107162}
108163
109164function main() {
110165 run_unit_test_vlm
111166 run_unit_test
167+ cat ${SUMMARY_LOG}
112168}
113169
114170main
0 commit comments