• Aucun résultat trouvé

8.2 Presentation of the Verification Tools

8.2.1 The L USTRE Tool-Chain

8.2.1.1 Reactive Systems

LUSTREwas originally created to implementreactive systems, as opposed to transformational systems. A transformational system is a system that reads its input, perform a computation, emits an output and then terminates. A reactive system, on the other hand, is a system that never terminates. It periodically reads inputs and responds with outputs. Figure8.1illustrates the way the system interacts with its environment.

Environment Reactive System

Outputs:

Inputs:

{I1, I2, . . . , Ii, . . .} {S1, S2, . . . , Si, . . .}

(with memory)

Figure 8.1: Interaction of a Reactive System With its Environment

Each input emitted is a function of the inputs previously received. In other words, it is a function of the current input and the history kept in the memory of the system.

8.2.1.2 The Synchronous Approach

Thesynchronous approach proved to be a very efficient model to design critical reactive systems. The general constraints for such system are the following:

Bounded memory: The system has to be able to run forever, and runs of a physical system on which memory is finite. To make sure that the system will never go out of memory, we have to make sure that the system’s memory usage is statically bounded (and make sure this bound is lower than the physical memory of the machine). The best way to enforce this requirement is to ban dynamic

124/190 Verimag/STMicroelectronics — 9 d´ecembre 2005 Matthieu Moy

8.2. Presentation of the Verification Tools

memory allocation. This means in particular that the memory of the system can not contain the whole history, but only a bounded subset of this information.

Parallel description: To allow a component-based approach, a reactive system needs to be able to deal with parallelism. “A system with two components” means two components executing in parallel, not one after the other.

Determinism: To validate the implementation of a system, it is desirable to have a deterministic system, i.e. always get the same sequence of outputs from a given sequence of inputs.

The last two requirements are sometimes conflicting, since parallelism can be a source of non-determinism. The synchronous approach solves this problem by introducing the notion of logical global clock: the execution of the system is split into an infinite sequence of instants. At each instant (orclock tick), the system reads some inputs, update its internal memory (or internal state), and emits some output.

Communication and computation is assumed to be done in zero time.

The different components are logically executed in parallel, and in practice, an order of execution is computed statically and deterministically, satisfying data dependency. The execution can be fully sequen-tial although the description is parallel (this mechanism is often referred to ascompiled parallelism).

If a system has no memory, then, the output at each instant is a function of the inputs at the same instant.

Such system is called acombinationalsystem. More generally, the computation performed at each clock tick is called the combinational logic. Computations depending on the value of the memory is called the sequentiallogic.

8.2.1.3 LUSTRE: A Synchronous Data-Flow Language

In the middle of the 1980s, the Verimag laboratory developed the synchronous data-flow language LUSTRE. It was originally developed to suite the needs of control engineers who were used to manipulate systems of equations on data-flows to describe the behavior of their systems, and had to implement those systems on sequential machines.

The basic principle of LUSTRE is that the objects manipulated are infinite sequences of data (X = {x1, x2, . . . , xi, . . .}). Some operators are defined to compose those sequences, and a LUSTREprogram is a set of equations on the sequences in a particular form.

8.2.1.3.1 Combinational Operators. Classical, or combinational operators act on the sequences point by point. For example, the+operator in LUSTREis defined as follow:

X+Y = {x1, x2, . . . , xi, . . .}+{y1, y2, . . . , yi, . . .}

= {x1+y1, x2+y2, . . . , xi+yi, . . .}

The following operators are defined in the same way:

• Boolean operators:or,and,not,xorand implication=>,

• Usual arithmetic operators:+,-,*, real numbers division/, integer divisiondivand modulomod,

• Comparison operators on integers and real numbers: =,>=,>,<=and<>(the=operator can also be used on Boolean),

• Conditional structure: the expression if C then E1 else E2 (where C is a boolean ex-pression and E1 and E2 are 2 expressions of the same type) describe the flow X such that

∀n.ifCnthenXn =E1nelseXn =E2n.

8.2.1.3.2 Operators on Flows. The combinational operators do not allow the behavior to depend on history. LUSTREdefines two operators on streams: pre(for “previous”) and “->” (for “followed by”), defined by:

pre({x1, x2, . . . , xi, . . .}) ={nil, x1, x2, . . . , xi−1, . . .}

Matthieu Moy Ph.D Thesis 125/190

Chapter 8. Back-Ends: ConnectingHPIOMto Verification Tools

=

pre if +

1 0

x accumulator

0 ->

edge counter edge

pre i

false ->

Figure 8.2: Example of a Graphical LUSTREProgram

The operatorpreallows the system to have some memory. The operator->is the necessary comple-ment. Sincepreleads to a flow whose first element is undefined, we need an operator to define the first element of the flow:

{x1, x2, . . . , xi, . . .}->{y1, y2, . . . , yi, . . .}={x1, y2, . . . , yi, . . .}

Those operators are often used together like in

X−>pre(Y) ={x1, x2, . . . , xi, . . .}-> pre({y1, y2, . . . , yi, . . .}) ={x1, y1, y2, . . . , yi−1, . . .}

8.2.1.3.3 Equations. A variablevof a LUSTREprogram is defined by an equation of the form v = expr ;. The equation can be recursive like in n = 0 -> (pre(n) + 1), which defines the flow {0,1,2, . . .}.

8.2.1.3.4 Nodes. A LUSTREnode is a set of inputs, a set of outputs, a set of local variables, and a set of equations. It can be compared to the notion of functions in traditional imperative languages.

8.2.1.3.5 Graphical Syntax. LUSTREprograms can also be defined graphically. The graphical syntax of LUSTREis the one used for its commercial version, SCADETM. It also gives an idea of how a LUSTRE

program could be synthesized in hardware. Flows are represented with wires, and operators are “boxes”

connecting those wires. Figure8.2gives an example of a graphical LUSTREprogram. Figure8.3is the textual form of the same program.

8.2.1.3.6 The EC format. A program in the LUSTRElanguage can use any number of nodes. Nodes can be hierarchical. In Figure8.2, the program is the composition of a nodeedge, that emitstrueon its output whenever the input value changes, and the nodeaccumulatorthat computes the sum of its inputs over time. In the composition, the operatorifis used to transform the Booleantrue/falsein the output ofedgeinto the numerical0/1for the input ofaccumulator. The result is itself a node that could be encapsulated in a larger program, that counts the number of edges on its input.

A LUSTRE program can be “flattened”: all the internal nodes can be inlined into the main node. In the graphical representation, this means simply removing the boxes around the operators. In the textual version, the resulting program contains the union of the equations of the nodes. The resulting format is a subset of the LUSTRElanguage, calledEC.

EC is a very simple language, easy to parse and to manipulate. Most tools manipulating LUSTREcode in the Verimag tool chain use it as an intermediate format (i.e. calllus2ecand work on the resulting file).

126/190 Verimag/STMicroelectronics — 9 d´ecembre 2005 Matthieu Moy

8.2. Presentation of the Verification Tools

1 node edge(i: bool) 2 returns (x: bool)

3 let

4 x = false -> (i <> pre i);

5 tel

6

7 node accumulator(i: int) 8 returns (sum: int)

9 let

10 sum = 0 -> pre(sum) + i;

11 tel

12

13 node edge_counter(i: bool) 14 returns (x: int)

15 var

16 edge_int: int;

17 let

18 x = accumulator(edge_int);

19 edge_int = if (edge(i)) then 1 else 0;

20 tel

Figure 8.3: Textual Version of the Counter Program

1 node edge_counter 2 (i: bool) 3 returns 4 (x: int);

5

6 var

7 V10_edge_int: int;

8

9 let

10 x = (0 -> ((pre x) + V10_edge_int));

11 V10_edge_int = (if (false -> (i <> (pre i))) then 1 else 0);

12 tel.

13

Figure 8.4: EC Version of the Counter Program

Matthieu Moy Ph.D Thesis 127/190

Chapter 8. Back-Ends: ConnectingHPIOMto Verification Tools

Remark: We presented here only the single clock flavor of LUSTRE. LUSTREactually allows different variables to be computed according to different clocks, but we won’t use this feature in LUSSY.

8.2.1.4 Model-checkingLUSTREPrograms:LESAR,GBAC

The set of equations in a EC file can actually be seen as the definition of a function (output,next state) =F(inputs,state)

This is exactly the kind of input a model-checker expects.

LESARis a model checker for LUSTREdeveloped by Pascal Raymond in the Verimag laboratory. Its input is a LUSTREprogram whose first input (necessary a Boolean) gives the property to prove: the property will be “The first output remains true forever”. Any safety property can be reduced to this class of property, but LESARis not able to prove liveness properties.

LESARfirst transforms the LUSTREprogram into an EC program. Then it removes all the numerical variables and replace all conditions depending on Boolean variables by Boolean inputs. The resulting program is a Boolean, flat program.

This program is then encoded using BDDs (as explained in section3.2.1.2). LESARcan use either a symbolic or an enumerative exploration of the state-space. The symbolic exploration can be done either forward (starting with the set of initial states, iterating until an error state is found or the fixed point is reached) or backward (starting with the set of error states, applying the inverse of the transition function until an initial state or the fixed point has been reached).

LESARcan also eliminate some numerically unsatisfiable transition guard: when used with the-poly option, it will represent the conditions appearing on transitions with polyhedra. If a polyhedra is empty, then the transition can be deleted. Of course, the programmer is not supposed to write automata with unsatisfiable transitions, but they often appear when computing the product of several automata.

The tool GBAC, also developed by Pascal Raymond in Verimag is a prototype for the next generation of LUSTREmodel-checkers. It is a symbolic model checker, with several improvements over LESAR, that usually makes it much more efficient. Since it is a prototype, it still doesn’t have all the functionalities of LESAR. The main difference between LESARand GBAC is that LESARcomputes the BDD for the transition function statically whereas GBAC computes the BDD at each step. The resulting BDDs are therefore simpler, since the possible values of state variables are known at the time the BDD is computed.

GBACtherefore performs many small computations (where LESARperforms fewer costly computations) which is in practice much faster in most cases.

8.2.1.5 Abstract Interpretation:NBAC

NBACis part of another family of verification tools: it is an abstract interpreter written by Bertrand Jeannet during his Ph.D Thesis in Verimag. It has been designed to verify properties depending on numerical values, and in particular, counters. Local satisfiability would not be of any help in the case of counters: the value of the counter depends on its previous value at each instant. It is therefore impossible to say anything about it locally.

NBACimplements dynamic partitioning to compute a set of relevant control points, and associates with each control point a superset of the possible valuations of the variables. This information propagates from one control point to another.

Initially, NBACdefines three control points: one representing the set of initial states, one representing the set of states that we want to prove unreachable, and one for all other states. All transitions are supposed to be possible.

128/190 Verimag/STMicroelectronics — 9 d´ecembre 2005 Matthieu Moy

8.2. Presentation of the Verification Tools