linux白盒测试流程(4)

发表于:2015-03-25来源:uml.org.cn作者:不详点击数: 标签:linux
return 0 ; -: 27 :} 分析这个文件说明目前的代码覆盖率是100.00%。为了简化流程,写了个脚本完成上述任务。 $cat flow.sh # !/ bin / sh output_key_word = check case_key_w
return 0;
-: 27:}

  分析这个文件说明目前的代码覆盖率是100.00%。为了简化流程,写了个脚本完成上述任务。

  $cat flow.sh

#!/bin/sh

output_key_word='check'
case_key_word='Case'

usage()
{
echo "Usage : flow.sh file_name"
exit;
}

# input file is $1.res
# output file is $2.ver
#
generate_ver()
{
echo --------------------------------------- > $2
echo -e "\tTest Results Summary\n" >> $2
echo -e -n "Total Number of Comparisons\t\t:\t" >> $2
comparison_nums=`grep -r $output_key_word $1 | cut -f2 | wc -l`
echo -e "$comparison_nums" >> $2

echo -e -n "Total Number of Comparisons Failed\t:\t" >> $2
failed_nums=`grep -r $output_key_word $1 | cut -f2 | grep -r '= 0'| wc -l`
echo -e "$failed_nums" >> $2

echo -e -n "Total Number of Comparisons Passed\t:\t" >> $2
passed_nums=`expr $comparison_nums - $failed_nums`
echo -e "$passed_nums" >> $2

echo -e -n "Total Number of Test Cases Included\t:\t" >> $2
case_nums=`grep -r $case_key_word $1 | wc -l`
echo -e "$case_nums" >> $2

echo >> $2
echo -e -n "Percentage of Comparisons Passed\t:\t">>$2
percentage=`awk 'BEGIN{print '$passed_nums'/'$comparison_nums'}'`
echo -e "$percentage" >> $2
echo >> $2

echo --------------------------------------- >> $2

}

[ $# -ne 1 ] && usage

# Clean
rm -f *.gcno *.gcda *.c.gcov
rm -f *.ver *.rpt *.res

# Complier
gcc -fprofile-arcs -ftest-coverage -g -o $1 $1.c

# Debug
[ -e $1.gdb ] && gdb -x $1.gdb > $1.res

# Test Result Report
generate_ver $1.res $1.ver
[ -e $1.ver ] && echo "Generate VER file successfully!"

# Code Coverage Report
gcov $1.c > $1.rpt
[ -e $1.c.gcov ] && cat $1.c.gcov >> $1.rpt
[ -e $1.rpt ] && echo "Generate RPT file successfully!"

原文转自:http://www.uml.org.cn/Test/2009021210.asp