You are on page 1of 75

Software Analysis

Software Analysis

Sandro Morasca and Dario Bertolino


Università degli Studi dell'Insubria
Dipartimento di Scienze Teoriche e Applicate
Via Ottorino Rossi 9 – Padiglione Rossi
I-21100 Varese, Italy
{sandro.morasca,dario.bertolino}@uninsubria.it

Sandro Morasca 1
Software Reliability and Testing
Characteristics Software Analysis

 Basic Concepts Software analysis is for documents (artifacts)


Reviews
Tools
“Formal”
Analysis

Sandro Morasca and Dario Bertolino 2


Progettazione del Software
Characteristics Software Analysis

 Basic Concepts Software analysis is for code (one of the artifacts)


Reviews
Tools
“Formal”
Analysis

Sandro Morasca and Dario Bertolino 3


Progettazione del Software
Software Analysis Is a Set of
Software Analysis
Different Activities

 Basic Concepts
Reviews
Tools
“Formal”
Analysis

Sandro Morasca and Dario Bertolino 4


Progettazione del Software
Characteristics Software Analysis

 Basic Concepts Is carried out without executing software


Reviews
Tools Finds defects
“Formal”
Analysis • not failures
Allows for early defect detection
Different types of reviews exists
Complements software testing
• it is also carried out when debugging

Sandro Morasca and Dario Bertolino 5


Progettazione del Software
Advantages Software Analysis

 Basic Concepts Inexpensive way of detecting and eliminating defects


Reviews
Tools • early defect detection and correction
“Formal”
Analysis • focuses on root causes
• not failures
Can be performed well before testing
All kinds of software artifacts
Reviews can find omissions
Knowledge exchange between people in reviews
Structuring for presentation helps authors rethink their work
Quality is a team’s concern and not a single person’s
Data collected in reviews can be used for process
improvement

Sandro Morasca and Dario Bertolino 6


Progettazione del Software
Manual Techniques Software Analysis

 Basic Concepts Reviews


Reviews
Tools • inspection
“Formal”
Analysis • (peer) reviews
• walkthroughs
• pair programming
• pair desk-check
• ad-hoc review

Sandro Morasca and Dario Bertolino 7


Progettazione del Software
What is a Review? Software Analysis

Basic Concepts A review is an evaluation of a product or project status to


 Reviews
Tools ascertain discrepancies from planned results and
“Formal”
Analysis
recommend improvements
Any software artifact can be reviewed, including
• requirements
• specifications
• architectures
• designs
• source code
• test plans, test specifications, test cases, test scripts
• user guides
• web pages

Sandro Morasca and Dario Bertolino 8


Progettazione del Software
What is a Review? Software Analysis

Basic Concepts The main manual activity is to examine an artifact and


 Reviews
Tools comment it
“Formal”
Analysis

Missing
Requirement!
We don’t need
this functionality!

The algorithm
I can’t should be
understand the faster
code

Sandro Morasca and Dario Bertolino 9


Progettazione del Software
Reviews Goals Software Analysis

Basic Concepts Typical defects that are easier to find in reviews


 Reviews
Tools • deviations from standards
“Formal”
Analysis • requirements defects
• design defects
• insufficient maintainability
• incorrect specifications
The emphasis is on defect detection, not correction

Sandro Morasca and Dario Bertolino 10


Progettazione del Software
Review Activities Software Analysis

Review document Base documents


Basic Concepts
 Reviews
Tools
“Formal”
Analysis
Planning

Kick-off Manager

Individual preparation
Moderator
Review meeting
Reviewer

Rework

Follow-up
Author
Scribe

Corrected document List of findings, measures, etc.

Sandro Morasca and Dario Bertolino 11


Progettazione del Software
Planning Software Analysis

Basic Concepts Selecting the personnel


 Reviews
Tools
“Formal” Allocating roles
Analysis
Defining the entry and exit criteria for more formal review
types (e.g., inspection)
Selecting which parts of documents to look at

Sandro Morasca and Dario Bertolino 12


Progettazione del Software
Planning: roles Software Analysis

Basic Concepts Manager


 Reviews
Tools • decides on the execution of reviews
“Formal”
Analysis • allocates time
• determines if the review objectives have been met

Sandro Morasca and Dario Bertolino 13


Progettazione del Software
Activities Software Analysis

Review document Base documents


Basic Concepts
 Reviews
Tools
“Formal”
Analysis Planning

Kick-off Manager

Individual preparation
Moderator
Review meeting
Reviewer

Rework

Follow-up
Author
Scribe

Corrected document List of findings, measures, etc.

Sandro Morasca and Dario Bertolino 14


Progettazione del Software
Kick-off Software Analysis

Basic Concepts Distributing the documents


 Reviews
Tools
“Formal” Explaining the objectives, process, and documents to the
Analysis participants
Checking the entry criteria for more formal review types (e.g.,
inspection)

Sandro Morasca and Dario Bertolino 15


Progettazione del Software
Kick-off: Roles Software Analysis

Basic Concepts Manager


 Reviews
Tools • shows the plan to participants
“Formal”
Analysis
Author
• has the responsibility for the document being reviewed
Reviewers
• have specific technical or business backgrounds
• identify and describe faults
• should represent different perspectives and roles

Sandro Morasca and Dario Bertolino 16


Progettazione del Software
Activities Software Analysis

Review document Base documents


Basic Concepts
 Reviews
Tools
“Formal”
Analysis Planning

Kick-off Manager

Individual preparation
Moderator
Review meeting
Reviewer

Rework

Follow-up
Author
Scribe

Corrected document List of findings, measures, etc.

Sandro Morasca and Dario Bertolino 17


Progettazione del Software
Individual Preparation Software Analysis

Basic Concepts Work done by each of the participants on their own


 Reviews
Tools • before the review meeting
“Formal”
Analysis
Outcomes
• potential defects
• questions
• comments
• suggestions for improvement
• …

Sandro Morasca and Dario Bertolino 18


Progettazione del Software
Activities Software Analysis

Review document Base documents


Basic Concepts
 Reviews
Tools
“Formal”
Analysis Planning

Kick-off Manager

Individual preparation
Moderator
Review meeting
Reviewer

Rework

Follow-up
Author
Scribe

Corrected document List of findings, measures, etc.

Sandro Morasca and Dario Bertolino 19


Progettazione del Software
Review Meeting Software Analysis

Basic Concepts Discussion


 Reviews
Tools • documented results
“Formal”
Analysis • minutes (for more formal review types)
Outcomes
• defects
• recommendations
• decisions

Sandro Morasca and Dario Bertolino 20


Progettazione del Software
Review Meeting: Basic rules Software Analysis

Basic Concepts Not a big ego fight


 Reviews
Tools • authors: keep an open mind, avoid arguing or defending
“Formal”
Analysis yourselves
• reviewers: it’s not about showing how smart you are
Keep the review team small
• 3 – 7 participants
Limit review meetings to two hours
Only find problems in reviews
• do NOT try to solve them at the meeting

Sandro Morasca and Dario Bertolino 21


Progettazione del Software
Review Meeting: roles Software Analysis

Basic Concepts Moderator


 Reviews
Tools • leads the review
“Formal”
Analysis • planning
• running the meeting
• follow-up
• tries to find an agreement among different viewpoints
• probably the central figure for the review
Scribe
• documents
• issues
• problems
• open points

Sandro Morasca and Dario Bertolino 22


Progettazione del Software
Activities Software Analysis

Review document Base documents


Basic Concepts
 Reviews
Tools
“Formal”
Analysis Planning

Kick-off Manager

Individual preparation
Moderator
Review meeting
Reviewer

Rework
Follow-up
Author
Scribe

Corrected document List of findings, measures, etc.

Sandro Morasca and Dario Bertolino 23


Progettazione del Software
Rework and Follow-up Software Analysis

Basic Concepts Rework


 Reviews
Tools • fixing defects
“Formal”
Analysis • done by author
Follow-up
• checking that defects have been addressed
• gathering measures
• checking satisfaction of exit criteria (for more formal review
types)

Sandro Morasca and Dario Bertolino 24


Progettazione del Software
Data on Results Software Analysis

Basic Concepts Reading rates


 Reviews
Tools • source code: 100 – 150 NCLOC/hour during individual
“Formal”
Analysis preparation
• text documents: 1 – 5 pages/hour
• proofreading: 7 – 25 pages/hour
Productivity
• inspections (formal reviews): 16 – 20 faults/KLOC
• informal reviews: 3 faults/KLOC
Totals
• code inspections: about 60% of faults
• higher than other techniques
• design + code inspections: 70% - 85% of faults

Sandro Morasca and Dario Bertolino 25


Progettazione del Software
Degree of Formality Software Analysis

Basic Concepts
 Reviews
Tools
“Formal”
Analysis
formal informal

Inspection Team review Walkthrough Pair Peer desk- Ad-hoc


programming check review

Planning YES YES YES YES NO NO

Preparation YES YES NO NO YES NO

Meeting YES YES YES Continuous YES YES

Correction YES YES YES YES YES YES

Verification YES NO NO YES NO NO

Sandro Morasca and Dario Bertolino 26


Progettazione del Software
Inspection Software Analysis

Basic Concepts It is the most systematic and rigorous kind of review


 Reviews
Tools • documented procedure
“Formal”
Analysis • Led by a trained moderator—NOT the author
• Usually peer examination, it is repeated until all objectives
are achieved
• Defined roles: author, reviewers, moderator, scribe
• Includes measures about the productivity of the reviewing
process

Sandro Morasca and Dario Bertolino 27


Progettazione del Software
Inspection Software Analysis

Basic Concepts Formal process


 Reviews
Tools • rules
“Formal”
Analysis • pre-meeting preparation
• checklists
• entry and exit criteria
• report and list of findings
• Specific follow-up process
Main purpose: Find faults

Sandro Morasca and Dario Bertolino 28


Progettazione del Software
Fagan’s Code Inspections Software Analysis

Review document Base documents


Basic Concepts
 Reviews
Tools
“Formal”
Analysis Planning

Overview

Individual Preparation
Moderator
Inspection meeting
Readers, Testers

Rework

Follow-up
Author

Corrected document List of findings, measures, etc.

Sandro Morasca and Dario Bertolino 29


Progettazione del Software
Fagan’s Code Inspections Software Analysis

Basic Concepts Software Inspection Roles


 Reviews
Tools • Moderator
“Formal”
Analysis • is typically borrowed from another project
• chairs meeting
• chooses participants
• controls process
• Readers, Testers
• read code to group
• look for flaws
• Author
• passive participant
• answers questions when asked

Sandro Morasca and Dario Bertolino 30


Progettazione del Software
Faga’s Code Inspections Software Analysis

Basic Concepts Planning


 Reviews
Tools • moderator checks entry criteria, chooses participants,
“Formal”
Analysis schedules meeting
Overview
• provide background education, assign roles
Individual Preparation
Inspection meeting (see ahead)
Rework
Follow-up (& possible re-inspection)

Sandro Morasca and Dario Bertolino 31


Progettazione del Software
In the Meeting Software Analysis

Basic Concepts Goal: Find as many faults as possible


 Reviews
Tools • max 2 x 2 hour sessions per day
“Formal”
Analysis • approx. 150 source lines/hour
Approach: Line-by-line paraphrasing
• reconstruct intent of code from source
• may also “hand test”
Find and log defects, but do not fix them
• moderator responsible for staying on track

Sandro Morasca and Dario Bertolino 32


Progettazione del Software
Checklists — NASA example Software Analysis

Basic Concepts About 2.5 pages for C code, 4 for FORTRAN


 Reviews
Tools • Divided into: Functionality, Data Usage, Control, Linkage,
“Formal”
Analysis Computation, Maintenance, Clarity
Examples:
• Does each module have a single function?
• Does the code match the Detailed Design?
• Are all constant names upper case?
• Are pointers not typecast (except assignment of NULL)?
• Are nested “INCLUDE” files avoided?
• Are non-standard usages isolated in subroutines and well
documented?
• Are there sufficient comments to understand the code?

Sandro Morasca and Dario Bertolino 33


Progettazione del Software
Incentive Structure Software Analysis

Basic Concepts Faults found in inspection are not used in personnel


 Reviews
Tools evaluation
“Formal”
Analysis • programmer has no incentive to hide faults
Faults found in testing (after inspection) are used in
personnel evaluation
• programmer has incentive to find faults in inspection, but
not by inserting more

Sandro Morasca and Dario Bertolino 34


Progettazione del Software
Variation: Active Design
Software Analysis
Reviews

Basic Concepts Observation:


 Reviews
Tools • an unprepared reviewer can sit quietly and say nothing
“Formal”
Analysis • this must be avoided
Variant process:
• choose reviewers with appropriate expertise
• several reviewers to look at different aspects
• author asks questions of the reviewer
• reviewer’s job is to answer the questions

Sandro Morasca and Dario Bertolino 35


Progettazione del Software
Variation: Phased Inspections Software Analysis

Basic Concepts Divide inspection into a series of smaller, focused “phases” in


 Reviews
Tools a definite order
“Formal”
Analysis
Inspection
Phase 1 list
check list
Phase 2 list

Phase 3 list

Phase 4 list

Sandro Morasca and Dario Bertolino 36


Progettazione del Software
Variation: Phased Inspections Software Analysis

Basic Concepts Single inspector for simple, unambiguous checks (e.g.,


 Reviews
Tools standards conformance)
“Formal”
Analysis • may be technical writer or junior programmer
Multiple inspectors for complex checks (e.g., correctness)
• skilled, knowledgeable engineers
• independent inspections in private
• reconciliation meeting to compare results

Sandro Morasca and Dario Bertolino 37


Progettazione del Software
Inspection Automation Software Analysis

Basic Concepts Although a manual technique, many kinds of automated


 Reviews
Tools support are possible:
“Formal”
Analysis • automate trivial checks (e.g., formatting)
• reference: checklists, standards with examples
• focus (highlight, selection) on relevant parts
• annotation & communication
• process guidance and (partial) enforcement
• e.g., InspeQ will not allow check-off until all relevant
parts of a document have been observed

Sandro Morasca and Dario Bertolino 38


Progettazione del Software
Inspection Advantages Software Analysis

Basic Concepts The evidence says inspection is cost-effective


 Reviews
Tools • detailed, formal process, with record keeping
“Formal”
Analysis • checklists
• self-improving process
• social aspects of process, especially for author
• consideration of entire input space
• applies to incomplete programs

Sandro Morasca and Dario Bertolino 39


Progettazione del Software
Inspection Disadvantages Software Analysis

Basic Concepts Limitations


 Reviews
Tools • scale
“Formal”
Analysis • inherently a unit-level technique
• non-incremental
• what about evolution?

Sandro Morasca and Dario Bertolino 40


Progettazione del Software
Degree of Formality Software Analysis

Basic Concepts
 Reviews
Tools
“Formal”
Analysis
formal informal

Inspection Team review Walkthrough Pair Peer desk- Ad-hoc


programming check review

Planning YES YES YES YES NO NO

Preparation YES YES NO NO YES NO

Meeting YES YES YES Continuous YES YES

Correction YES YES YES YES YES YES

Verification YES NO NO YES NO NO

Sandro Morasca and Dario Bertolino 41


Progettazione del Software
Team Review Software Analysis

Basic Concepts
 Reviews
Tools
“Formal”
Analysis

Sandro Morasca and Dario Bertolino 42


Progettazione del Software
Team Review Software Analysis

Basic Concepts Technical review


 Reviews
Tools • a peer group discussion that focuses on achieving
“Formal”
Analysis consensus on the technical approach to use
Planned and strucured
• but less formal than inspections
• may range from very formal to very informal
Participants
• different skills, including
• peers and technical experts
• focus on different problems
• learning opportunity

Sandro Morasca and Dario Bertolino 43


Progettazione del Software
Team Review Software Analysis

Basic Concepts Leader


 Reviews
Tools • trained moderator, if possible
“Formal”
Analysis • it can also be the author
Pre-meeting preparation required
Optional activities:
• checklists, review report, list of finding
Productivity
• about 2/3 of inspection productivity
Main goals
• discuss, make decisions, evaluate alternatives, find
defects, solve technical problems, check conformance to
specifications and standards

Sandro Morasca and Dario Bertolino 44


Progettazione del Software
Degree of Formality Software Analysis

Basic Concepts
 Reviews
Tools
“Formal”
Analysis
formal informal

Inspection Team review Walkthrough Pair Peer desk- Ad-hoc


programming check review

Planning YES YES YES YES NO NO

Preparation YES YES NO NO YES NO

Meeting YES YES YES Continuous YES YES

Correction YES YES YES YES YES YES

Verification YES NO NO YES NO NO

Sandro Morasca and Dario Bertolino 45


Progettazione del Software
Walkthrough Software Analysis

Basic Concepts Informal review in which the author describes the product to a
 Reviews
Tools
group of peers and solicits comments
“Formal” • example: going through a specific user scenario
Analysis
Meeting led by authors, while other roles are usually not defined
• author selects and presents the material
• author usually records the findings
Open-ended session
Optional: pre-meeting preparation of reviewers
Productivity: 50% of defects found in inspections (according to a case
study)
Purposes
• learning, gaining understanding, brainstorm alternative solutions,
find defects

Sandro Morasca and Dario Bertolino 46


Progettazione del Software
This My C++ Class Software Analysis

Basic Concepts
 Reviews
Tools class CoinBox
“Formal”
{
Analysis
int totalQtrs; // total quarters collected
int curQtrs; // current quarters collected
boolean allowVend; // true=vending is allowed
public:
CoinBox() {reset();}
void addQtr(); // add a quarter
void returnQtrs() {curQtrs=0;}
// return current quarters
boolean isAllowedVend() {return allowVend;}
void reset() {totalQtrs = 0; allowVend = false;curQtrs = 0;}
void vend(); //if vending allowed, update totalQtrs and
curQtrs
};

Sandro Morasca and Dario Bertolino 47


Progettazione del Software
What Do You Think about My
Software Analysis
Work?

Basic Concepts
 Reviews
void CoinBox::addQtr()
Tools
“Formal” {
Analysis curQtrs = curQtrs+1; //add a quarter
if (curQtrs > 1)
//if more than one quarter is collected,
allowVend = false; //then set allowVend
}
void CoinBox::vend()
{
if (isAllowedVend()) //if allowVend
{
totalQtrs = totalQtrs+curQtrs; //update totalQtrs
curQtrs = 0; //curQtrs
allowVend = false; //allowVend
} //else no action
}

Sandro Morasca and Dario Bertolino 48


Progettazione del Software
What is an Informal Review Software Analysis

Basic Concepts Not based on a formal and documented process


 Reviews
Tools
“Formal” Usefulness varies depending on the reviewer
Analysis
Main purpose: inexpensive way to get some benefit
Typical informal reviews

Sandro Morasca and Dario Bertolino 49


Progettazione del Software
Degree of Formality Software Analysis

Basic Concepts
 Reviews
Tools
“Formal”
Analysis
formal informal

Inspection Team review Walkthrough Pair Peer desk- Ad-hoc


programming check review

Planning YES YES YES YES NO NO

Preparation YES YES NO NO YES NO

Meeting YES YES YES Continuous YES YES

Correction YES YES YES YES YES YES

Verification YES NO NO YES NO NO

Sandro Morasca and Dario Bertolino 50


Progettazione del Software
Pair Programming Software Analysis

Basic Concepts Two developers work together on a single workstation


 Reviews
Tools
“Formal” Advantages
Analysis
• communication
• continuous, incremental reviews
• continuous psychological pressure
• more fun
• fewer defects
Disadvantages
• more expensive

Sandro Morasca and Dario Bertolino 51


Progettazione del Software
Pair Programming Software Analysis

Basic Concepts
 Reviews
Tools
“Formal”
Analysis

Sandro Morasca and Dario Bertolino 52


Progettazione del Software
Degree of Formality Software Analysis

Basic Concepts
 Reviews
Tools
“Formal”
Analysis
formal informal

Inspection Team review Walkthrough Pair Peer desk- Ad-hoc


programming check review

Planning YES YES YES YES NO NO

Preparation YES YES NO NO YES NO

Meeting YES YES YES Continuous YES YES

Correction YES YES YES YES YES YES

Verification YES NO NO YES NO NO

Sandro Morasca and Dario Bertolino 53


Progettazione del Software
Peer Desk-check Software Analysis

Basic Concepts In a peer desk-check


 Reviews
Tools • reviewer else looks at the source listings alone
“Formal”
Analysis • then, author and reviewer discuss the findings
Pass-around
• multiple, concurrent desk-check
• involves several people
• at the end, the author puts together the results

Sandro Morasca and Dario Bertolino 54


Progettazione del Software
Peer Desk-check Software Analysis

Basic Concepts Interactive Tools for peer Desk-check in every version


 Reviews
Tools control software of the market (e.g. github, gitlab)
“Formal”
Analysis

Sandro Morasca and Dario Bertolino 55


Progettazione del Software
Degree of Formality Software Analysis

Basic Concepts
 Reviews
Tools
“Formal”
Analysis
formal informal

Inspection Team review Walkthrough Pair Peer desk- Ad-hoc


programming check review

Planning YES YES YES YES NO NO

Preparation YES YES NO NO YES NO

Meeting YES YES YES Continuous YES YES

Correction YES YES YES YES YES YES

Verification YES NO NO YES NO NO

Sandro Morasca and Dario Bertolino 56


Progettazione del Software
Ad-hoc Review Software Analysis

Basic Concepts A programmer asks another to get a different perspective


 Reviews
Tools
“Formal” Goal is to find problems that the programmer cannot usually
Analysis see alone

Sandro Morasca and Dario Bertolino 57


Progettazione del Software
Choosing a Review Approach Software Analysis

Basic Concepts Inspection Team Walkthrou Pair Desk- Passaround


 Reviews review gh prog. check
Tools
“Formal” Find defects X X X X X X
Analysis Check conformance X X X X
Check completeness and correctness X X X X
Assess understandability and X X X X
maintainability
Demonstrate quality of critical or high- X
risk components
Collect data for process improvement X X
Measure document quality X
Educate other team members X X X X
Reach consensus on an approach X X X
Ensure compatibility of changes X X X
Explore alternative approaches X X
Simulate execution of a program X
Minimize review costs X

Sandro Morasca and Dario Bertolino 58


Progettazione del Software
Automated Techniques Software Analysis

 Basic Concepts compiler


Reviews
Tools
“Formal” code style checker
Analysis
bug pattern detector
design/architecture analyzer
data/control flow analyzer
formal verification tools

Sandro Morasca and Dario Bertolino 59


Progettazione del Software
Automated Static Analysis Software Analysis

Basic Concepts Static analyzers are software tools that scan source code
Reviews
 Tools to detect possible faults
“Formal”
Analysis • no code execution is carried out
Potential problems
• control flow problems: loops with multiple entry or exit
points, unreachable code
• data use problems: uninitialized variables, variables that
are never used
• interface problems: inconsistency of routine and procedure
declarations and use
• other problems: common security holes, duplicate blocks,
style conventions and standards

Sandro Morasca and Dario Bertolino 60


Progettazione del Software
Typical Defects Detected Software Analysis

Basic Concepts Syntax rule violations


Reviews
 Tools
“Formal” Violations of coding and naming conventions
Analysis
Unreachable code
Undeclared variables
Uninitialized variables
Reference to an undefined variable
Variables that are never used
Methods that are never called
Function results are never used
Duplication of code blocks

Sandro Morasca and Dario Bertolino 61


Progettazione del Software
Typical Defects Detected Software Analysis

Basic Concepts Array out of bounds


Reviews
 Tools Parametery type mismatch
“Formal”
Analysis
Inconsistent interfaces
Security vulnerabilities
Null pointer dereferencing
Misuse of pointer
Division by zero
Deadlocks
Performance problems
Lack of localization

Sandro Morasca and Dario Bertolino 62


Progettazione del Software
False Positives vs. False
Software Analysis
Negatives

Basic Concepts False positives


Reviews
 Tools • problems are reported that will never occur
“Formal”
Analysis • useless work to fix them
• effort diverted from real problems
False negatives
• problems are not reported
• faults are left in the shipped product

Sandro Morasca and Dario Bertolino 63


Progettazione del Software
Compilers Software Analysis

Basic Concepts Different warning levels


Reviews
 Tools • some levels may be disabled
“Formal”
Analysis • balance between false positives and false negatives
• syntax checks
• type checks
• cross references
• undeclared variables
• unused return values
• unreachable code
• exception handling
• …

Sandro Morasca and Dario Bertolino 64


Progettazione del Software
Code Style Analyzers Software Analysis

Basic Concepts Using a consistent coding style


Reviews
 Tools • makes code more understandable
“Formal”
Analysis • may prevent specific faults
• putting constants on left-hand side of comparisons
• avoiding assignments in conditions
Typical defects detected
• naming conventions violated
• missing Javadoc comments
• duplicated code blocks
• …
• coding and design flaws (e.g., equals and hashCode())

Sandro Morasca and Dario Bertolino 65


Progettazione del Software
Design/Architecture Software Analysis

Basic Concepts Initial situation


Reviews
 Tools • complex system, no documentation, degraded
“Formal”
Analysis architecture,unavailable developers, etc.
• has the agreed on design been actually implemented?
• does the software system comply with the standards?
• is it possible to extend or test the software with
reasonable effort?
• …

Sandro Morasca and Dario Bertolino 66


Progettazione del Software
Design/Architecture Software Analysis

Basic Concepts Design/architecture review based on measures and static


Reviews
 Tools analysis, to identify potential problems
“Formal”
Analysis • size limits
• big classes (e.g., with more than 100 methods)
• OO misuse, e.g., direct access to member data, heavy use
of type casts, overuse of inheritance, classes that reference
subclasses, etc.
• cycles and bottlenecks
• changing them would affect a large part of the system
• architecture conformance problems
• e.g., upward references, references that skip one or
more layers, interface violations

Sandro Morasca and Dario Bertolino 67


Progettazione del Software
Data Flow Analysis
Software Analysis
Basic Ideas

Basic Concepts Analyze a program based on the events each variable goes
Reviews
Tools through at each statement
 “Formal”
Analysis Definition: the statement gives the variable a possibly new
value
Use: the statement “looks at” the variable’s value
(e.g. use of x x2 := x)
Annulment: the variable’s value no longer exists (e.g
annulment od f x: integer; )

Sandro Morasca and Dario Bertolino 68


Progettazione del Software
An Example Software Analysis

Basic Concepts 1. procedure swap(x1, x2: integer) DEFINITION OF X2 & X1


Reviews
Tools
 “Formal” 2. var
Analysis
3. x: integer; ANNULMENT OF X

4. begin
5. x2 := x;
USE OF X
6. x2 := x1;
7. x1 := x;
8. end;
DEFINITION OF X1

Sandro Morasca and Dario Bertolino 69


Progettazione del Software
General Rules Software Analysis

Basic Concepts L’utilizzo di una variabile deve essere sempre preceduto da


Reviews
Tools una definizione della stessa in ogni sequenza, senza degli
 “Formal”
Analysis
annullamenti nel mezzo.

For x
• a u u (problem!)

Sandro Morasca and Dario Bertolino 70


Progettazione del Software
General Rules Software Analysis

Basic Concepts La definizione di una variabile x deve essere sempre seguita


Reviews
Tools da un utilizzo di x prima di una seconda definizione o un
 “Formal”
Analysis
annullamento di x

For x2
• d d d (problem!)

Sandro Morasca and Dario Bertolino 71


Progettazione del Software
General Rules Software Analysis

Basic Concepts For x1


Reviews
Tools • dud
 “Formal”
Analysis

Sandro Morasca and Dario Bertolino 72


Progettazione del Software
Using a Regular Language Software Analysis

Basic Concepts Alphabet: {a, u, d, }


Reviews
Tools •  is the empty string
 “Formal”
Analysis
Every symbol of the alphabet is a regular expression
Given two regular expressions e1 and e2, the following ones
are regular expressions
• e1 e2  SEQUENCE
• e1 + e2  DECISION
• (e1)*  LOOP

Sandro Morasca and Dario Bertolino 73


Progettazione del Software
Another Example Software Analysis

program example(input, output)


Basic Concepts
Reviews var
Tools x, y, res: integer;
 “Formal” begin
Analysis
read(x);
read(y);
res := 0;
if y < 0 then begin
x := -x;
y := -y
end
while y > 0 do
begin
res := res+x;
y := y-1
end;
write(res)
end.

Sandro Morasca and Dario Bertolino 74


Progettazione del Software
Another Example Software Analysis

program example(input, output)


Basic Concepts
Reviews var
Tools
x, y, z: integer;
 “Formal”
Analysis begin
read(x);
read(y);
if x > y then x := x-1
else y := y-1;
while x+y > 0 do
begin
x := y-z;
z := x+y;
y := y-x
end;
if z > 0 then z := x+y+z
else z := x-y-z;
end.

Sandro Morasca and Dario Bertolino 75


Progettazione del Software

You might also like