Upload
softwarecentral
View
747
Download
0
Tags:
Embed Size (px)
Citation preview
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 1
Software engineering for real-time systems
Section 11
Analysing and testing source code
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 2
Objectives
To:Explain the underlying concepts of the testing of source code.
Describe the basics of static and dynamic analysis.
Introduce code complexity metrics.
Describe coverage analysis and its use as part of the dynamic analysis process.
Illustrate test issues specifically related to object-oriented programming constructs.
Introduction
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 3
Introduction to software testing
Part 1
Overview
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 4
WHY TEST SOFTWARE?
The really important questions:
Will it work properly?
Will it be reliable?
Will it to be easy to build?
Is it a quality design?
Will it be easy to maintain?
Why test software?
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 5
Analys isof source code quality
T estof source code behaviour
Evaluation ofsource code
Language-
quality andstandards
Coding-
quality andstandards
Functionalcorrectness
Tem poralcorrectness
Unexpectedbehaviour
and programviolations
Preventing errors
Detecting errors
Approaches to code testing
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 6
Error detection
Software source codetesting
Error prevention
Code INSPECTION(static analysis)
Code EXECUTION(dynamic analysis)
Software code test techniques
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 7
Software testing steps
Software system
Software sub-system 1 Software sub-system 2
Majorsoftware
function 1
Majorsoftwarefunction 2
Majorsoftwarefunction 3
Code unit1
Code unit3
Code unit2
Code unit5
Code unit4
Integration of parts
Test units
Integrate units then test functions
Integrate functions then test sub-systems
Integrate sub-systems then test the complete system
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 8
Introduction to static analysis
Part 2
Static Analysis
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 9
Source code analys is(static analys is)
Manual staticanalysis
Autom ated staticanalysis
Analysis ofattributes
Analysis offunctionality and
correctness
Static analysis techniques
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 10
Automatic staticanalysers
Program attributeanalyser
Program verificationanalyser
Programstructure
(control flowanalysis)
Data usage(dataflowanalysis)
Informationflow
(informationflow analysis)
Program functionalrelationships
(semantic analysis)
Programcorrectness(compliance
analysis)
Automated static analysis tools
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 11
Evaluating program structure - cyclomatic complexity measures
Controlflow
graphGraph complexity measured using
Cyclomaticcomplexitytechniques
Output from module
Source codedecision logic
Input to module
Structure described using a
McCabe’s cyclomatic complexity metric: a measure of the amount of decision logic in a code unit
Cyclomatic complexity value: the number of independent paths through a control flow graph
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 12
Control flow graph - simple sequence structure
Cyclomatic complexity value v(G): the number of independent paths through a control flow graph.
Here v(G) = 1
{
Accel [0] = Xnew; Accel [1] = Xold; Accel [2] = Ynew;
}
Statement 1
Statement 2
Statement 3
Node 1
Node 2
Node 3
Edge(1-2)
Edge(2-3)
Code of 'module'Corresponding flow
graph
Statement 1
Statement 2
Statement 3
Flowchart
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 13
Control flow graph - simple selection structure
{
if (P ressure > H ighPressureA larm ) cout << "\nH igh pressure alarm "; else cout << "\nPressure OK";
cout << "\nEnd of pressure test";
}
Construct 1
Construct 2
Construct 3
Construct 4
Node 2
Node 1
Edge (1-2)
Edge (1-3)
Edge (3-4)
Edge (2-4)
Node 3
Node 4
Code of 'm odule'
Corresponding flow graph
Statement
Flowchart
Statement
Statement
?
v(G) = 2
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 14
Control flow graph - simple iteration structure
{
while (DataValue < 10) { cout << "\nInput data value"; cin >> DataValue' cout << DataValue; } /* end while */
cout << "\nEnd of test";
}
Construct 1
Construct 2
Construct 3
Construct 4
Code of 'module'
Construct 5
Node 1
Edge(1-2)
Edge(2-3)
Edge(3-4)
Edge(4-1)
Node 5
Corresponding flow graph
Node 3
Node 2
Node 4
Edge(1-5)
Statement
Flowchart
Statement
?
Statement
Statement
v(G) = 2
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 15
Control flow graph -highly complex
structure
Control flow graph -simplest structure
achievable
Example control flow graphs
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 16
Introduction to dynamic analysis
Part 3
Dynamic Analysis
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 17
Black box and white box testing
Two ways of testing code
Overall function Internal workings
‘Black box’ testing
Performed at the interfaces
‘White box’ testing
Performed on the implementation
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 18
Inputstim ulus
Measuredresponses
Softwareundertest
(a) Fundam ental concept of dynam ic testing
Softwarespecification
Testcases Measured
responses
Com parisonand results
analysis
Calculatedresponses
Test scriptSoftware code for
testing
Codeexecution
(b) Detailed aspects of dynam ic testing
Basis of dynamic testing
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 19
Coverage analyzer
Creation oftest data
Control oftest data
supply
Control ofsoftware
execution
Recording ofsoftware
responses
Analysis of tests
Generation ofpredicted
results
Com parison of actualand predicted values
Error reporting
Data generator
Test driver
Prediction generator
Fault diagnostic ian
Results analyzer
The test harness
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 20
Dynam ic testing tool features
Test scriptgeneration
Softwareexecution
Softwareperform ance
(tim ing)
Datacorrectness
checking
Em ulation andsim ulation of
target system s
Features of general-purpose dynamic testing tools
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 21
Individual white box tests for coverage analysis Name
Exercise each statement of a program at least once. Statement testing
Exercise each branch in a program at least once Decision or branchtesting
Exercise all possible paths through the program. Path testing
Exercise all logical conditions within a program. Condition testing
Coverage analysis and white box testing
Coverage analysis
‘A measure of the effectiveness and completeness of code testing.’
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 22
Softwarespecification
Define testobjectives and
write test cases
W rite sourcecode
Test casedefinition file
Test scriptcode file
Com pilecode
Com pilecode
Linkcode
Source codefile
Generate testscript code
Executablecode file
Build the test un it
Test the software(execute the code)
Results file
Tool library(linkable file)
Basis of a practical dynamic testing tool
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 23
Softwarespecification
Define the testobjectives and write
the test cases
W rite thesource code
Test casedefinition file
Test scriptcode file
Com pilethe code
Com pilethe code
Link allcode
Source codefile
Generate the testscript code
Executablecode file
Build the test un it
Test the software(execute the code)
Results file
Tool library(linkable file)
Instrum entedsource code
file
Instrum ent thesource code
Static analysislist file
Analysisdirectives
file
Dynamic testing and coverage analysis tool
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 24
Integration and testing
Part 4
Integration and
test strategies
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 25
Combined unit and integration testing
Unit A
Unit A2Unit A1
Test code for unitA
Test 2
Integrate units A1 and A2 to form A
Test code for unitA1
Unit A1
Test 1(a)
Test code for unitA2
Unit A2
Test 1(b)
Phase 1: test individual units.
Phase 2: test the combined unit.
This test must exercise all features of A1 and A2.
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 26
Reduced integration testing
v
v
Call node
(a) Original graph - v(G) = 6
Call node
(a) Reducedl graph - v(G) = 2
Full flow graph of the integrated unit A.
Reduction steps:
1. Identify ALL control structures of units A1 and A2 not concerned with external units (A).
2. Remove these from the flow graph.
Reduced flow graph of the
integrated unit
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 27
Class and object testing
Part 5
OO systems -
Class and object testing
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 28
Structure
Function Dynamics
AttributesOperations
OBJECT FEATURES
Structure
Function Dynamics
ObjectsObjectrelationships
SYSTEM FEATURES
Controller
Sensor
Actuator
Class and object testing
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 29
Weighed methods per class (WMC).
Depth of inheritance tree (DIT).
Number of children (NOC).
Coupling between objects (CBO).
Response for a class (RFC).
Lack of cohesion for methods (LCOM).
OO metrics in general use
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 30
Use of OO metrics
Evaluation ofcompleteness andself-containment
Assessment ofdesign complexity
Prediction of requiredtest effort
Use of OO metrics(class and object)
Estimation ofcoding errors
Ÿ LOCŸ ADŸ MD
Ÿ MHFŸ AHFŸ LCOM
Ÿ DITŸ NOCŸ LCOMŸ WMC
Ÿ WMCŸ RFCŸ MHFŸ CBO
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 31
SensorClass
ShowData
C lasses and m ethods
ShowData
R esponse to the ca ll on the c lass m ethod (s)
SensorClass
ShowData
AttitudeClass
AttitudeData
HeightC lass
HeightData
SpeedClass
SpeedData
ShowData ShowData ShowData
ShowData ::A ttitudeClass
ShowData ::HeightC lass
ShowData ::SpeedClass
(a) Im plic it flow of control with polym orphic operations
(a) F low of control without inheritance
Inheritance, polymorphism and testing issues
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 32
Client object A
Client object C
Client object B
ShowData :SpeedClass
ShowData :HeightC lass
ShowData :A ttitudeClass
Multiple clients using multiple servers having polymorphic methods
THE question: How much testing is needed?
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 33
Client object A
Client object C
Client object B
ShowData ::SpeedClass
ShowData ::HeightC lass
ShowData ::A ttitudeClass
Client object A
Client object C
Client object B
ShowData ::SpeedClass
ShowData ::HeightC lass
ShowData ::A ttitudeClass
Client object A
Client object C
Client object B
ShowData ::SpeedClass
ShowData ::HeightC lass
ShowData ::A ttitudeClass
(a) Full and com prehensive test strategy
(b) M inim um acceptable test stragegy
(c) Com prom ise test stragegy
Alternative test strategies with multiple clients/servers
SOFTWARE ENGINEERING for REAL-TIME SYSTEMS (© J.E.Cooling 2003) Analysing and testing source code - slide 34
You should now:
Be able to explain the underlying concepts of software testing of source code structures.
Know what static and dynamic analysis are and how they may be carried out. Appreciate the features and use of the McCabe cyclomatic complexity metric. Know what white box and black box testing entails. Recognize that dynamic analysis includes both testing and coverage analysis. Know what test strategies can be applied to integration testing. Realize that OO designs bring new problems into the software test arena.
END OF SECTION ‘Analysing and testing source code’
Review of ‘Analysing and testing source code’