Lecture 2-Control flow Flashcards
What is a program graph?
Directed graph in which nodes are statement fragments and edges represent flow of control.
*Statement fragments includes complete statement.
What is a Control Flow Graph(CFG)?
It models all executions of a method by describing control structures.
How can we simplify a CFG?
By grouping together statements which always execute together–> BASIC BLOCK with 1 entry point and 1 exit point
What are the 6 code coverage models(6)?
1.Statement coverage(SC)
2.Segment coverage (basic block)
3.Branch coverage(BC)
4.Condition coverage(CC)
5.Branch and condition coverage(BCC)
6.Modified/Decision condition (MC)
What is statement coverage?
-Achieved when all statements in a method have been executed at least once.
-Most used in industry
SC = # OF EXECUTED STATEMENTS/TOTAL # OF STATEMENTS
Typical statement coverage is 80-90%. Why don’t we aim at 100%? e.g. What are the problems with SC(3)?
-Predicate may be tested for only 1 value –>It misses many bugs
-Loop bodies only iterated once
-Statement coverage can be achieved without branch coverage –>important cases may be missed
*Think of the =0 case
What is segment coverage?
It counts segments rather than statements
What is the problem with segment coverage?
It may produce drastically different numbers.
What is branch coverage (BC) ?
-Achieved when every branch from a node is executed for each predicate.
-At least one true and one false evaluation for each predicate.
BC= # OF EXECUTED BRANCHES/TOTAL # OF BRANCHES
What are the problems with BC(3)?
-Short circuit evaluation means that many predicates might not be evaluated.
-A compound predicate is treated as a single statement.(if n clauses, 2^n combinations, but old 2 are tested.
-Only a subset of all entry-exit paths is tested.
What is condition coverage (CC)(Predicate Coverage)?
-It reports the true or false outcome of each condition.
-It measures the condition independently of each other.
CC= # OF CONDITIONS THAT ARE BOTH T AND F/ TOTAL # OF CONDITIONS
What are branch and condition coverage (BCC)(Decision coverage)?
It is computed by considering both branch and individual condition coverage measures.
What is modified/decision coverage(MC/DC)?
Key idea:
-Test important combinations of conditions and limiting testing costs.–> Each condition should be evaluated one time to TRUE and one time to FALSE and this with affecting the decision’s outcome.
-Often required for the mission-critical systems
How do we test nested loops?
They must be tested separately starting with the innermost.
*Loops are highly fault-prone.