71
Software Engineering 1 N.L. Hsueh, SE-Lab IECS FCU Software Testing N.L. Hsueh

92 SE-Testing.ppt

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: 92 SE-Testing.ppt

Software Engineering

1N.L. Hsueh, SE-Lab IECS FCU

Software Testing

N.L. Hsueh

Page 2: 92 SE-Testing.ppt

Software Engineering

2N.L. Hsueh, SE-Lab IECS FCU

Testing

Testing is the process of exercising a program with the specific intent of finding errors prior to delivery to end users

Principles All tests should be traceable to customer requirements Tests should be planned long ago before testing begins The Pareto principle applies to software testing

80% errors uncovered during testing will likely be traceable to 20% of all programs

Testing should begin “in the small” and progress toward testing “in the large”

Exhaustive testing is not possible To be more effective, testing should be conducted by an

independent third party

Page 3: 92 SE-Testing.ppt

Software Engineering

3N.L. Hsueh, SE-Lab IECS FCU

Testability

Operability E.g., No bugs block the execution of tests

Observability Distinct output is generated for each input Internal errors are automatically reported Source do is accessible

Controllability Software and hardware states and variable can be controlled directly by t

he test engineering Decomposability

The software system is built from independent modules Simplicity

Code simplicity Stability

Changes to the software are infrequent Understandability

The design is well-understood Documentation is instantly accessible

Page 4: 92 SE-Testing.ppt

Software Engineering

4N.L. Hsueh, SE-Lab IECS FCU

Basic Concept

Verification and Validation Dynamic and Static Statistical and Defect Reliability achievement Test Plan Test Process

Page 5: 92 SE-Testing.ppt

Software Engineering

5N.L. Hsueh, SE-Lab IECS FCU

Verification: "Are we building the product right" The software should conform to its specification

Validation: "Are we building the right product" The software should do what the user really requires

Process Is a whole life-cycle process - V & V must be applied at

each stage in the software process. Has two principal objectives

The discovery of defects in a system

The assessment of whether or not the system is usable in an operational situation.

Verification vs validation

Page 6: 92 SE-Testing.ppt

Software Engineering

6N.L. Hsueh, SE-Lab IECS FCU

Dynamic Testing Concerned with exercising and observing product

behavior (testing)

Static Testing Concerned with analysis of the static system

representation to discover problems

Dynamic and Static Testing

Page 7: 92 SE-Testing.ppt

Software Engineering

7N.L. Hsueh, SE-Lab IECS FCU

Static and dynamic testing

Formalspecification

High-leveldesign

Requirementsspecification

Detaileddesign

Program

PrototypeDynamicvalidation

Staticverification

Page 8: 92 SE-Testing.ppt

Software Engineering

8N.L. Hsueh, SE-Lab IECS FCU

Statistical testing used for reliability estimation. related to software reliability tests designed to reflect the frequencies of user inputs

Defect testing Tests designed to discover system defects A successful defect test is one which reveals the

presence of defects in a system.

Defect testing and debugging are distinct processesDefect testing is concerned with confirming the presence

of errorsDebugging is concerned with locating and repairing these

errors

Statistical vs. Defect

Page 9: 92 SE-Testing.ppt

Software Engineering

9N.L. Hsueh, SE-Lab IECS FCU

Reliability achievement

Fault avoidance Development technique are used that either minimise the

possibility of mistakes or trap mistakes before they result in the introduction of system faults

Fault detection and removal Verification and validation techniques that increase the

probability of detecting and correcting errors before the system goes into service are used

Fault tolerance Run-time techniques are used to ensure that system faults

do not result in system errors and/or that system errors do not lead to system failures

Page 10: 92 SE-Testing.ppt

Software Engineering

10N.L. Hsueh, SE-Lab IECS FCU

Unit testing testing of individual components

Module testing testing of collections of dependent components

Sub-system testing testing collections of modules integrated into sub-

systems System testing

testing the complete system prior to delivery Acceptance testing

testing by users to check that the system satisfies requirements. Sometimes called alpha testing

Testing stages

Page 11: 92 SE-Testing.ppt

Software Engineering

11N.L. Hsueh, SE-Lab IECS FCU

The testing process

Sub-systemtesting

Moduletesting

Unittesting

Systemtesting

Acceptancetesting

Componenttesting

Integration testing Usertesting

Page 12: 92 SE-Testing.ppt

Software Engineering

12N.L. Hsueh, SE-Lab IECS FCU

The test plan

The testing process Define major phases of the testing process

Requirements traceability All requirements are individually tested

Tested items What are to be tested?

Testing schedule Link to project development schedule

Test recording procedures Record the results in a systematic way

Hardware and software requirements Constraints

Page 13: 92 SE-Testing.ppt

Software Engineering

13N.L. Hsueh, SE-Lab IECS FCU

The V-model of development

Requirementsspecification

Systemspecification

Systemdesign

Detaileddesign

Module andunit codeand tess

Sub-systemintegrationtest plan

Systemintegrationtest plan

Acceptancetest plan

ServiceAcceptance

testSystem

integration testSub-system

integration test

Page 14: 92 SE-Testing.ppt

Software Engineering

14N.L. Hsueh, SE-Lab IECS FCU

Testing Strategies

Page 15: 92 SE-Testing.ppt

Software Engineering

15N.L. Hsueh, SE-Lab IECS FCU

Testing strategies

Testing strategies are ways of approaching the testing process

Different strategies may be applied at different stages of the testing process

Strategies covered Top-down testing: starting with the most abstract Bottom-up testing: starting with the fundamental

component Thread testing Stress testing: how well the system can cope with

overload situations Whenever testing strategy is adopted, it is always sensible

to adopt an incremental approach to subsystem and system testing

Page 16: 92 SE-Testing.ppt

Software Engineering

16N.L. Hsueh, SE-Lab IECS FCU

Incremental testing

T3

T2

T1

T4

T5

A

B

C

D

T2

T1

T3

T4

A

B

C

T1

T2

T3

A

B

Test sequence1

Test sequence2

Test sequence3

moduletesting

Page 17: 92 SE-Testing.ppt

Software Engineering

17N.L. Hsueh, SE-Lab IECS FCU

Top-down testing

Level 2Level 2Level 2Level 2

Level 1 Level 1Testing

sequence

Level 2stubs

Level 3stubs

. . .

Page 18: 92 SE-Testing.ppt

Software Engineering

18N.L. Hsueh, SE-Lab IECS FCU

Top-down testing

Start with the high-levels of a system and work your way downwards

Testing strategy which is used in conjunction with top-down development finds architectural errors It demonstrates the feasibility of the system to

management Validation can begin early in the testing process

May need system infrastructure before any testing is possible

May be difficult to develop program stubs Consider a function which relies on the conversion of

an array of objects into a linked list, this stub is not easy to do

Page 19: 92 SE-Testing.ppt

Software Engineering

19N.L. Hsueh, SE-Lab IECS FCU

Bottom-up testing

Level NLevel NLevel NLevel NLevel N

Level N–1 Level N–1Level N–1

Testingsequence

Testdrivers

Testdrivers

Page 20: 92 SE-Testing.ppt

Software Engineering

20N.L. Hsueh, SE-Lab IECS FCU

Bottom-up testing

Necessary for critical infrastructure components Start with the lower levels of the system and work upward Needs test drivers to be implemented Does not find major design problems until late in the process Appropriate for object-oriented systems

Page 21: 92 SE-Testing.ppt

Software Engineering

21N.L. Hsueh, SE-Lab IECS FCU

Thread testing

Suitable for real-time and object-oriented systems Based on testing an operation which involves a sequence of

processing steps which thread their way through the system Start with single event threads then go on to multiple event

threads Complete thread testing is impossible because of the large

number of event combinations

Page 22: 92 SE-Testing.ppt

Software Engineering

22N.L. Hsueh, SE-Lab IECS FCU

Process interactions

P2

P1

P5

P4

I1 (P2)

O2 (P4)

O1(P5)

I2 (P1)

I1 (P1)

I3 (P1)

P3I1 (P3) O1 (P4)

Page 23: 92 SE-Testing.ppt

Software Engineering

23N.L. Hsueh, SE-Lab IECS FCU

Thread testing

P2P3 P4 O1(P4)

I1(P3)

P2P1 P5 O1(P5)

I2(P1)

I1(P1)

I3(P1)

Page 24: 92 SE-Testing.ppt

Software Engineering

24N.L. Hsueh, SE-Lab IECS FCU

Multiple-thread testing

P2P1 P5

P4

I1 (P2)

O2 (P4)

O1 (P5)I2 (P1)

I1 (P1)

I3 (P1)

Page 25: 92 SE-Testing.ppt

Software Engineering

25N.L. Hsueh, SE-Lab IECS FCU

Exercises the system beyond its maximum design load until the system fails

Stressing the system often causes defects to come to light Systems should not fail catastrophically Particularly relevant to distributed systems which can exhibit

severe degradation as a network becomes overloaded

Stress testing

Page 26: 92 SE-Testing.ppt

Software Engineering

26N.L. Hsueh, SE-Lab IECS FCU

Defect Testing

Page 27: 92 SE-Testing.ppt

Software Engineering

27N.L. Hsueh, SE-Lab IECS FCU

Defect testing

The objective of defect testing is to discover defects in programs

A successful defect test is a test which causes a program to behave in an anomalous way

Tests show the presence not the absence of defects

Test data Inputs which have been devised to test the system

Test cases Inputs to test the system and the predicted outputs

from these inputs if the system operates according to its specification

Page 28: 92 SE-Testing.ppt

Software Engineering

28N.L. Hsueh, SE-Lab IECS FCU

The defect testing process

Design testcases

Prepare testdata

Run programwith test data

Compare resultsto test cases

Testcases

Testdata

Testresults

Testreports

Page 29: 92 SE-Testing.ppt

Software Engineering

29N.L. Hsueh, SE-Lab IECS FCU

Defect testing approaches

Interfacetesting

Functionaltesting

Structuraltesting

Sub-systemSystemUnit andmodule

Testingteam

Developmentteam

Black-box testing White-box testing

Page 30: 92 SE-Testing.ppt

Software Engineering

30N.L. Hsueh, SE-Lab IECS FCU

Functional (black-box) testing

Approach to testing where the program is considered as a ‘black-box’

The program test cases are based on the system specification

Test planning can begin early in the software process

input output

Page 31: 92 SE-Testing.ppt

Software Engineering

31N.L. Hsueh, SE-Lab IECS FCU

Black-box testing

Ie

Input test data

OeOutput test results

System

Inputs causinganomalousbehaviour

Outputs which revealthe presence ofdefects

Page 32: 92 SE-Testing.ppt

Software Engineering

32N.L. Hsueh, SE-Lab IECS FCU

Input equivalence partitions are sets of data where the set members should all be processed in an equivalent way by the program

The partitioning is identified by a tester using experience to predict which classes of input value are likely to detect errors

Partition system inputs into ‘equivalence sets’ If input is a 5-digit integer between 10,000 and 99,999,

equivalence partitions are <10,000, 10,000-99,999 and > 10, 000

Choose test cases at the boundary of these sets: 00000, 09999, 10000, 99999, 10001

Partition system input into ‘equivalence sets’ Output partitions (<10, 10-20, >20)

Design input values to output values located in partition 1, 2, and 3, respectively

Equivalence partitioning

Page 33: 92 SE-Testing.ppt

Software Engineering

33N.L. Hsueh, SE-Lab IECS FCU

Equivalence partitioning

Input partition Output partition

Final partition

Page 34: 92 SE-Testing.ppt

Software Engineering

34N.L. Hsueh, SE-Lab IECS FCU

Search routine specification

procedure Search (Key : ELEM ; T: ELEM_ARRAY; Found : in out BOOLEAN; L: in out ELEM_INDEX) ;

Pre-condition-- the array has at least one elementT’FIRST <= T’LAST

Post-condition-- the element is found and is referenced by L( Found and T (L) = Key)

or -- the element is not in the array( not Found and

not (exists i, T’FIRST >= i <= T’LAST, T (i) = Key ))

In black-box testing, testing is based on specification

Page 35: 92 SE-Testing.ppt

Software Engineering

35N.L. Hsueh, SE-Lab IECS FCU

Inputs which conform to the pre-conditions Inputs where a pre-condition does not hold Inputs where the key element is a member of the array Inputs where the key element is not a member of the array

Search routine - input partitions

Page 36: 92 SE-Testing.ppt

Software Engineering

36N.L. Hsueh, SE-Lab IECS FCU

Testing guidelines (arrays)

Test software with arrays which have only a single value Programmers naturally think of arrays as a sequence

of values and sometimes they embed this assumption in their programs

Use arrays of different sizes in different tests even, and odd number of size

Derive tests so that the first, middle and last elements of the array are accessed To reveal boundary effects

Test with arrays of zero length (if allowed by programming language)

Page 37: 92 SE-Testing.ppt

Software Engineering

37N.L. Hsueh, SE-Lab IECS FCU

Search routine – input partitions

Array ElementSingle value In arraySingle value Not in arrayMore than 1 value First element in arrayMore than 1 value Last element in arrayMore than 1 value Middle element in arrayMore than 1 value Not in array

Input array (T) Key (Key) Output (Found, L)17 17 true, 117 0 false, ??17, 29, 21, 23 17 true, 141, 18, 9, 31, 30, 16, 45 45 true, 617, 18, 21, 23, 29, 41, 38 23 true, 421, 23, 29, 33, 38 25 false, ??

test casesExpected output

Page 38: 92 SE-Testing.ppt

Software Engineering

38N.L. Hsueh, SE-Lab IECS FCU

Bugs lurk in corners and congregate at boundaries

Boris Beizer

Page 39: 92 SE-Testing.ppt

Software Engineering

39N.L. Hsueh, SE-Lab IECS FCU

Structural testing

Page 40: 92 SE-Testing.ppt

Software Engineering

40N.L. Hsueh, SE-Lab IECS FCU

Sometime called white-box testing Derivation of test cases according to program structure Objective is to exercise all program statements Knowledge of the program is used to identify additional test

cases By examining the code of the search routine, we can

see that binary searching involves splitting the search space into three parts

Each of these parts makes up an equivalence partition Test cases where the key lies at the boundaries of

each of these partitions should be chosen to exercise the code

Structural testing

Page 41: 92 SE-Testing.ppt

Software Engineering

41N.L. Hsueh, SE-Lab IECS FCU

void Binary_search (elem key, elem* T, int size, boolean &found, int &L){

int bott, top, mid ;bott = 0 ; top = size -1 ;L = ( top + bott ) / 2 ;if (T[L] == key)

found = true ;else

found = false ;while (bott <=top && !found){

mid = top + bott / 2 ;if ( T [mid] == key ){

found = true;L = mid ;

}else if (T [mid] < key )

bott = mid + 1 ;else

top = mid-1 ;} // while

} //binary_search

void Binary_search (elem key, elem* T, int size, boolean &found, int &L){

int bott, top, mid ;bott = 0 ; top = size -1 ;L = ( top + bott ) / 2 ;if (T[L] == key)

found = true ;else

found = false ;while (bott <=top && !found){

mid = top + bott / 2 ;if ( T [mid] == key ){

found = true;L = mid ;

}else if (T [mid] < key )

bott = mid + 1 ;else

top = mid-1 ;} // while

} //binary_search

Page 42: 92 SE-Testing.ppt

Software Engineering

42N.L. Hsueh, SE-Lab IECS FCU

Pre-conditions satisfied, key element in array Pre-conditions satisfied, key element not in array Pre-conditions unsatisfied, key element in array Pre-conditions unsatisfied, key element not in array Input array has a single value Input array has an even number of values Input array has an odd number of values

Binary search - equiv. partitions

Page 43: 92 SE-Testing.ppt

Software Engineering

43N.L. Hsueh, SE-Lab IECS FCU

Binary search equiv. partitions

Mid-point

Elements < Mid Elements > Mid

Equivalence class boundaries

Input array (T) Key (Key) Output (Found, L)17 17 true, 117 0 false, ??17, 21, 23, 29 17 true, 19, 16, 18, 30, 31, 41, 45 45 true, 717, 18, 21, 23, 29, 38, 41 23 true, 417, 18, 21, 23, 29, 33, 38 21 true, 312, 18, 21, 23, 32 23 true, 421, 23, 29, 33, 38 25 false, ??

Test Cases

Page 44: 92 SE-Testing.ppt

Software Engineering

44N.L. Hsueh, SE-Lab IECS FCU

Path testing To exercise every independent execution path through the

component If every independent path is executed then all statements in the

program must have been executed at least once All conditional statements are tested for both true and false cases

The starting point for path testing is a program flow graph Flow graph

Describes the program control flow Is constructed by replacing program control statements by

equivalent diagrams If there are no ‘goto’ statements in a program, it is a

straightforward mapping from a program to a flow graph Used as a basis for computing the cyclomatic

complexity

Page 45: 92 SE-Testing.ppt

Software Engineering

45N.L. Hsueh, SE-Lab IECS FCU

The number of independent path in a program can be discovered by computing the cyclomatic complexity (McCabe 1976) Complexity = Number of edges - Number of nodes +1

Program flow graphs

if-then-else loop-while case-of

Page 46: 92 SE-Testing.ppt

Software Engineering

46N.L. Hsueh, SE-Lab IECS FCU

1

2

3

54

76

98

10

1112

13

(if not Found then...)

(while Bott <= Top loop)

(If T (mid) = Key then.. .)

(if T (mid) < Key then...)

Page 47: 92 SE-Testing.ppt

Software Engineering

47N.L. Hsueh, SE-Lab IECS FCU

The number of tests to test all control statements equals the cyclomatic complexity

Cyclomatic complexity equals number of conditions in a program

Useful if used with care. Does not imply adequacy Does not take into account data-driven programs

Cyclomatic complexity

Page 48: 92 SE-Testing.ppt

Software Engineering

48N.L. Hsueh, SE-Lab IECS FCU

1, 2, 3, 4, 12, 13 1, 2,3, 5, 6, 11, 2, 12, 13 1, 2, 3, 5, 7, 8, 10, 11, 2, 12, 13 1, 2, 3, 5, 7, 9, 10, 11, 2, 12, 13 Test cases should be derived so that all of these paths are e

xecuted A dynamic program analyzer may be used to check that pat

hs have been executed

Independent paths

Page 49: 92 SE-Testing.ppt

Software Engineering

49N.L. Hsueh, SE-Lab IECS FCU

V(G) = Cyclomatic complexity

modules

modules in this range are more error prone

A number of industry studies have indicated that the higher V(G), the higher the probability or errors.

Page 50: 92 SE-Testing.ppt

Software Engineering

50N.L. Hsueh, SE-Lab IECS FCU

Takes place when modules or sub-systems are integrated to create larger systems

Objectives are to detect faults due to interface errors or invalid assumptions about interfaces

Particularly important for object-oriented development as objects are defined by their interfaces

Interface testing

A

C

B

Page 51: 92 SE-Testing.ppt

Software Engineering

51N.L. Hsueh, SE-Lab IECS FCU

Interfaces types

Parameter interfaces Data passed from one procedure to another

Shared memory interfaces Block of memory is shared between procedures

Procedural interfaces Sub-system encapsulates a set of procedures to be

called by other sub-systems Message passing interfaces

Sub-systems request services from other sub-systems

Page 52: 92 SE-Testing.ppt

Software Engineering

52N.L. Hsueh, SE-Lab IECS FCU

Interface errors

Interface misuse A calling component calls another component and

makes an error in its use of its interface e.g. parameters in the wrong order

Interface misunderstanding A calling component embeds assumptions about the

behaviour of the called component which are incorrect Timing errors

The called and the calling component operate at different speeds and out-of-date information is accessed

Page 53: 92 SE-Testing.ppt

Software Engineering

53N.L. Hsueh, SE-Lab IECS FCU

Interface testing guidelines

Design tests so that parameters to a called procedure are at the extreme ends of their ranges

Always test pointer parameters with null pointers Use stress testing in message passing systems

Design tests which generate many more messages than are likely to occur in practice

In shared memory systems, vary the order in which components are activated

Page 54: 92 SE-Testing.ppt

Software Engineering

54N.L. Hsueh, SE-Lab IECS FCU

Reliability Achievement

Page 55: 92 SE-Testing.ppt

Software Engineering

55N.L. Hsueh, SE-Lab IECS FCU

Taxonomy of Quality control activities (UML class diagram)

Page 56: 92 SE-Testing.ppt

Software Engineering

56N.L. Hsueh, SE-Lab IECS FCU

Fault Avoidance

Fault avoidance Development technique are used that either minimise the

possibility of mistakes or trap mistakes before they result in the introduction of system faults

Techniques Development methodology Configuration management Verification techniques Reviews

Page 57: 92 SE-Testing.ppt

Software Engineering

57N.L. Hsueh, SE-Lab IECS FCU

Fault Detection

Fault detection and removal Verification and validation techniques that increase the

probability of detecting and correcting errors before the system goes into service are used

Techniques Debugging

Correctness debugging

Performance debugging Testing

Component testing

Integration testing

System testing

Page 58: 92 SE-Testing.ppt

Software Engineering

58N.L. Hsueh, SE-Lab IECS FCU

Fault Tolerance

Fault tolerance Run-time techniques are used to ensure that system faults

do not result in system errors and/or that system errors do not lead to system failures

Fault tolerance means that the system can continue in operation in spite of software failure

In critical situations, software systems must be fault tolerant.

Page 59: 92 SE-Testing.ppt

Software Engineering

59N.L. Hsueh, SE-Lab IECS FCU

Fault tolerance actions

Fault detection The system must detect that a fault (an incorrect system

state) has occurred. Damage assessment

The parts of the system state affected by the fault must be

detected. Fault recovery

The system must restore its state to a known safe state. Fault repair

The system may be modified to prevent recurrence of the fault. As many software faults are transitory, this is often unnecessary.

Page 60: 92 SE-Testing.ppt

Software Engineering

60N.L. Hsueh, SE-Lab IECS FCU

Fault tolerance techniques

Techniques Atomic transactions

Database systems provide atomic transactions to recover from failure during a sequence of actions that need to be executed together or not at all

Modular redundancyAssign more than one component to perform the same

operation Defensive programming

Programmers assume that there may be faults in the code of the system and incorporate redundant code to check the state after modifications to ensure that it is consistent

Exception handling

Page 61: 92 SE-Testing.ppt

Software Engineering

61N.L. Hsueh, SE-Lab IECS FCU

Exception handling

A program exception is an error or some unexpected event such as a power failure.

Exception handling constructs allow for such events to be handled without the need for continual status checking to detect exceptions.

Using normal control constructs to detect exceptions in a sequence of nested procedure calls needs many additional statements to be added to the program and adds a significant timing overhead.

Page 62: 92 SE-Testing.ppt

Software Engineering

62N.L. Hsueh, SE-Lab IECS FCU

Exceptions in Java

class SensorFailureException extends Exception {SensorFailureException (String msg) {

super (msg) ;Alarm.activate (msg) ;

}} // SensorFailureException

class Sensor {int readVal () throws SensorFailureException {try {

int theValue = DeviceIO.readInteger () ;if (theValue < 0)

throw new SensorFailureException ("Sensor failure") ;return theValue ;

}catch (deviceIOException e)

{ throw new SensorFailureException (“ Sensor read error ”) ; }} // readVal

} // Sensor

Page 63: 92 SE-Testing.ppt

Freezer controller (Java)

class FreezerController {Sensor tempSensor = new Sensor () ;Dial tempDial = new Dial () ;float freezerTemp = tempSensor.readVal () ;final float dangerTemp = (float) -18.0 ;final long coolingTime = (long) 200000.0 ;public void run ( ) throws InterrupedException {try {

Pump.switchIt (Pump.on) ;do { if (freezerTemp > tempDial.setting ())

if (Pump.status == Pump.off){ Pump.switchIt (Pump.on) ;

Thread.sleep (coolingTime) ; } elseif (Pump.status == Pump.on)

Pump.switchIt (Pump.off) ;if (freezerTemp > dangerTemp)

throw new FreezerTooHotException () ;freezerTemp = tempSensor.readVal () ;

} while (true) ;} // try blockcatch (FreezerTooHotException f){ Alarm.activate ( ) ; }catch (InterruptedException e){ System.out.println (“Thread exception”) ;

throw new InterruptedException ( ) ; }} //run

} // FreezerController

Page 64: 92 SE-Testing.ppt

Software Engineering

64N.L. Hsueh, SE-Lab IECS FCU

Fault detection

Languages such as Java and Ada have a strict type system that allows many errors to be trapped at compile-time

However, some classes of error can only be discovered at run-time

Fault detection involves detecting an erroneous system state and throwing an exception to manage the detected fault

Page 65: 92 SE-Testing.ppt

Software Engineering

65N.L. Hsueh, SE-Lab IECS FCU

Fault detection

Preventative fault detection The fault detection mechanism is initiated before the state

change is committed. If an erroneous state is detected, the change is not made

Retrospective fault detection The fault detection mechanism is initiated after the system

state has been changed. Used when a incorrect sequence of correct actions leads

to an erroneous state to when preventative fault detection involves too much overhead

Page 66: 92 SE-Testing.ppt

Software Engineering

66N.L. Hsueh, SE-Lab IECS FCU

Damage assessment

Analyse system state to judge the extent of corruption caused by a system failure

Must assess what parts of the state space have been affected by the failure

Generally based on ‘validity functions’ which can be applied to the state elements to assess if their value is within an allowed range

Page 67: 92 SE-Testing.ppt

Software Engineering

67N.L. Hsueh, SE-Lab IECS FCU

Checksums are used for damage assessment in data transmission

Redundant pointers can be used to check the integrity of data structures

Watch dog timers can check for non-terminating processes. If no response after a certain time, a problem is assumed

Damage assessment techniques

Page 68: 92 SE-Testing.ppt

Java class with damage assessment

class RobustArray {// Checks that all the objects in an array of objects// conform to some defined constraintboolean [] checkState ;CheckableObject [] theRobustArray ;

RobustArray (CheckableObject [] theArray){

checkState = new boolean [theArray.length] ;theRobustArray = theArray ;

} //RobustArraypublic void assessDamage () throws ArrayDamagedException{

boolean hasBeenDamaged = false ;

for (int i= 0; i <this.theRobustArray.length ; i ++){

if (! theRobustArray [i].check ()){

checkState [i] = true ;hasBeenDamaged = true ;

}else

checkState [i] = false ;}if (hasBeenDamaged)

throw new ArrayDamagedException () ;} //assessDamage

} // RobustArray

Page 69: 92 SE-Testing.ppt

Software Engineering

69N.L. Hsueh, SE-Lab IECS FCU

Forward recovery Apply repairs to a corrupted system state

Backward recovery Restore the system state to a known safe state

Forward recovery is usually application specific - domain knowledge is required to compute possible state corrections

You know why faults happen and how to correct them

Backward error recovery is simpler. Details of a safe state are maintained and this replaces the

corrupted system state

Fault recovery

Page 70: 92 SE-Testing.ppt

Software Engineering

70N.L. Hsueh, SE-Lab IECS FCU

Transactions are a frequently used method of backward recovery.

Changes are not applied until computation is complete. If an error occurs, the system is left in the state preceding

the transaction

Periodic checkpoints allow system to 'roll-back‘ to a correct state

Backward recovery

Page 71: 92 SE-Testing.ppt

Safe sort procedure (Java)

class SafeSort {static void sort ( int [] intarray, int order ) throws SortError{

int [] copy = new int [intarray.length];

// copy the input array

for (int i = 0; i < intarray.length ; i++)copy [i] = intarray [i] ;

try {Sort.bubblesort (intarray, intarray.length, order) ;if (order == Sort.ascending)

for (int i = 0; i <= intarray.length-2 ; i++)if (intarray [i] > intarray [i+1])

throw new SortError () ;else

for (int i = 0; i <= intarray.length-2 ; i++)if (intarray [i+1] > intarray [i])

throw new SortError () ;} // try blockcatch (SortError e ){

for (int i = 0; i < intarray.length ; i++)intarray [i] = copy [i] ;

throw new SortError ("Array not sorted") ;} //catch

} // sort} // SafeSort