first version.
[build-srcpkg.git] / bin / devtask
blob03c25596d8ef3b8c140e8a02490dc17f6315df2f
1 #!/bin/bash
2 ############################################################
3 # source: devtask
4 # author: CottonCandyOwner(CottonCandyOwner@126.com)
5 # date: 2022-11-17
6 ############################################################
7 # note:
8 # devtask is a utility program for develop task getting.
9 # pkg-builder use 'todo' as a feature list file to be developed,
10 # and categoried by version id in plan. and it use 'todolist'
11 # as the task list of a src-pkg. then, use 'worktasks.tmp'
12 # for developer task list.
13 # devtask copy the feature item to be developed between
14 # those file. even if do not use this program, developers
15 # can do this work manually.
16 ############################################################
20 # todo:
21 # @ user action diagram, paramter list
22 # @ email send/recv.
23 # @ git/svn operation.
24 # @
25 # @
28 . shlibinc
29 include dbgout.shlib
30 include args.shlib
31 #include inifile.shlib
32 #include shellprog.shlib
35 TESTING_ROOT_DIR=
36 TESTING_TMP_DIR=~/.testing/$(basename $0)/
40 # 遍历每个目录及子目录
41 foreach_dir ()
43 local item_proc=$2
45 [[ -z $1 || -z $z || ! -f $1 ]] && err "err: file ($1) does not exist.\n" && exit
47 test_list_depth=$((test_list_depth++))
49 # dbgout "curr content $1\n"
51 ls $1 | sort -n |
52 while read file; do
53 # 忽略.txt文件,在处理.sh文件时再进行处理
54 [[ ! -d $file ]] && continue
56 $item_proc $file
58 cd $file
59 foreach_dir $PWD/$file $item_proc
60 done
62 test_list_depth=$((test_list_depth--))
67 # 遍历每个目录及子目录下的文件
68 foreach_file ()
70 local item_proc=$2
72 [[ -z $1 || -z $z || ! -f $1 ]] && err "err: file ($1) does not exist.\n" && exit
74 test_list_depth=$((test_list_depth++))
76 # dbgout "curr content $1\n"
78 ls $1 | sort -n |
79 while read file; do
80 # 忽略.txt文件,在处理.sh文件时再进行处理
81 [[ -d $file ]] && continue
83 $item_proc $file
85 cd $file
86 foreach_dir $PWD/$file $item_proc
87 done
89 test_list_depth=$((test_list_depth--))
100 # test_item <id> <script_name> <desc_str>
101 test_item ()
103 local ret=
104 local tmp=
105 local script_name=
106 local test_desc=
107 local exetime=
109 script_name="$1.$2.sh"
110 test_desc=$3
111 # dbgout "script_name = $script_name\n"
113 # 参数有效性判断
114 if [[ ! -f $script_name ]]; then
115 err "err: file $script_name is not exist.\n"
116 return 1
119 if [[ -z $test_desc ]]; then
120 err "err: descript string is missing.\n"
121 return 1
124 if [[ ! -f $script_name.$test_desc.txt ]]; then
125 err "err: file $script_name.$test_desc.txt is not exist.\n"
126 return 1
129 # 测试item字符串信息输出
130 stdout "$CHIGHL$IFCCOLOR$TPREFIX[item] $1 $2 $3 ... "
132 # 删除原有目录,重新创建,并复制测试文件
133 rm $TESTING_TMP_DIR/$1.$2/ -rf
134 mkdir -p $TESTING_TMP_DIR/$1.$2/{,scripts}
135 cp $1.* $TESTING_TMP_DIR/$1.$2/ -rf
136 cp -rf scripts/$1.* $TESTING_TMP_DIR/$1.$2/scripts/ 2> /dev/null
137 cp -rf scripts/testing/ $TESTING_TMP_DIR/$1.$2/scripts/ 2> /dev/null
138 cd $TESTING_TMP_DIR/$1.$2
139 # dbgcmd ls -l
140 chmod +x *.sh scripts/* 2> /dev/null
142 # 如有测试运行时间信息,显示该项测试所需时间
143 if [[ -f $1.$2.time.txt ]]; then
144 exetime=`head -n 2 $1.$2.time.txt`
145 tmp=${exetime##`echo -ne "\nreal "`}
146 tmp=${tmp%%m*}
147 [[ -z $tmp ]] && err "err: the syntax of test time info is not correct.\n"
148 exetime=${exetime##*m}
149 exetime=${exetime%.*}
150 exetime=$(( tmp * 60 + exetime ))
151 # 多于5秒的测试项显示测试时间
152 [[ -n $exetime && $exetime -gt 5 ]] && stdout "(time:${exetime}s) "
155 # 带运行时间信息输出的测试项测试
156 if [[ $test_verbose == "true" ]]; then
157 ( time (
158 stdout "$CNORMAL\n###############################################" ;
159 # 输出测试脚本的stdout和stderr到管道,管道的调试信息使用tee在控制台stdout输出,并保存到日志文件
160 ( ./$script_name 2>&1 ) | tee log.txt;
161 stdout "###############################################$CHIGHL$IFCCOLOR\n"
162 ) > $dbgout_ttydev 2> /dev/null
163 ) 2> time.txt #2>&1
164 else
165 ( time ./$script_name > log.txt 2>&1 ) 2> time.txt #2>&1
168 diff log.txt $script_name.$test_desc.txt > diff.txt
169 if [[ -z "`cat diff.txt`" ]]; then
170 stdout "[ ok ]$CNORMAL\n"
171 ret=0
172 else
173 stdout "[failed]$CNORMAL\n"
174 stdout "testing result difference from correct output.\n"
175 stdout "###############################################\n"
176 if [[ $test_verbose == "true" ]]; then
177 cat diff.txt >&2
178 # cat log.txt >&2
179 else
180 cat diff.txt >&2
182 # 将测试failed项的日志保存到log目录,便于测试后的查看。
183 stdout "###############################################\n"
184 ret=1
187 cd - > /dev/null
188 if [[ $update_test_result_file == "true" ]]; then
189 cp $TESTING_TMP_DIR/$1.$2/log.txt $script_name.$test_desc.txt
190 exetime=`head -n 2 $TESTING_TMP_DIR/$1.$2/time.txt`
191 tmp=${exetime%%m*}
192 tmp=${tmp##`echo -ne "\nreal "`} # }
193 exetime=${exetime##*m}
194 exetime=${exetime%.*}
195 exetime=$(( tmp * 60 + exetime ))
196 [[ -n $exetime && $exetime -gt 5 ]] && cp $TESTING_TMP_DIR/$1.$2/time.txt $1.$2.time.txt
199 # clean testing info
200 rm $TESTING_TMP_DIR/$1.$2/ -rf
202 return $ret
205 test_dir_level=0
206 test_cnt=0
207 test_cnt_num=99999
209 err_continue_cnt=0
210 err_cnt=0
212 FCCOLOR=$FCGREEN
213 IFCCOLOR=$FCMAGENTA
214 EFCCOLOR=$FCRED
217 curr_test_id=""
219 test_stage="skip"
220 test_id_cnt=
225 test_id_check ()
227 local i
228 local test_id=$1
230 # dbgout_func_stub
232 # 这里或只进行eq判断
233 case $test_stage in
234 skip )
235 [[ -z ${begin_test_id[0]} ]] && return 0
237 # $(( test_dir_level+1 ))
238 test_id_cnt=${#begin_test_id[@]}
239 for (( i=1; i<$test_id_cnt ; i++ )); do
240 [[ -z ${curr_test_id[$i]} ]] && test_stage="testing" && test_id_cnt=${#end_test_id[@]} && return 0
241 if [[ ${begin_test_id[$i]} -lt ${curr_test_id[$i]} ]]; then
242 return 1
243 elif [[ ${begin_test_id[$i]} -eq ${curr_test_id[$i]} ]]; then
244 continue
245 else
246 # 通常运行不到这里
247 test_stage="testing" && test_id_cnt=${#end_test_id[@]} && return 0
249 done
251 testing )
252 [[ -z ${end_test_id[0]} ]] && return 0
254 # test_id_cnt=${#end_test_id[@]}
255 for (( i=1; i<$test_id_cnt ; i++ )); do
256 [[ -z ${curr_test_id[$i]} ]] && test_stage="ignor" && return 0
257 if [[ ${end_test_id[$i]} -lt ${curr_test_id[$i]} ]]; then
258 return 1
259 elif [[ ${end_test_id[$i]} -eq ${curr_test_id[$i]} ]]; then
260 continue
261 else
262 # 通常运行不到这里
263 test_stage="ignor" && return 0
265 done
267 ignor )
269 esac
270 return 2
274 # test_unit <test_dir>
275 test_unit ()
277 local tmp=
278 local test_dir=$1
279 local ret=0
280 local saved_test_id=
282 # dbgout_func_stub
284 cd $1
285 test_cnt=`test_list_curr_content $test_dirs |
286 ( while read line; do
287 tmp=( $line )
288 curr_test_id[$(( test_dir_level + 1 ))]="${tmp[1]}"
289 # id范围判断
290 test_id_check "${tmp[1]}"
291 ret=$?
292 case $ret in
297 continue
300 continue
302 esac
304 # dbgout "test_dir_level = $test_dir_level\n"
305 case ${tmp[0]} in
306 "item" )
307 test_dir_level=$(( test_dir_level + 1 ))
308 ## curr_test_id[$saved_test_id]="${tmp[1]}"
310 TPREFIX=$(printf "%*s" $(( $test_dir_level * 4)) " ")
312 test_cnt=$(( test_cnt + 1 ))
314 # dbgout "test_cnt = $test_cnt\n"
315 # dbgout "test_cnt_num = $test_cnt_num\n"
317 #dbgout "$CHIGHL$IFCCOLOR$TPREFIX${tmp[1]} ${tmp[3]} ${tmp[2]} ... "
318 test_item ${tmp[1]} ${tmp[3]} ${tmp[2]}
319 if [[ $? != 0 ]]; then
320 err_cnt=$(( err_cnt + 1 ))
321 err_continue_cnt=$(( err_continue_cnt + 1 ))
322 if [[ $test_ignor_err != "enable" ]]; then
323 err "err interrupt ...\n"
324 ret=1
325 else
326 ret=0
327 [[ $err_continue_cnt -ge 10 ]] && ret=1
329 else
330 if [[ $err_continue_cnt != 0 ]]; then
331 err_continue_cnt=0
333 ret=0
336 if [[ $test_cnt -ge $test_cnt_num ]]; then
337 ret=1
340 curr_test_id[$saved_test_id]="${tmp[1]}"
341 test_dir_level=$(( test_dir_level - 1 ))
342 TPREFIX=$(printf "%*s" $(( $test_dir_level * 4)) " ")
344 [[ $ret == 1 ]] && break
346 "module" | "unit" | "dir" )
347 if [[ $test_cnt -gt $test_cnt_num ]]; then
348 #echo $test_cnt
349 ret=1
350 break
353 test_dir_level=$(( test_dir_level + 1 ))
354 ## curr_test_id[$saved_test_id]="${tmp[1]}"
355 TPREFIX=$(printf "%*s" $(( $test_dir_level * 4)) " ")
357 ## if [[ ${begin_test_id[$test_dir_level]} -lt ${curr_test_id[$test_dir_level]} ]]; then
358 ## :
359 ## fi
361 stdout "$CHIGHL$FCCOLOR$TPREFIX# [${tmp[0]}] ${tmp[1]}.${tmp[2]} begin testing ...$CNORMAL\n"
363 test_unit "${tmp[1]}.${tmp[3]}.${tmp[2]}.${tmp[0]}"
364 ret=$?
366 curr_test_id[$test_dir_level]=""
367 test_dir_level=$(( test_dir_level - 1 ))
369 TPREFIX=$(printf "%*s" $(( $test_dir_level * 4)) " ")
370 [[ $ret != 0 ]] && break
373 echo $test_cnt
374 break
376 esac
377 done; echo $test_cnt $err_cnt $err_continue_cnt ; return $ret ); return $?`
379 # while语句由于|重定向,以一个sub-process运行,所以使用return和exit都只是从sub-process中退出。
380 # sub-proc中的环境变量test_cnt在return之前echo,在循环结束时echo,以stdout赋值给外部的test_cnt。
381 ret=$?
383 test_cnt=( $test_cnt )
384 err_cnt=${test_cnt[1]}
385 err_continue_cnt=${test_cnt[2]}
386 # dbgout "err_cnt = $err_cnt\n"
387 # dbgout "err_continue_cnt = $err_continue_cnt\n"
388 unset test_cnt[1]
389 unset test_cnt[2]
390 # dbgout "test_cnt[@]=\"${test_cnt[@]}\"\n"
392 [[ $err_continue_cnt -ge 10 ]] && stdout "连续10个测试项failed,暂停测试。\n" && ret=1
394 # dbgout "test_cnt = $test_cnt\n"
395 cd ..
396 return $ret
399 test_list_depth=0
401 # 列出指定目录下的测试内容,包括模块、单元、目录、测试项
402 # test_list_content <path>
403 test_list_curr_content ()
405 local tmp=0
406 local script_name=
407 local test_desc=
409 test_list_depth=$((test_list_depth++))
411 # dbgout "curr content $1\n"
412 ls $1 | sort -n |
413 while read file; do
414 # 忽略.txt文件,在处理.sh文件时再进行处理
415 [[ $file =~ ".txt" ]] && continue
417 # echo file=$file
418 # 以小数点分隔,包含3个字符串的为测试脚本
419 # 包含3个字符串的为测试模块/单元/目录
420 # 包含5个字符串的为测试项信息描述文件
421 OLD_IFS=$IFS
422 IFS="."
423 tmp=( $file )
424 IFS=$OLD_IFS
425 # echo "tmp(${#tmp[@]}) = ${tmp[@]}"
427 # todo:添加非数字idx过滤
428 # [[ ${tmp[1]} =~ "^[:digital:]" ]] && continue
430 if [[ ${#tmp[@]} == 5 ]]; then
431 test_desc=`ls $file.*.txt`
432 [[ -z $test_desc ]] && echo "err: txt descript file not found for $file." >&2 && return 1
433 test_desc=${test_desc#$file\.}
434 test_desc=${test_desc%\.txt}
435 script_name=${tmp[1]}
436 elif [[ ${#tmp[@]} == 4 ]]; then
437 # if [[ ${tmp[3]} == "\.module" ]]; then
438 case ${tmp[3]} in
439 "module" )
440 echo "${tmp[3]} ${tmp[0]} ${tmp[2]} ${tmp[1]}"
442 "unit" )
443 echo "${tmp[3]} ${tmp[0]} ${tmp[2]} ${tmp[1]}"
445 "dir" )
446 echo "${tmp[3]} ${tmp[0]} ${tmp[2]} ${tmp[1]}"
448 esac
449 # fi
450 elif [[ ${#tmp[@]} == 3 ]]; then
451 if [[ "${tmp[2]}" == "sh" ]]; then
452 test_desc=`ls $file.*.txt`
453 [[ -z $test_desc ]] && echo "err: txt descript file not found for $file." >&2 && return 1
454 test_desc=${test_desc#$file\.}
455 test_desc=${test_desc%\.txt}
457 echo "item ${tmp[0]} $test_desc ${tmp[1]}"
460 done
462 test_list_depth=$((test_list_depth--))
467 # test_list_full_content <test_dir>
468 test_list_full_content ()
470 local tmp=
471 local test_dir=$1
473 cd $1
474 test_list_curr_content $test_dirs |
475 while read line; do
476 tmp=( $line )
477 case ${tmp[0]} in
478 "item" )
479 test_dir_level=$(( test_dir_level + 1 ))
480 TPREFIX=`printf "%*s" $(( $test_dir_level * 4)) " "`
481 # dbgout "test_dir_level = $test_dir_level\n"
483 echo -ne "$TPREFIX[item] ${tmp[1]} ${tmp[3]} ${tmp[2]}\n"
484 # test_item ${tmp[1]} ${tmp[3]} ${tmp[2]}
486 test_dir_level=$(( test_dir_level - 1 ))
487 TPREFIX=`printf "%*s" $(( $test_dir_level * 4)) " "`
489 "module" | "unit" | "dir" )
490 test_dir_level=$(( test_dir_level + 1 ))
491 TPREFIX=`printf "%*s" $(( $test_dir_level * 4)) " "`
492 # dbgout "test_dir_level = $test_dir_level\n"
494 echo -ne "$TPREFIX[${tmp[0]}] ${tmp[1]}.${tmp[2]}\n"
496 test_list_full_content ${tmp[1]}.${tmp[3]}.${tmp[2]}.${tmp[0]}
498 test_dir_level=$(( test_dir_level - 1 ))
499 TPREFIX=`printf "%*s" $(( $test_dir_level * 4)) " "`
501 esac
502 done
503 cd ..
506 # 这里以短参数、长参数、命令的顺序排列,否则解析时有异常。
507 usage_desc_str="
508 prog $0 '应用测试程序。用于对指定目录下的一系列测试脚本运行测试,并输出测试结果。如未指定测试目录参数,以当前目录下的testing目录作为默认测试信息目录,并进行测试。'
510 param -l --list --- = %<list_test_list> !<args_list_test_list> '列出testing目录下的测试单元/模块/目录,及测试项。'
511 param -d --dir --- =<test_dir> %<test_dir> ! '指定测试信息的目录。默认值为当前目录下的testing目录。'
512 param -s --save --- =<save_desc_file> %<save_desc_file> !<args_save_desc_file> '根据测试目录下的测试文件目录结构,生成测试信息描述文件。如果文件已存在,只显示提示信息。添加-f参数用于覆盖生成的文件。'
513 param -i --import --- =<import_desc_file> %<import_desc_file> !<args_import_desc_file> '根据测试信息描述文件,生成测试目录及测试脚本等文件,用于用户编写各种测试用例。'
515 param -t --test --- =<test_id> %<test_id> !<args_test_id> '根据指定测试编号运行测试脚本。用于测试目录下的所有测试脚本,'
516 '或指定一个测试脚本。当该参数不添加参数时,表示保存的起始id开始的单项测试。'
517 param -b --begin --- =<begin_test_id> %<begin_test_id> !<args_begin_test_id> '从该id值开始测试。'
518 param -e --end --- =<end_test_id> %<end_test_id> !<args_end_test_id> '测试到该id值为止。'
519 param -S --set --- = %<set_test_info> !<args_set_test_info> '保存-b和-e参数设置的测试范围。-n参数测试时在该范围内测试。'
520 param -R --rollup --- = %<test_id_rollup> !<args_test_id_rollup> '保存的测试起始编号加1,用于表示当前项测试后进入下一项测试。'
522 param -n --num --- =<test_cnt_num> %<test_cnt_num> ! '测试n项item。'
523 param -u --update --- = %<update_test_result_file> !<args_update_test_result_file> '该参数用于测试时,将测试脚本的输出更新到测试信息文件中。测试信息文件用于比较测试脚本输出是否正确。'
524 param -r --ignor-err --- = %<test_ignor_err> !<args_test_ignor_err> '当某一测试项报错时,忽略报错,运行其它测试项。'
525 param -V --verbose --- = %<verbose> !<args_verbose> '测试failed时,默认输出差异信息,使用该参数输出所有测试信息。'
527 param -p --print-vars --- = %<print_vars> !<args_print_vars> '输出参数定义的变量信息。'
528 param -m --mono --- = %<mono> !<args_mono> '输出非彩色的字符串信息。'
529 param -v --version --- = %<version_info> !<args_version_info> '程序的版本信息。'
530 param -h --help --- = %<help_info> !<help_info> '程序的参数helper信息。'
532 #param -a --all ---all = %<test_all> !<param_test_all> '测试所有模块。默认操作的参数。'
535 # 这里的注释不能删除,用于插入参数描述信息解析后的环境变量,以免程序初始化卡顿。
536 # args-var-define-begin
537 # args-var-define-end
542 args_list_test_list ()
544 local test_path=
546 if [[ ! -d $test_dir ]]; then
547 test_path=$test_dir
550 if [[ ! -d $test_path ]]; then
551 test_path=testing/
554 [[ ! -d $test_path ]] && echo "err: testing dir is not exist." && exit
556 echo "$FUNCNAME is invoked!"
558 test_list_full_content $test_path | more
560 exit
565 args_save_desc_file ()
567 echo "$FUNCNAME is invoked!"
569 [[ -z $1 ]] && return
571 args_list_test_list 2>&1 > $1
573 exit
577 # todo:
578 args_import_desc_file ()
580 local tmp
582 echo "$FUNCNAME is invoked!"
584 [[ -z $1 || ! -f $1 ]] && err "err: file ($1) does not exist.\n" && exit
586 test_list_depth=$((test_list_depth++))
588 # dbgout "curr content $1\n"
590 ls $1 | sort -n |
591 while read file; do
592 # 忽略.txt文件,在处理.sh文件时再进行处理
593 [[ -d $file ]] && continue
595 $item_proc $file
597 cd $file
598 foreach_dir $PWD/$file $item_proc
599 done
601 test_list_depth=$((test_list_depth--))
603 foreach_dir $1 import_desc_file_item_proc
605 exit
609 # todo:
610 args_test_id ()
612 local test_id
613 local id
614 local i
615 local cnt
616 local tmp
617 local curr_path=$PWD
619 local test_path=
621 if [[ ! -d $test_dir ]]; then
622 test_path=$test_dir
625 if [[ ! -d $test_path ]]; then
626 test_path=testing/
629 [[ ! -d $test_path ]] && echo "err: testing dir is not exist." && exit
631 echo "$FUNCNAME is invoked!"
633 OLD_IFS=$IFS
634 IFS="."
635 test_id=$1
636 test_id=( $test_id )
637 cnt=${#test_id[@]}
638 IFS=$OLD_IFS
640 cd $test_path
641 IFS="\n"
642 for (( i=0; i<cnt; i++ )); do
643 [[ -z ${test_id[$i]} ]] && err "err: test_id[$i] does not invalide.\n" && exit
644 id=${test_id[$i]}
645 tmp=( `ls -1 -d $id.*` )
646 dbgout "tmp=$tmp\n"
647 # ls -d $tmp
648 [[ -d $tmp ]] && cd $tmp && $tmp="" && continue
649 tmp=`ls $id.*.sh`
650 [[ -f $tmp ]] && break
651 done
653 dbgout "test_id=$test_id\n"
654 dbgout "i=$i\n"
655 dbgout "cnt=$cnt\n"
656 dbgout "tmp=$tmp\n"
657 if [[ $i == $cnt ]]; then
658 test_unit .
659 exit
662 dbgout "test path is $tmp\n"
663 # todo:这里可以改为测试一个unit
664 [[ -z $tmp ]] && err "err: test id ($1) does not specify a valide test item file.\n" && exit
666 tmp=`ls $id.*.txt`
667 [[ -z $tmp ]] && err "err: test id ($i) does not contain a corresponding txt description file.\n" && exit
669 OLD_IFS=$IFS
670 IFS="."
671 tmp=( $tmp )
672 IFS=$OLD_IFS
674 test_item ${tmp[0]} ${tmp[1]} ${tmp[3]}
676 exit
680 # todo:
681 args_begin_test_id ()
683 echo "$FUNCNAME is invoked!"
687 # todo:
688 args_end_test_id ()
690 echo "$FUNCNAME is invoked!"
694 # todo:
695 args_set_test_info ()
697 echo "$FUNCNAME is invoked!"
699 [[ -z $begin_test_id ]] && echo "请使用-b参数指定起始测试编号" && exit
700 [[ -z $end_test_id ]] && echo "请使用-e参数指定末尾测试编号" && exit
702 echo "[paramters]" > $TESTING_TMP_DIR/test_id.txt
703 echo "begin_test_id=$begin_test_id" >> $TESTING_TMP_DIR/test_id.txt
704 echo "end_test_id=$end_test_id" >> $TESTING_TMP_DIR/test_id.txt
708 # todo:
709 args_test_id_rollup ()
711 echo "$FUNCNAME is invoked!"
716 # args_update_test_result_file
717 args_update_test_result_file ()
719 echo "$FUNCNAME is invoked!"
721 update_test_result_file="true"
724 test_verbose=0
728 args_verbose ()
730 echo "$FUNCNAME is invoked!"
732 test_verbose="true"
733 IFCCOLOR="$FCBLUE"
739 args_print_vars ()
741 echo "$FUNCNAME is invoked!"
743 OptDescParamPrint
745 exit
750 # args_mono
751 args_mono ()
753 FCCOLOR=""
754 IFCCOLOR=""
755 EFCCOLOR=""
758 V1=0
759 V2=1
760 V3=0
761 VEXT=
764 # args_version_info
765 args_version_info ()
767 echo "version v$V1.$V2.${V3}$VEXT"
768 exit
772 # help_info
773 help_info ()
775 usage
776 exit
779 testing ()
781 local tmp
782 local test_path=
783 local xbegin_test_id=
784 local xend_test_idg=
786 init_dbgout 2 testing 20000
788 # todo
789 # ini文件加载环境变量
791 ProgOptDispatch "$@"
793 stdout "begin testing ... \n"
796 # 测试目录使用-d参数对应的test_dir环境变量
797 # 指定的目录作为测试信息目录。
798 # 默认为当前路径下的testing目录。
800 if [[ -n $test_dir ]]; then
801 if [[ -d $test_dir ]]; then
802 test_path=$test_dir
803 else
804 err "err: parameter -d specified a invalide path $test_dir\n"
805 exit
809 if [[ ! -d $test_path ]]; then
810 test_path=testing/
813 [[ ! -d $test_path ]] && err "err: testing dir is not exist.\n" && exit
815 # 测试id起止范围比较
816 # dbgout "begin_test_id=$begin_test_id\n"
817 # dbgout "end_test_id=$end_test_id\n"
819 if [[ -n $begin_test_id ]]; then
820 xbegin_test_id=$begin_test_id
821 begin_test_id=( "1" ${begin_test_id//./ } )
824 if [[ -n $end_test_id ]]; then
825 xend_test_id=$end_test_id
826 end_test_id=( "1" ${end_test_id//./ } )
829 cnt=${#begin_test_id[@]}
830 for (( i=0; i<cnt; i++)); do
831 [[ -z ${end_test_id[$i]} ]] && break
832 if [[ ${begin_test_id[$i]} -gt ${end_test_id[$i]} ]]; then
833 err "err: begin_test_id($begin_test_id) is larger then end_test_id($end_test_id).\n"
834 exit
835 elif [[ ${begin_test_id[$i]} -eq ${end_test_id[$i]} ]]; then
836 continue
837 else
838 break
840 done
842 # 测试起始范围递增1
843 if [[ $test_id_rollup == "enable" ]]; then
844 [[ -z $xbegin_test_id ]] && echo "请使用-b参数指定起始测试编号" && exit
846 dbgout "begin_test_id=${begin_test_id[@]}\n"
848 begin_test_id[$cnt]=$(( ${begin_test_id[$cnt]} + 1 ))
849 xbegin_test_id="${begin_test_id[@]}"
850 xbegin_test_id=${xbegin_test_id// /.}
851 set_test_info="enable"
853 stdout "begin_test_id rollup 1.\n"
856 # 保存-b -e参数指定的id
857 if [[ $set_test_info == "enable" ]]; then
858 # [[ -z $xbegin_test_id ]] && echo "请使用-b参数指定起始测试编号" && exit
859 # [[ -z $xend_test_id ]] && echo "请使用-e参数指定末尾测试编号" && exit
861 echo "[paramters]" > $TESTING_TMP_DIR/test_id.txt
862 [[ -z $xbegin_test_id ]] && echo "begin_test_id=${xbegin_test_id}" >> $TESTING_TMP_DIR/test_id.txt
863 [[ -z $xend_test_id ]] && echo "end_test_id=${xend_test_id}" >> $TESTING_TMP_DIR/test_id.txt
865 stdout "test id saved!\n"
867 # 测试id保存时,不进行测试,便于testcase中测试起止id编号
868 exit
871 # dbgout "begin_test_id=${begin_test_id[@]}\n"
872 # dbgout "end_test_id=${end_test_id[@]}\n"
874 stdout "test dir is \"$test_path\"\n"
876 # 指定测试信息目录的循环测试
877 test_unit $test_path
878 # echo main testing ret=$?
880 stdout "end testing ...\n"
881 if [[ $err_cnt != 0 ]]; then
882 stdout "$EFCCOLOR ($FCGREEN$test_cnt$EFCCOLOR) items is tested,Error count is ($FCGREEN$err_cnt$EFCCOLOR)$CNORMAL\n"
883 else
884 stdout "$FCGREEN ($test_cnt) items is tested,Error count is ($err_cnt)$CNORMAL\n"
888 main ()
890 testing "$@"
893 xxx=
896 main "$@"