Quality Assurance II -------------------------------------- slide number 1
Quality Assurance II
______________________________
Outline
These slides will be covered during TWO lectures.
Introduction
Formal Verification
Theoretical Limits
Quality Assurance II -------------------------------------- slide number 2
Software Quality
Previous discussions relating to QA have focused on
* process quality
* related to the currently popular Demming notions
* manifested in QA plans
* testing
* most important technical part of QA
* testing has two levels - strategy and tactics
* metrics
* error tracking & prediction
Quality Assurance II -------------------------------------- slide number 3
Software Quality Assurance
Process
* methods and tools
* configuration management and change control
* standards and standard compliance mechanisms
* reporting mechanisms
Verification and Validation
* formal technical reviews
* multi-tiered testing strategy
* measurement
o symbolic execution
=> formal verification techniques
Quality Assurance II -------------------------------------- slide number 4
Verification [4mversus[24m Validation
Verification:
"Are we building the product right?"
* implementation meets specifications
Validation:
"Are we building the right product?"
* specifications meet needs
Quality Assurance II -------------------------------------- slide number 5
Symbolic Execution
[1mGoal: [22mreason about history of value changes
Represent
* values with character strings
* operations by augmented strings
== trace
For example:
readf "%d", x;
y := x + 2;
z := y + 3;
sets
x <= "input"
y <= "input + 2"
z <= "(input + 2) + 3"
* expression simplification
Quality Assurance II -------------------------------------- slide number 6
Formal Verification
Program Proving
* vitally dependent on specification
formal verification can only be done against a formal specification
Techniques
* assertions
* formal semantics
In depth
* P415/P515 Introduction to Verification
Quality Assurance II -------------------------------------- slide number 7
Basic Idea
Each statement S is surrounded by logical formulae [4mF1[24m and [4mF2[0m
Notation:
{ [4mF1[24m } S { [4mF2[24m }
Interpretation:
In a -c-o-r-r-e-c-t--p-r-o-g-r-a-m-, if [4mF1[24m is true before S, then [4mF2[24m is true
afterwards.
[4mF1[24m is called a [4mpre-condition[24m for S
[4mF2[24m is called a [4mpost-condition[24m for S
Both are called [4massertions[0m
Quality Assurance II -------------------------------------- slide number 8
Assertions
* for example
{[4my>5[24m} x := y-2 [4m{x>3[24m [4m&[24m [4my>5}[0m
* in a program:
- always possible as comments
- some languages provide ASSERT statements
ASSERT y > 5;
x := y - 2;
ASSERT x > 3 & y > 5;
* can "chain" assertions
{ [4mF1[24m } S1 { [4mF2[24m } S2 { [4mF3[24m }
Quality Assurance II -------------------------------------- slide number 9
Formal Deduction
Program with assertions are manipulated in a formal deduction system based
on [4mproof[24m [4mrules[24m, such as
{[4mF1[24m} S1 {[4mF2[24m} , {[4mF2[24m} S2 {[4mF3[24m}
__________________________
{[4mF1[24m} S1 ; S2 {[4mF3[24m}
These proof rules are in the same spirit as the proof rules of "classical"
logic, such as
A , A => B
___________
B
Quality Assurance II ------------------------------------- slide number 10
Assertions and Loops
Loop Invariant:
an assertion preserved by the -b-o-d-y-of a loop
If {[4mF[24m} is invariant for a particular loop (body)
then {[4mF[24m} is preserved by the entire loop
[4mproof[24m: by induction on number of iterations
Write {{[4mF[24m}} to indicate [4mF[24m is a loop invariant
Quality Assurance II ------------------------------------- slide number 11
Example Procedure
[1mProcedure [22mBubbleSort(
A: [1mARRAY OF INT[22m, lim: [1mINT [22m);
[1mfor [22mi := 2 [1mto [22mlim [1mdo[0m
j := i;
[1mwhile [22mj>1 [1mand [22mA[j]1 [1mand [22mA[j]1 [1mand [22mA[j]1 [1mand [22mA[j][24m [4my[24m }
{{ [4mx[24m [4m>[24m [4my[24m }}
[1mwhile [4m[22mx[24m [4m<>[24m [4m0[24m [1mdo[0m
[4mx[24m [4m:=[24m [4mx-2[24m [4m;[0m
[4my[24m [4m:=[24m [4my-2[24m [4m;[0m
[1mend[0m
[4m{[24m [4mx[24m [4m>[24m [4my[24m [4m&[24m [4mx[24m [4m=[24m [4m0[24m [4m}[0m
The proof rule shows the above to be correct
[1mbut [22mthe loop terminates
if and only if [4mx[24m is initially even and positive.
Quality Assurance II ------------------------------------- slide number 17
Loop Invariants and Induction
Tail recursion => iteration
[4mf([24m [4mi,[24m [4mx[24m [4m)[24m [4m:=[24m [4mif[24m [4m([24m [4mi=0[24m [4m)[0m
[4mthen[24m [4mg(x)[0m
[4melse[24m [4mh([24m [4mi,[24m [4mf([24m [4mi-1,[24m [4mx[24m [4m)[24m [4m)[0m
becomes
[4mf([24m [4mm,[24m [4mx[24m [4m)[24m [4m{[0m
[4mr[24m [4m:=[24m [4mg(x);[0m
[4mfor[24m [4mi[24m [4m=[24m [4mm[24m [4muntil[24m [4m1[24m [4mdo[0m
[4mr[24m [4m:=[24m [4mh([24m [4mi,[24m [4mr[24m [4m);[0m
[4mreturn[24m [4mr[24m [4m}[0m
Loop invariant on iterative version is very close to induction on
recursive version
Quality Assurance II ------------------------------------- slide number 18
Loop Invariants as Design Aid
Formalism is -n-o-t-necessary
Ask:
* What is changed in this loop?
* What is preserved in this loop?
Look for higher-level concepts/properties
(such as part of array being sorted)
Quality Assurance II ------------------------------------- slide number 19
Back to Termination
It would be valuable to have a method to discover whether or not a program
terminates.
Why not just run it?
* Fundamental limitation to computer science
Quality Assurance II ------------------------------------- slide number 20
The Halting Problem
(A [4mproblem[24m is a set of inputs which we would like to classify by some
program.)
[1mQ[22m: Can we tell whether or not an arbitrary program halts?
[1mA[22m: In general, no!
Intuition for the proof:
[4mThis[24m [4mstatement[24m [4mis[24m [4mfalse.[0m
[1mtrue => false[0m
[1mfalse => true[0m
This contradiction requires:
+o self-reference
+o negation
Quality Assurance II ------------------------------------- slide number 21
Statement & Proof Outline
[1mTheorem: [22mIt is impossible to write a procedure that decides whether an
arbitrary program halts.
[1mOutline: [22mproof by contradiction
1. assume the result is false ([4mi.e.[24m such a procedure -d-o-e-s-exist)
2. define a new program using assumption
3. consider cases when this new program halts
a. if it halts => it doesn't
b. if it doesn't => it does
hence program cannot be constructed, so procedure does [1mnot [22mexist.
Quality Assurance II ------------------------------------- slide number 22
Proof - Step 1
[1mAssume [22mthere is a Boolean procedure DoesHalt? such that:
DoesHalt?(Pfile) returns
-t-r-u-e-if the program represented by Pfile halts and
-f-a-l-s-e-if the program goes into an infinite loop.
[4mPreconditions:[0m
a. Pfile is a text file
b. Pfile represents a syntactically correct program
[4mPostconditions:[0m
a. Pfile is not changed
b. The value -t-r-u-e-or -f-a-l-s-e-is returned as indicated above
Quality Assurance II ------------------------------------- slide number 23
Proof - Step 2
On the file [4mConfound[24m put the program:
/* file Confound */
main( )
#include DoesHalt?
{
if (DoesHalt?( __________ ))
{ /* loop forever */
while ( true ) { };
}
}
(will fill in "__________" later)
[4mThat[24m [4mis,[24m [4mthe[24m [4mprogram[24m Confound [4mhalts[0m
[4mif[24m DoesHalt?(__________)
[4mis[24m FALSE
[4mbut[24m [4mit[24m [4mloops[24m [4mforever[0m
[4mif[24m DoesHalt?(__________)
[4mis[24m TRUE[4m.[0m
Quality Assurance II ------------------------------------- slide number 24
A "Thought Experiment"
Pretend to execute the program by:
1. compiling the program file Confound
2. running the compiled program
That is:
%cc Confound
%a.out
[4mWhat[24m [4mwould[24m [4mhappen???[0m
[4mWould[24m [4mit[24m [4mhalt???[0m
Quality Assurance II ------------------------------------- slide number 25
Proof - Step 3
Two cases: DoesHalt? in Confound
o either returns -T-R-U-E-
o or it returns -F-A-L-S-E-:
[1mcase 1 [22m-
DoesHalt?("Confound") is TRUE
=>
the program loops
=>
DoesHalt?("Confound") is FALSE
[1mcase 2 [22m-
DoesHalt?("Confound") is FALSE
=>
the program halts
=>
DoesHalt?("Confound") is TRUE
Quality Assurance II ------------------------------------- slide number 26
Consequences of Halting Problem
* halting problem takes on many "disguises"
* virtually any program that takes other programs as input is
vulnerable:
* compiler optimization
dead code eliminantiIoFn's, 2n possible paths
* program verification
* concurrency synchronization
* expert systems
* sometimes restrict power to avoid trap
* SQL, other database query languages
exhaustive testing impossible
* in general, a valuable warning
Proving that many conditions are mutually exclusive
=> many fewer possible paths
Q=u>alityeAxshsauursatnicvee ItIes-t-s--m-a-y--b-e--p-o-s-s-i-b-l-e------------------- slide number 27
Testing and Formal Verification
Recall the complexity problem with testing a long chain of IF's:
Quality Assurance II ---------O-M-I-T-T-E-D--f-i-g-u-r-e--------------- slide number 28
Proofs in Practice
* dependence on formal specifications
=>
cannot [4mprove[24m systems with complex interactions
* program proving useful for critical internal modules
- [1ma[22mbstract [1md[22mata [1mt[22mypes (ADT's)
- synchronizations
* proofs complement testing
useful for hard-to-test situations
Quality Assurance II ------------------------------------- slide number 29
Proofs in Practice
Just as the typical mathematician does not
prove theorems using the predicate calculus,
the typical computer scientist should not
prove programs by formal deduction.
Hence
* human-readable proofs
* "programmer's assistant" to handle details
* CASE tools should facilitate use of assertions
Proof-like algorithms often internal
* type checking
* database validation
Quality Assurance II ------------------------------------- slide number 30
Example: Trusted Agents
[4mGoal[24m: admit "foreign" code inside of "firewall"
[4mApplication[24m: network protocol checkers
small, quick
[4mTraditional[24m [4mapproaches[24m: interpretation, bounds checking
essentially, a mini-firewall
[4mAlternative[24m: foreign module -i-n-c-l-u-d-e-s-both code & -p-r-o-o-f-of proper behavior
* use the fact that proof -c-h-e-c-k-i-n-g-is easy even if proof
-d-i-s-c-o-v-e-r-y-is hard
Quality Assurance II ------------------------------------- slide number 31
Ten Commandments of Formal Methods
1. choose appropriate notation
2. formalize but don't over-formalize
3. estimate costs
4. have a formal methods expert on call
5. augment rather than replace traditional methods
6. document sufficiently
7. don't compromise other quality standards
8. do not be dogmatic
9. test, test, and test again
10. reuse
- after Bowan and Hinchley, [4mComputer[24m April
1995
Additional Reading:
R. A. DeMillo, R. J. Lipton, & A. J. Perlis,
"Social Processes and Proofs of Theorems and
Programs," Comm. ACM 22,5 (May 1979),
271-280. responses Comm. ACM 22,11 (Nov.
1979) 621-630.
D. L. Parnas, "Software Aspects of Strategic
Defense Systems," Comm. ACM 28,12 (Dec.
1985), 1326-1335. responses Comm. ACM 29,7
(July 1986), 591-592; 29,9 (Sept 1986),
830-831.
Copyright 2109-2-16, Edward L. Robertson