1 CEN 4072 Software Testing PPT12: Fixing the defect.

Slides:



Advertisements
Similar presentations
Object Oriented Analysis And Design-IT0207 iiI Semester
Advertisements

Test process essentials Riitta Viitamäki,
11-Jun-14 The assert statement. 2 About the assert statement The purpose of the assert statement is to give you a way to catch program errors early The.
Delta Debugging and Model Checkers for fault localization
CSE 331 SOFTWARE DESIGN & IMPLEMENTATION DEBUGGING Autumn 2011 Bug-Date: Sept 9, 1947.
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
Chapter 3.5 Debugging Games
Applied Software Project Management INTRODUCTION Applied Software Project Management 1 5/20/2015.
Debugging Introduction to Computing Science and Programming I.
Debugging CPSC 315 – Programming Studio Fall 2008.
16/27/2015 3:38 AM6/27/2015 3:38 AM6/27/2015 3:38 AMTesting and Debugging Testing The process of verifying the software performs to the specifications.
Applied Software Project Management 1 Introduction Dr. Mengxia Zhu Computer Science Department Southern Illinois University Carbondale.
Test Preparation Strategies
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
University of Palestine software engineering department Testing of Software Systems Fundamentals of testing instructor: Tasneem Darwish.
Applied Software Project Management Andrew Stellman & Jennifer Greenehttp:// Applied Software Project Management Chapter 1: Introduction.
CS 501: Software Engineering Fall 1999 Lecture 16 Verification and Validation.
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
Tracking The Problem  By Aaron Jackson. What’s a Problem?  A suspicious or unwanted behavior in a program  Not all problems are errors as some perceived.
ICAPRG301A Week 4Buggy Programming ICAPRG301A Apply introductory programming techniques Program Bugs US Navy Admiral Grace Hopper is often credited with.
Testing CSE 140 University of Washington 1. Testing Programming to analyze data is powerful It’s useless if the results are not correct Correctness is.
Program Development Life Cycle (PDLC)
Chapter 3 (Part 3): Mathematical Reasoning, Induction & Recursion  Recursive Algorithms (3.5)  Program Correctness (3.6)
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 4 (Part 3): Mathematical Reasoning, Induction.
Bug Localization with Machine Learning Techniques Wujie Zheng
Testing -- Part II. Testing The role of testing is to: w Locate errors that can then be fixed to produce a more reliable product w Design tests that systematically.
How Failures Come To Be By: Blake Burton. Golden rule: Software testing begins with careful design Modularity of your code is a big part in software testing.
CEN 4072 Software Testing Chapter 1: How Failures Come To Be.
Dr. Tom WayCSC Testing and Test-Driven Development CSC 4700 Software Engineering Based on Sommerville slides.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
DEBUGGING. BUG A software bug is an error, flaw, failure, or fault in a computer program or system that causes it to produce an incorrect or unexpected.
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
Software Engineering Chapter 3 CPSC Pascal Brent M. Dingle Texas A&M University.
Making Good Code AKA: So, You Wrote Some Code. Now What? Ray Haggerty July 23, 2015.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
CS101 Computer Programming I Chapter 4 Extra Examples.
BMTRY 789 Lecture 11: Debugging Readings – Chapter 10 (3 rd Ed) from “The Little SAS Book” Lab Problems – None Homework Due – None Final Project Presentations.
What is Testing? Testing is the process of finding errors in the system implementation. –The intent of testing is to find problems with the system.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Fixing the Defect CEN4072 – Software Testing. From Defect to Failure How a defect becomes a failure: 1. The programmer creates a defect 2. The defect.
Scientific Debugging. Errors in Software Errors are unexpected behaviors or outputs in programs As long as software is developed by humans, it will contain.
PRESENTER PRIYANKA GUPTA.  Testing the complete system with respect to requirements.  In System testing, the functionalities of the system are tested.
PPT12: Fixing the Defect Software Testing - CEN 4072.
CSC 480 Software Engineering Test Planning. Test Cases and Test Plans A test case is an explicit set of instructions designed to detect a particular class.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
CompSci 100E 18.1 Testing and Debugging Robert A Wagner.
Teaching slides Chapter 9. Chapter 9 Software Testing (Verification & Validation) Introduction Software testing & software engineering methodologies Introduction.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Flow of Control: Loops Module 4. Objectives Design a loop Use while, do, and for in a program Use the for-each with enumerations Use assertion checks.
Testing Overview Software Reliability Techniques Testing Concepts CEN 4010 Class 24 – 11/17.
Defensive Programming. Good programming practices that protect you from your own programming mistakes, as well as those of others – Assertions – Parameter.
Foundations of Software Testing Chapter 5: Test Selection, Minimization, and Prioritization for Regression Testing Last update: September 3, 2007 These.
Chapter 4 (Part 3): Mathematical Reasoning, Induction & Recursion
Regression Testing with its types
John D. McGregor Session 9 Testing Vocabulary
Testing and Debugging PPT By :Dr. R. Mall.
Logger, Assert and Invariants
Aditya P. Mathur Purdue University
SwE 455 Program Slicing.
John D. McGregor Session 9 Testing Vocabulary
John D. McGregor Session 9 Testing Vocabulary
CSCE 315 – Programming Studio, Fall 2017 Tanzir Ahmed
PPT and video are due: no later than November 16, 5:00 PM
PPT1: How failures come to be
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
Welcome to Corporate Training -1
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
An Introduction to Debugging
Announcements Lab 3 was due today Assignment 2 due next Wednesday
Presentation transcript:

1 CEN 4072 Software Testing PPT12: Fixing the defect

2 From defect to failure How does a defect in a program become a failure? When a defect causes an infection (erroneous program state) that is visible to the user Not all defects lead to failures –Nevertheless a defect is an erroneous piece of code and should be fixed How to locate the defect that leads to a given failure? 1.Start with the infected value that defines the failure 2.Determine the possible origins of the infected value, following dependencies in the code 3.Observe each origin to determine whether it is infected or not –Restart at step 2 with the infected origin(s) The above process will loop until an infection is found that has all sane origins The code that produces this infection is the defect that caused the failure

3 Techniques for locating defects Infections If an assertion fails Dependences Identify what the value of a variable is dependent on –Example: average = sum / count The value of average is dependent on sum and count Causes Identify causes through experimentation –The likelihood of finding a defect near a cause is very high Anomalies Identify states that only occur in failing runs –Example: if function getSum() only run on failing runs the likelihood that the defect is closely related to this anomaly is high Code Smells Identify constructs in the code that are known to cause errors –Example: initialized variables These do not necessarily cause errors, but they do at a very high rate

4 Focusing on errors Reduce defect search time Focus search on origins that are more likely to cause errors Assertions Guarantee the sanity of data over time on any program run –If an assertion fails then an infection has been identified –Else anything covered by the assertion can be ignored in the search Because it is known to be in a sane state Anomalies Aspects of the program that correlate with failure –Example: a certain function only runs on failing runs –This correlation to failure means that it is wise to focus on these Causes Not only correlate to failure, but have been experimentally proven to cause the failure –These origins are even more likely than anomalies to indicate the defect

5 Focusing on errors Focus on Infections If an origin is known to be faulty then focus on it first –Check whether or not the infection causes the failure Focus on Causes If some form of experimentation has shown some state or input to be a failure cause –Check if the cause is infected Focus on Anomalies Any origin that is associated with an anomaly has a good chance to contain errors –Check if these origins are infected Focus on Code Smells If code smells have been identified and the origin is one of these code smells –Check if the code smell causes the infection and/or error Focus on Dependences If all the above fail to find the defect, then the defect must be found in some dependency –For all of the possible origins, check the backward slice for an infection Start with the origins nearest the failure

6 Techniques: dependences Starting from the failure, follow dependences to find possible origins of the defect

7 Techniques: observation Observe the state of an origin and decide whether or not it is infected

8 Techniques: assertion Use assertions to determine whether a given origin is sane or not Note that a single assertion can cover multiple origins as seen below

9 Techniques: anomaly Here there are two origins to choose from One of them is observed to be an anomaly so it is focused

10 Techniques: cause transition Here a cause transition is identified This is known because of the fact that the target is infected but the origin is sane

11 Techniques: defect found The defect has now been identified

12 Techniques: TRAFFIC strategy The techniques explained above follow the TRAFFIC strategy Specifically, the “focus on likely origins” step TRAFFIC strategy Track the problem Reproduce Automate Find origins Focus on likely origins Isolate Correct

13 Techniques: ordering The order in which to apply the aforementioned techniques is as follows 1.Focus on infections 2.Focus on causes 3.Focus on anomalies 4.Focus on code smells 5.Focus on dependences This ordering is chosen so that the techniques that are more likely to find a defect are applied before the techniques that are less likely to find a defect

14 Is the error a cause? Just because an error has been found does not mean that the error causes the failure When tracing an infection chain it must be shown at each step that 1.The origin is infected 2.The origin causes the infection chain Example: a = compute_value(); printf("a = %d\n", a); If the output of the program is always “a = 0” Then it may be assumed that the defect is related to the compute_value() function This can be shown to be false by manually setting a = 1 right before the print –If the program still outputs “a = 0” when a is known to not be 0 Then the problem must be with the print statement If this manual check had not occurred –Then the tester would search through origins where the cause does not exist Some error may be found in this search; however, this error is not the cause

15 Does making symptoms disappear fix the error? Simply making the symptoms of an error disappear does not mean that the error has been fixed Example: balance[account] = 0.0; for (int i = 0; i < n; i++) balance[account] += deposit[i] Assume that account 123 has an incorrect balance The following makes the symptom disappear but does not fix the true error if (account == 123) balance[123] += 45.67

16 Debugging into existence Changing the code to make it work without understanding the cause Example: static void shell_sort(int a[], int size) { int i, j; int h = 1; do { h = h * 3 + 1; } while (h <= size); do { h /= 3; for (i = h; i < size; i++) { int v = a[i]; for (j = i; j >= h && a[j - h] > v; j -= h) a[j] = a[j - h]; if (i != j) a[j] = v; } } while (h != 1); } Assume that the fix for this program was to change the highlighted line to instead be the following for (i = h; i < size - 1; i++) This change was made based off a guess that the loop bound was off by one. There was no testing to prove this to be the case. This is wrong because it is unknown whether or not the true error was fixed. This technique of debugging with guesses is dangerous because it can introduce new bugs into the program.

17 Devil’s guide to debugging Find the defect by guessing Scatter debugging statements throughout the program Try changing code until something works Do not back up old versions of the code Do not bother understanding what the program should do Do not waste time understand the problem Most problems are trivial anyways Use the most obvious fix Just fix what you see Example: x = compute(y) // compute(17) is wrong – fix it if (y == 17) x = x = Why bother tracing the error through compute()? Just fix it ! These are all techniques that should be fully avoided

18 Correcting the defect Before applying the correction to the code you must always first BACKUP THE CODE After correcting the code there are four problems that must be looked at 1.Does the failure no longer occur? –If the failure no longer occurs then the correction was successful –If the failure is still present then there are two possible reasons 1.The failure was caused by more than one defect and only one was fixed 2.Your understanding of the infection chain was wrong 2.Did the correction introduce new problems? –A few practices that are useful for this question 1.Have corrections peer reviewed 2.Have a regression test ready to detect unwanted changes

19 Correcting the defect 3.Was the same mistake made elsewhere? –Check for other defects that are caused by the same mistake Focus on –Code from the same developer –Code involving the same API 4.Did I commit the change? –Assign resolution to the problem (such as FIXED) –Integrate the fix into the production code

20 Workarounds Why might workarounds be needed? 1.Unable to change –The source code may not be available to be changed 2.Risks –The correction may induce huge risks Such as if the fix implies large changes throughout the system 3.Flaw –The problem may not be in the code but the overall design of the program In which case the system design must undergo a major revision Under what circumstances are workarounds allowed? If no better solution is known –Workarounds are meant to be temporary fixes –Be sure to keep the problem open so that a true fix may one day be found

21 Famous workarounds 1.Spam filters –Workaround for solving a flaw in the system Anyone can forge messages and conceal their true identity –Proper solution would involve reworking the entire system 2.Virus scanners –Privilege level flaw in operating systems By default a user has admin rights Means that any download can gain complete control of the machine –Proper solution would be to limit user rights Problem is that too many regular programs assume admin privileges 3.Date windowing –Inability of many legacy systems to deal with four-digit years –Resolves ambiguity of two-digit year by defining a 100-year window –Proper solution would require adapting legacy systems Too much cost and risk involved

22 Learning from mistakes Improve quality assurance –Introduce systematic processes to obtain program requirement and design –Check specifications early Find differences in what the developers think the program should do and what the clients want the program to do Resolving these issues early leads to requirements being more precise Improve test suite –If the test suite failed to find the defect Once the defect has been found the test suite should be extended to test for the new defect Setup assertions –Can narrow down the infection chain of a failure –Will catch similar infections in the future Improve the software process –Plan the software carefully before starting Improve analysis tools –Verify whether common tools could have found the defect early Particularly tools that detect code smells or verify system assertions

23 Facts on fixes The size of fixes with respect to other changes –Fixes are typically two to three times smaller than other changes Fixes and failures –Fixes are more likely to induce failures than other changes Fixes and older modules –A module that is one year older than another has 30 percent less errors Newly written code versus old code –Newly written code is 2.5 times as likely to contain a defect than old code

24 References Zeller, Andreas. Why Programs Fail. Second edition. Chapters 15 and 16.