linux白盒测试流程(2)

发表于:2015-03-25来源:uml.org.cn作者:不详点击数: 标签:linux
如何结合gdb和gcov进行白盒测试?主要有两个阶段: 1.编译程序,执行gdb调试脚本。 在编译程序的时候加上-fprofile-arcs -ftest-coverage参数。所以这里运行 gcc

  如何结合gdb和gcov进行白盒测试?主要有两个阶段:

  1.编译程序,执行gdb调试脚本。

  在编译程序的时候加上-fprofile-arcs -ftest-coverage参数。所以这里运行

  gcc -fprofile-arcs -ftest-coverage -g -o calnumber calnumber.c

  gdb的命令参数-x可以从文件读出gdb调试命令再执行。运行

  gdb -x calnumber.gdb > calnumber.res

  下面是gdb脚本的输出:

  $cat calnumber.res

GNU gdb 6.5.50.20060706-cvs (cygwin-special)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i686-pc-cygwin".

---------------------
Test Case 1

Breakpoint 1 at 0x401083: file calnumber.c, line 4.

Breakpoint 1, main () at calnumber.c:4
4 {
Breakpoint 2 at 0x401096: file calnumber.c, line 9.

Breakpoint 2, main () at calnumber.c:9
9 for(i = 0; i <= number; i++)
"check number == 8" $1 = 1
"check sum == 0" $2 = 1
"set number = 4" $3 = 4
Breakpoint 3 at 0x4010c2: file calnumber.c, line 14.

Breakpoint 3, main () at calnumber.c:14
14 if(sum != 36)
"set sum = 10" $4 = 10
Breakpoint 4 at 0x401121: file calnumber.c, line 24.

Breakpoint 4, main () at calnumber.c:24
24 if(quit) printf("Finish!\n");
"check quit == 0" $5 = 1
"check i == 5" $6 = 1
"check sum == 10" $7 = 1
sum = 10

Program exited normally.

---------------------
Test Case 2

Breakpoint 5 at 0x401083: file calnumber.c, line 4.

Breakpoint 5, main () at calnumber.c:4
4 {
Breakpoint 6 at 0x401121: file calnumber.c, line 24.

Breakpoint 6, main () at calnumber.c:24
24 if(quit) printf("Finish!\n");
"check i == 9" $8 = 1
"check sum == 36" $9 = 1
"check quit == 1" $10 = 1
sum is 36

Program exited normally.

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