The ASTR´
EE Analyzer
Xavier RIVAL
rival@di.ens.fr
EE Analyzer Xavier R IVAL rival@di.ens.fr Certification of embedded - - PowerPoint PPT Presentation
The A STR EE Analyzer Xavier R IVAL rival@di.ens.fr Certification of embedded softwares Safety critical applications avionic softwares but also automotive, space... synchronous Properties to prove to guarantee safety:
rival@di.ens.fr
avionic softwares but also automotive, space... synchronous
absence of runtime errors
synchronous requirement, i.e., time constraint
resource usage
◮ no dynamic memory allocation ◮ stack usage
The ASTR´
EE Analyzer – p.2/36
Inputs a C program (some restrictions, see later) User-defined assumptions about the input values (ranges) Computes an over-approximation of the reachable states Produces an alarm when an operation is not proved safe
◮ Sound: detects all errors ◮ Incomplete: false alarms are possible
MAUBORGNE, A. MIN ´
E, D. MONNIAUX
EE addresses:
Runtime errors Non specified behaviors
The ASTR´
EE Analyzer – p.3/36
ASTR ´
EE covers all executions, hence is sound; testing is unsound
ASTR ´
EE does sound approximation, hence incompleteness
Cost considerations:
ASTR ´
EE is designed to implement the C semantics
ASTR ´
EE uses a quasi-infinite predicate set
ASTR ´
EE lagging for automatic refinement (work in progress)
ASTR ´
EE is automatic with little to no user interaction
But ASTR ´
EE needs to infer indecidable properties; hence is incomplete
The ASTR´
EE Analyzer – p.4/36
ASTR ´
EE project started :
Scalability = main goal
Simple non-relational domains: intervals + first refinements Analysis of a 10 kLOCs software, few alarms (2002)
Inspection of alarms:
Improve precision, with new abstractions,
Successful analysis of two families of industrial applications
The ASTR´
EE Analyzer – p.5/36
declare and initialize state variables; loop forever read volatile input variables, compute output and state variables, write to volatile output variables; wait for next clock tick (10 ms) end loop
No fatal error as defined by the semantics of the C language
No overflow in integer or floating point computations User defined properties: e.g., no NaN! Architecture dependant properties (data-type sizes)
The ASTR´
EE Analyzer – p.6/36
Not all C: no malloc, no recursion Mostly static data ; a few local variables
Size of programs to analyze: > 100 kLOC, > 10 000 variables
Floating point computation should be analyzed precisely
Intricate dependencies between variables:
◮ Stability of computation should be established ◮ Relations between numerical and boolean data to infer ◮ Long sequences of dependences between inputs and outputs
The ASTR´
EE Analyzer – p.7/36
The ASTR´
EE Analyzer – p.8/36
C-99 standard IEEE 754-1985 norm (floating point computations) Assumptions about the target architecture and the area of application :
◮ size of integer data-types ◮ initialization of static variables ◮ ranges for inputs; duration of an execution
The ASTR´
EE Analyzer – p.9/36
EE computes an invariant I ∈ D♯ (D♯: our abstract domain):
For each control point l For each context κ (e.g., calling stack)
M of a set of stores
M expresses a (usually infinite) set of predicates
I should account for all executions in P Meaning of I: γ(I) Soundness statement:
The ASTR´
EE Analyzer – p.10/36
Use an abstract transfer function assign(x = e) : D♯
M → D♯ M
D♯
M: manages addition and removal of constraints
Soundness: this operation should over-approximate concrete executions
For each concrete, elementary step F, a sound approximation computed
M, ρ ∈ γ(d♯) =
D♯
M provides such sound transfer functions: guard, . . .
M provides a sound approximation ⊔ of ∪ The ASTR´
EE Analyzer – p.11/36
A sound approximation ∇ of ⊔; Termination is enforced by the widening properties
U U U while (...) { ... } memorized abstract invariants propagated abstract invariants
Program Iterative invariant computation
The ASTR´
EE Analyzer – p.12/36
sound approximation of join: ∀x, y ∈ D♯
M, γ(x) ∪ γ(y) ⊑ x∇y
termination: for any increasing sequence (yn)n∈ N of elements of D♯
M, the
M defined by x0 = y0 and
Example, with intervals:
In practice: remove unstable constraints
The ASTR´
EE Analyzer – p.13/36
Idea: postpone widening to iteration 2 or 3 More precision in the first abstract join operations
Principle: when x < 4 is not stable, x < 8 may be stable Threshold widening: ordered families of constraints T
Implementation based on strategies such as:
The ASTR´
EE Analyzer – p.14/36
The ASTR´
EE Analyzer – p.15/36
Guard: for conditions (if, while, assert,...) Assign Variable creation, disposal...
If inf♯(x♯, y♯) returns TRUE, then γ(x♯) ⊆ γ(y♯) But the test may fail! (decidability!)
Dozens of domains implemented in ASTR ´
EE...
Need for information communication across domains
The ASTR´
EE Analyzer – p.16/36
1 abstract cell ≡ 1 or several concrete cells (smashed arrays) Information about pointers: points-to
Constraints a ≤ x ≤ b (x: abstract cell) Not an expensive analysis Implementation: sound approximation of floating point computations
EE: started with an interval analysis
Enough to express the absence of runtime errors
Not expressive enough to infer/prove precise invariants
The ASTR´
EE Analyzer – p.17/36
The ASTR´
EE Analyzer – p.18/36
assume(x ∈ [−10, 10]) if(x < 0){y = −x; } else{y = x; } ①if(y ≤ 5) {②assert(−5 ≤ x ≤ 5); }
At point ① :
At point ② :
Analyzer alarm (assert not proved)
Express constraints of the form ±x ± y ≤ c.
◮ At point ①,
◮ At point ②,
More reasonable cost: O(n2) space; O(n3) time (still high)
The ASTR´
EE Analyzer – p.19/36
O(n3) time complexity per operation, if n variables So if n ≡ 10 000: will not work
Pack: small group of variables to relate Strategy and heuristics used to choose packs
◮ syntactic pre-analysis: variables “used together” ◮ possibility to add user-defined packs (rarely needed)
Cost: linear in the number of packs
The ASTR´
EE Analyzer – p.20/36
Linearized forms can be handled by an octagon transfer function Interval constraints used to make the transformation
Semantics of octagons in terms of real numbers Linearization bridges the gap with the floating point values
The ASTR´
EE Analyzer – p.21/36
D♯
M, γ is reduced iff γ(x♯) = γ(y♯) ⇒ x♯ = y♯
◮ most domains are not reduced; ◮ this is source of imprecision
Reduction: should map x♯ into a more preicse y♯ Non reduction may cause incompleteness of the ordering
Principle:
Cost considerations: cubic cost, hence should be used sparsely
Use the more precise bounds found above, to refine interval constraints Get more precise constraints from other domains (some described later)
The ASTR´
EE Analyzer – p.22/36
The ASTR´
EE Analyzer – p.23/36
int x, sgn;
l0 if(x < 0){ l1 sgn = −1; l2 }else{ l3 sgn = 1; l4 } l5 y = x/sgn; l6 . . . at l2, x < 0, sgn = −1 at l4, x ≥ 0, sgn = 1 at l5, sgn ∈ {−1, 1}
At l5, approximation: sgn ∈ [−1, 1] Consequence: the division is not proved safe (alarm at l5) Clearly, sgn = 0 for any real execution (false alarm)
The ASTR´
EE Analyzer – p.24/36
Invariant at l5:
Results:
◮ The division is safe ◮ Invariant for y at l6: y ≥ 0
We simply focus on the control history: Invariant at l5:
l0 if(x < 0){ l1 sgn = −1; l2 }else{ l3 sgn = 1; l4 } l5 y = x/sgn; l6 . . . The ASTR´
EE Analyzer – p.25/36
l0 if(x < 0){ l1 sgn = −1; l2 }else{ l3 sgn = 1; l4 } l5 y = x/sgn; l6 . . . P0
(l0) (l1, TRUE) (l2, TRUE) (l5, TRUE) (l3, FALSE) (l4, FALSE) (l5, FALSE) (l6)
P1
(l0) (l1, TRUE) (l2, TRUE) (l5, TRUE) (l3, FALSE) (l4, FALSE) (l5, FALSE) (l6, TRUE) (l6, FALSE)
The ASTR´
EE Analyzer – p.26/36
Partitions Hierarchy of domains P P1 P0 D[P] D[P1] D[P0]
The ASTR´
EE Analyzer – p.27/36
If statements: delayed abstract join Loop unrolling: distinguish the n first iterations; delay the abstract join Variable value: distinguish all possible values of a variable
◮ do not partition if too many values ◮ possible values are determined by the analysis
Exhaustive application of the criteria would not scale up
◮ huge number of partitions available ◮ most partitions are of no interest or may play against widening
Strategies: determine which partitions to consider
◮ where to distinguish flow paths ◮ where to merge distinguished flow paths
The ASTR´
EE Analyzer – p.28/36
x y 1 1
y = −1 if x ≤ −1 −0.5 + 0.5 × x if − 1 ≤ x ≤ 1 −1 + x if 1 ≤ x ≤ 3 2 if 3 ≤ x l0 :
int i = 0;
l1 : while(i < 4 && x > tx[i + 1]) l2 : i ++ ; l3 : y = tc[i] × (x − tx[i]) + ty[i] l4 : . . .
No relation between x and the slope
Analysis, with input x > 0, output possibly unbounded (slope in blue)
The ASTR´
EE Analyzer – p.29/36
The ASTR´
EE Analyzer – p.30/36
j
Switch
b i z-1
Unit delay
z-1 B
+ + +
t x(n)
Unit delay Switch Switch
Xn =
In
X U F(X) X F(X)
F(X) X X U F(X)
The ASTR´
EE Analyzer – p.31/36
x = 1.0; while(TRUE){① x = x/3.0; x = x ⋆ 3.0; }
Constraint | x |≤ A · Bn + C,
Number of iterations: bounded bu N: ⇒ | x |≤ A · BN + C
Domains using mathematical theorems proved once for all (design of the
Beyond what automatic refinement can do!
The ASTR´
EE Analyzer – p.32/36
bp = x ≤ 0.; bn = x ≥ 0.; ①if(bp && bn) ②y = 0.0; else y = 1.0/x;
bp = FALSE ⇒ x = 0 bn = FALSE ⇒ x = 0
bp bn x < 0 x = 0 x > 0 T F T F
Nodes labeled with boolean variables Leaves: values in a numerical domain
Same as in the case of octagons; Also addresed with a variable packing strategy
The ASTR´
EE Analyzer – p.33/36
The ASTR´
EE Analyzer – p.34/36
The ASTR´
EE Analyzer – p.35/36
Memory model, to analyze low level features Asynchronous softwares (ongoing) Automatize alarm diagnostics...
Accademic version website:
http://www.astree.ens.fr/
Absint website:
http://www.absint.com/astree/
The ASTR´
EE Analyzer – p.36/36