14 Debugging
14 Debugging
#include <assert.h>
Assertions …
in C int f ( int a, int b) {
assert ((a > b) && (b != 0));
…
}
If condition is FALSE at run time, automatically prints the
following, and aborts execution:
c = getc(stdin);
assert(c == ‘A’);
Output
> a.out
x
test.c:15: failed assertion ‘c == ‘A’’
>
test theories
• Use a debugger
CSC326: Software Engineering © NC State Software Engineering Faculty Text © Rex Black L01 - 25
Example Bug Report
• Steps to Reproduce
– Test input file: in1
– Expected output: eout1
– % ./pgm < in1 >! aout1
– The actual results print 3, when we expect 2
• Isolation & Generalization
– The test focuses on the bounds of the input
– The program may make an incorrect check on input
– Also happens with new input file, in7, where the input value
considers another boundary value