Download Dynamically Discovering Likely Program Invariants to Support Program Evolution | CSCI 780 and more Exams Computer Science in PDF only on Docsity!
10/15/2003 1
Dynamically Discovering
Likely Program Invariants to
Support Program Evolution
by
Michael D. Ernst
Jake Cockrell
William G. Griswold
10/15/2003 2
Outline
Role of Invariants
Daikon Description
Simple Example
Choosing What to Infer
How Daikon Works
Daikon in Use
Scalability of Daikon
Use of Test Suites
Future Work
Summary, Critique, and Discussion
10/15/2003 3
Role of Invariants
Program development
Refining specification into a correct program Static verification of properties (type declarations) Runtime checking (assert statements)
Software evolution
Prevents changes from violating assumptions for correct behavior
Documentation of program’s operation
and data structures
10/15/2003 4
Inferring Invariants
Inferred statically or dynamically
Dynamically inferred invariants are
inferred from captured variable traces
Depend on the test suite
Uses
Double-check existing documentation Indicate a bug Assist in test-case generation or validate a test suite
Daikon
Dynamic invariant detector
Runs program with a test suite
Infers invariants from program runs
Can detect context-dependent
properties
Static analyses are limited
Typically sound, but conservative
Limited by uncertainty
Simple Example
Array Sum Program
i, s := 0,0;
do i != n ->
i, s := i + 1, s + b[i]
od
Precondition: n >= 0
Postcondition: s = (Σj : 0 <= j < n: b[j])
Loop invariant: 0 <= i <= n and s = (Σj : 0 <= j < i : b[j])
10/15/2003 7
Array Sum Program
Preconditions, postconditions, and loop
invariants were specified by author
Ran Daikon on 100 randomly-generated
arrays of length 7 to 12
Found the fundamental invariants
S = sum(B) (postcondition)
Also found some not specified by author
N = size (B) (obvious?)
Shows potential, but not overly
impressive
i, s := 0,0; do i != n -> i, s := i + 1, s + b[i] od
10/15/2003 8
Choosing what to Infer
Invariants involving a single variable
x ε {a, b, c} (limited values) x <= a
Invariants involving multiple variables
x = ay + bz + c x >= y
Invariants over sequence variables
min/max, range, nondecreasing x is a subsequence of y
10/15/2003 9
Performing the Inference
Infers at specific program points
Procedure entries and exits Loop heads
Each potential invariant instantiated and
tested for each variable or variable tuple
Only checked once if shown false Cost roughly proportional to number of invariants discovered
Does not include all potential invariant
types
Users can add their own invariants 10/15/2003 10
Performing the Inference (2)
Computes invariant confidences
Probability that property is random
Only reports invariants above specified
confidence level
Avoids long list of spurious invariants
Larger, more complete test suite helps
- Shows counterexamples
- Adds to confidence if it agrees
Performing the Inference (3)
Derived Variables
Derives variables, treated like all others
Derived from a sequence
Size(s) S[size(s)] Sum(s)
Derived from a sequence and variable i
s[i] Subsequences: s[a..b]
Derived in iterations
Stops computing derivations of derivations after a fixed number of iterations
Program Instrumentation
Daikon instruments the program to
output information
All values of variables in scope written to
data trace file at each program point
Daikon operates only with scalar numbers
and arrays of numbers
Use Abstract Syntax Trees to determine
variables in scope
Insert code at program point to dump
variable values into output file
10/15/2003 19
Analysis
Invariants provide insight that would be
difficult to manually extract
Leads to thinking in terms of invariants
Fewer errors
Reveal facts that would not have been
noticed
2 Daikon tools were useful
Trace database queries Invariant set comparator (for changes)
10/15/2003 20
Scalability
Factors leading to increased costs
Number of program points
- Proportional to program size Number of variables
- Potentially cubic (tuples involve up to 3)
- Most important factor Number of invariants checked Number of test cases
Analysis of portion of large program same
as an entire small program
10/15/2003 21
Test Suites
Play a large role in Daikon
Too few test cases
Small number of invariants (not justified statistically) Spurious invariants
Too many test cases
Linearly increases run time
Range where benefit per test-case
increase is greatest
Program correctness improves invariants
10/15/2003 22
Test Suite Generation
Randomly-generated
Ineffective Miss many portions of code Many inputs are invalid, wasting time
Grammar-generated
Random, but generated from grammar describing valid inputs More effective, but more effort Can be simplified by allowing some errors
Future Work
Increase the relevance of discovered
invariants
Improve performance
Very little optimization used Much room for improvement
Better invariant view tools
Easier to find relevant invariants Could categorize or predict usefulness
Richer Invariants
Discover over pointer-based recursive data structures
Summary
Discovering invariants on execution
traces can be feasible and effective
Found all invariants in set of
formally-specified programs (sort of)
Useful in software evolution task
Using method can qualitatively
affect programmers
Useful invariants at acceptable cost
Critique
Paper makes positive aspects sound
better than they are
“automatically detected all the stated invariants in a set of formally-specified programs” “invariants erroneously omitted from the formal specification but detected by Daikon”
Would be very slow for large programs
Does show some positive qualities though
Discussion
What types of programs would Daikon be
good/bad for?
Is it too slow for legitimate use? (563 line
C program w/ 21 procedures, 3000 test
cases: 540 seconds)
Is the reliance on the test suite a major
problem?
Other Potential Uses?
Too cumbersome with useless invariants
output?