Software Testing Debugging Techniques Slides PDF
Document Details
Uploaded by VibrantSwamp
Kaveh Eshraghian
Tags
Summary
These slides provide information about software testing and debugging. They cover different types of errors, debugging processes and techniques, and also offer troubleshooting tips.
Full Transcript
Software Testing Debugging Instructor: Kaveh Eshraghian Overview Debugging Definition Debugging Process Types of Errors Debugging Techniques Debugging Clues Debugging Definition: The process of identifying and removing errors/bugs from computer software/hardware....
Software Testing Debugging Instructor: Kaveh Eshraghian Overview Debugging Definition Debugging Process Types of Errors Debugging Techniques Debugging Clues Debugging Definition: The process of identifying and removing errors/bugs from computer software/hardware. How: Using print statements Creating and reviewing log files Using an interactive debugger Debugging Process Start Gather Evidence Failed Passed Test Interpret Done Code Evidence Fix Bug Types of Errors You code does not follow rules of the language. Syntactic Detected and reported at compile time. errors Easy to fix. Logic errors in the running program. Semantic More difficult to find and fix. errors Requires the use of debugging techniques. Requirements We are building the wrong program. errors Clarify requirements. Syntactic Errors Errors Warnings Severe and stop compilation Do not stop compilation Need to be corrected before Indicates that something unusual continuing has been found Often points to a possible semantic error Should NOT be ignored Programmers should strive for a program with no warnings Linker Errors Defi nition: Linker errors are mismatches between the compiled symbols and the libraries that use them. functions.c Compiler functions.obj Textually included functions.h Linker main.exe Textually included main.c Compiler main.obj Declaration Vs Definition the name of the function. Declaration: the number and type of the parameters. the type returned by the function. what the function does. Definition: what the linker is looking for. Extern Declarations Declaration Definition #ifndef HEADER_H #ifndef HEADER_H #define HEADER_H #define HEADER_H // declares type of n // allocates memory for n extern int n; int n; #endif #endif Debugging Techniques When debugging you need to know: Where the program was executing when the bug occurred, Whether the point of termination of the program was where the bug occurred If the program produced incorrect results, where is the bug? How did this line of code ever get executed? What are the values of the variables as the program executes? Debugging Clues Most Common Reasons of bugs: Segmentation Faults Bus Error Random Behavior Program Executing Wrong Code Variable Changing Value Working on some Compilers Program Stopping Unexpectedly Memory Errors Numeric Problems Non-Zero Return Code Segmentation Faults Definition: A program attempting to access memory that has been not allocated to it. Outcome: Generates segmentation fault. Normally results in termination. Most Common Reasons: Subscripts which run off the end of an array. A pointer containing an invalid address. A NULL pointer. An uninitialized variable. Accessing memory which has been deallocated. Bus Error Definition: A program attempting to access illegal memory/ memory which does not exist. Outcome: Same as segmentation fault Random Behavior Problem Definition: A program behaving differently on every execution of the software. Outcome: Unexpected behavior on every launch. Most Common Reasons: Uninitialized Variables, caused by accessing random memory. Executing Wrong Code Problem Definition: Program is executing code that it should not have been executing. Outcome: Part of a stack trace missing. Most Common Reasons: Bad pointer Variable Changing Value Problem Definition: A variable within the program is changing its value on Its own. Most Common Reasons: Running off the end of an array Using a bad pointer Working on Some Compilers Problem Definition: Programs behave differently on different compilers and OS. Most Common Reasons: Different compilers in different OS do different things. Windows zeros memory, while Unix does not. Different memory allocation and layout Program Stopping Unexpectedly Problem Definition: program stops in the middle of execution for no reason. Most Common Reasons: Might have handled an exception or a signal. Used a try-catch and done nothing with it. Memory Layout Application memory is broken into 4 main parts: Memory Layout Issues 1. Out of stack Space a) Storing a very large number of local variables or large arrays as local variables inside the functions. b) A case of infinite recursion. 2. Out of Heap Memory a) Allocating too much memory b) Memory leak Numeric Problems List of numeric Problems: Incorrect Results - might used integer arithmetic and lost the fractional part of a number. Results start OK but then change sign - Numbers are stored such that if a number gets too big, it wraps around and becomes negative. The problem is that you are using too small a type to store the number. Inf - this means that the result of the calculation is infinity. Look for division by zero or other arithmetic problem NaN - Not a Number. Often due to divide by zero but might be for another reason. Regardless, the value is not a valid number Prints a strange value - Check your format codes to make sure you are not printing an int as a float or similar type problem in a printf. Non-Zero Return Code Problem Definition: Non-zero return codes are normally used for failure cases. Most common reasons: Divide by zero Out of memory Review: Try running the code and stopping at various points until you hit the bug. This might give a clue as to where it is occurring. Repeatedly narrow it down until you find the line on which it occurs.