Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeContact

The text of a manual · part 4 of 14

Feasibility of formal model checking in the Vitatron environment: Chapter 2Model checking, pages 11 to 18

Pages 11 to 18 of 91, from Feasibility of formal model checking in the Vitatron environment

The original document is the PDF (6.4 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.

Filed in the catalog under the Vitatron EE244

Page 11

Chapter 2

Model checking More general information about model checking can be found in [6] and [14]. Many software and hardware systems are composed of separate components that are being executed in parallel and together define the behavior of the system by interacting with each other. The system behavior is represented by all possible sequences of actions that a system can perform during its lifetime. Such a system whose functionality is distributed over two or more components is also called a distributed system. A component of a distributed system does not contain any concurrency and is described as a sequence of operations on a set of inputs, possibly resulting in one or more outputs. When designing a large distributed system consisting of several components, it is generally very hard to maintain a clear picture of the overall behavior of the system. The number and the size of all possible executions of a distributed system are exponential in the number of possible input combinations and in the number and the size of the system components. Execution must be understood as the action sequence that is performed by the system in response to one particular set of inputs. It is often impossible to analyze all these executions separately when one wants to check whether the system behavior satisfies its requirements. One possible tactic to verify such systems could be verifying whether the executions that result from the mostly occurring input combinations, are valid. But this generally leaves a rather big number of executions unverified, which could possibly contain an execution that does not satisfy the requirements. Model checking is a formal method that has been developed for extensively analyzing and verifying complex distributed systems. The model checking method aims at guaranteeing that all executions of the analyzed system satisfy the system requirements, or if these requirements are not met, the method tries to provide information about the circumstances (the particular inputs and system settings) in which the system is not correct. To provide such an automatic and complete verification method of distributed systems, formal analysis techniques and tools are developed. These techniques require a formal model which is an abstraction of the behavior of the analyzed system. By modeling the system behavior, the responsibilities of the system components and the communication between them are made explicit. Often the system is only partially formalized, because some parts are not relevant for the system requirement that is verified. Each modeled system component translates to one or more concurrent processes in the formal model. Depending on the nature

10

Page 12

of the system, one or more concurrent processes can be contained to provide inputs to the processes that represent the system. Figure 2.1 shows how system, formal model and model checking relate to each other.

Figure 2.1: The model checking process Because the modeled system can be very complex, it is generally also difficult to get a valid formal model of the system. Therefore it is wise to use a kind of iterative modeling approach in which the formal analysis techniques are used to find flaws in the model. These flaws can be corrected after which the model can again be analyzed, etc. Eventually this hopefully will result in a valid formal model of the system. As a running example for this chapter consider a simple coffee machine system. The system is designed to deliver coffee, tea or water to the user; the user should be able to choose for coffee, tea or water by pushing the button choose coffee, choose tea, or choose water respectively. After choosing a drink, the user can insert money and the machine starts preparing when at least 30 cents are inserted by the user. When the drink has been prepared, the machine serves the drink to the user and returns the money that is paid too much. The coffee machine system is represented as a state transition diagram in figure 2.2. Unfortunately the required ‘choose water’ option has not been included in the design, which is reflected by the absence of a choose water transition in the figure. Although the coffee machine system is not a real distributed system, because it consists of only one component, it will be useful to explain the basic notions of model checking.

11

Page 13

choice : {tea, coffee, water }; paid : N;

choose coffee choice = coffee choice = tea; paid = 0 ;

wait start paid < 30 → coin(y : Nat) paid = paid + y choose tea choice = tea return(paid ) paid = 0 paid ≥ 30 → prepare(choice)

served prepared serve(choice) paid = paid − 30

Figure 2.2: Coffee machine system Because we do not use a standard notation in figure 2.2, a few notation issues must be addressed. In the dashed rectangle the variables choice and paid are declared that are set when the user chooses a drink or inserts a coin, respectively. A label on a transition may consist of the following fields: a guard followed by an arrow which indicates under which condition this transition may be taken, the action that will cause the transition to be taken, and assignments to variables of the process (below a horizontal line). Each transition must have exactly one action in its label, but there may be zero or multiple guards and variable assignments in a label. Note that a small incoming arc to state ‘start’ indicates that ‘start’ is the initial state of the process. This arc also has a label in which the variables choice and paid are initialized. The action coin has an argument y to indicate what value the inserted coin has. The problem of proving that a requirement holds for a given model is called the model checking problem. In our coffee machine example, you want to be sure that the user always gets the drink of his or her choice, provided that enough coins are inserted. If you are verifying a data communication protocol, you want to make sure that a sent message always will eventually reach its recipient and nobody else than the recipient. Such requirements can be expressed in a logic formula, which together with the formal model forms the input to a model checker. The model checker either reports that the requirement holds or does not hold. Depending on the kind of formula and the result of the verification, the model checker can provide a counterexample trace or witnessing trace, which is a sequence of actions leading to a state in which the requirement is violated or satisfied, respectively. Such a counterexample potentially can provide useful feedback to improve the model and the modeled system itself. Notice that the described behavior of a model checker is somewhat idealized. Often the available resources are not sufficient to analyze the complete model and then simplifications of the model are needed to make model checking possible. The challenge is to choose the right simplifications to be sure that the analyzed model still represents the behavior of (the modeled part of) the original system. Otherwise a confirmation of the verified requirement is of limited value, because there could be a flaw in a part of the system behavior that is left out due to simplifications. 12

Page 14

2.0.1

State space generation

To describe the basic mechanism of a model checker, we first introduce the notion of the model state space. Depending on all previously performed actions the model of the analyzed system resides in a certain state which can be seen as a vector of the values of all component variables and the states of the individual components. For example, the coffee machine system from our example can be straightforwardly translated to a formal model in which the states are depicted by (state, choice, paid ) vectors. In such a formal model, the initial state is given by (start,tea,0) and performing action choose(coffee) in the initial state will move the model to state (wait,coffee,0). Each model has an associated state space, consisting of all states that are reachable from the model’s initial state. Under the assumption that all states of the formal model of the coffee machine system are reachable from its initial state, the state space of this model would be infinitely large, because the variable paid is a natural number. In figure 2.3 a schematic overview of all combinatorial possibilities is given. served prepared state wait start water coffee choice tea 0

1

2

3

4

5 paid

Figure 2.3: Possible states of the coffee machine system Though in reality there are limitations: the values of the coins that can be inserted are discrete; assume for now that only coins of 5, 10 and 20 cents are accepted by the coffee machine. Furthermore, the system’s state transition diagram of figure 2.2 makes clear that it is not possible to insert any more coins when already at least 30 cents have been inserted and that the user can not choose for water. We shall see that these limitations make the actual state space of the coffee machine model finite. A model checker generates the state space in order to make requirement verification possible. For this generation an algorithm is used that explores the state space from the initial state until it no longer finds new states. The precise order in which the states are explored depends on the used algorithm; this can for instance be a breadth-first search, a depth-first search or a random search algorithm. Here we only address the breadth-first search algorithm; this algorithm starts by exploring which states are reachable from the initial state by taking all possible transitions out of the initial state. The newly discovered states are added to the state space together with the transitions leading to them. The added states are said to be on level 1 of the state space, because they are reachable in one step from the initial state. When all discovered states are added to level 1, the initial state is said to be ‘explored’. In the second iteration the algorithm explores which states are reachable from the states on level 1; any newly found state is added to the state space again (on level 2) together with the 13

Page 15

transition leading to it, except when a found state is already present in the state space only the transition leading to it is added. If all states of level 1 are addressed by this procedure, the second iteration is finished and the algorithm iterates by exploring the states on level 2. The iteration stops if exploration of the states on a certain level does not discover new states, which means that all states in the state space have been explored after the exploration of this level. The state space generation results in a labeled transition system in which all transitions represent one single atomic action. For the coffee machine example, the state space is shown in figure 2.4. Note that the initial state is again marked with a small incoming arc. However there is no action on this arc, because variable initialization is made implicit by entering state (start,tea,0).

Figure 2.4: State space of the coffee machine system Although the state space of the coffee machine model is finite, its size can be even more reduced by improving the system’s state transition diagram of figure 2.2. The money that is paid too much is returned after serving the requested drink through which there are eight states in the state space for the machine state ‘served’. If the too much paid money should be returned before serving the drink there would be only two states (one for each possible drink) for ‘served’ in the resulting state space. This is a small example of how the architecture of the modeled system influences the size of the state space. The generated state space is explored by the model checker in order to verify the given requirement to the system. Basically it traverses all states consecutively and continuously checks whether the current state satisfies the requirement. Sometimes it is not required to

14

Page 16

traverse all states, but this depends on which kind of property is verified. For example, if it is questioned whether action a is ever performed in the state space, the verification can stop on the detection of one single a action, which possibly can be very soon. But when the state space does not contain any a action the complete state space must be explored before the algorithm can give its judgment.

2.0.2

Formulating model requirements

As already noted, a system requirement must be formulated in some kind of logic before a model checker can verify it. Propositional formulas over state variables are the most basic formulas. In such formulas, it can for instance be specified that a certain variable is at most 10 in the entire state space. Presuming that the user of our coffee machine is not able to choose water can be the reason that we want to verify whether the variable choice ever gets the value water in the state space of the coffee machine model. The model checker then traverses all states to check whether choice = water and will report that there is no state that satisfies the specified property. Clearly propositional logic is not expressive enough, because we can not specify anything about actions that are performed by the modeled system. Therefore there are more expressive logics which can be classified into non-temporal and temporal ones; temporal logics are the more expressive of the two types. Which specific logics can be used in model checking depends on the used tool, but generally all model checkers accept formulas in propositional, nontemporal, and temporal logics. We give some examples in temporal and non-temporal logic in order to indicate their differences. It is important to notice that the initial state is the reference point of all formulas in temporal and non-temporal logics. For explaining non-temporal logics and giving examples for these logics we use the HennessyMilner logic ([13]; also introduced in chapter 4 of [11]). Its syntax is given by the following grammar: φ ::= true | false | ¬φ | φ ∧ φ | φ ∨ φ | haiφ | [a]φ. The primitive formula true is valid in all states of a model and false is never valid in any state. The logical operators have their usual meaning and can be used to compose logic formulas. The two special constructs of the Hennessy-Milner logic are the diamond modality and the box modality. The diamond modality haiφ expresses that there is a transition labeled with action a and leading to a state in which the formula φ holds. The box modality [a]φ expresses that all transitions labeled with action a lead to a state in which formula φ holds. Now if we want to verify whether the user can choose coffee in our coffee machine system we formulate a formula as follows: hchoose coffeeitrue. The formula [choose water ]false expresses that whenever an action choose water is done, a state is reached where false is valid. Because false is not valid in any state, the formula expresses that an action choose water is not possible. The formula hchoose coffeeihcoin(20 )ihprepare(coffee)itrue expresses that the action sequence choose coffee, coin(20 ), prepare(coffee) is possible from the initial state, which is clearly not valid, because the machine can not start preparing coffee before enough money is inserted. As mentioned above, all logic formulas are evaluated in the initial state of the system. Because non-temporal logics do not provide the ability to specify an arbitrary action sequence, we can not specify that a certain requirement must hold during the entire lifetime of the system. Should the coffee machine model contain a flaw such that the coffee machine runs into a deadlock after serving the first drink in its lifetime, the truth values of the above 15

Page 17

mentioned formulas will remain the same, although the model behavior certainly does not satisfy its requirements. You want to make sure that the coffee machine operates as required during its entire lifetime. For this purpose, the property must be specified in a temporal logic. For example, the property “after choosing coffee the machine always eventually serves my coffee” is not expressible in non-temporal logics, though it is expressible in temporal logics. As the word temporal already says, a temporal logic deals with ‘time’, where performing actions must be understood as passage of ‘time’. In a temporal logic it is possible to express that a formula is always valid, eventually valid or valid until some other formula is valid. We give some examples in temporal logic, using the same Hennessy-Milner logic extended with regular expressions. In this extension more than just a single action is allowed in a diamond or box modality. See [11] for a description of this extension. With this extension it is possible to formulate the above property. We give the corresponding logic formula for the interested reader: [true ∗ · choose coffee]htrue ∗ · serve(coffee)itrue. Literally this formula says that if after a certain sequence of zero or more arbitrary actions (expressed by true ∗ ) an action choose coffee is possible, then after that an action serve(coffee) is possible after a certain sequence of zero or more arbitrary actions. A stronger property that can be formulated in temporal logic would be “after choosing coffee the machine will not process any other request before serving my coffee”. This is formulated as follows: ∗

[true ∗ · choose coffee]hchoose coffee ∪ choose tea ∪ choose water · serve(coffee)itrue. Literally this formula says that if after a certain sequence of zero or more arbitrary actions an action choose coffee is possible, then after that an action serve(coffee) is possible after a certain sequence of actions, not containing choose actions. Sometimes the nature of the model makes it hard to translate a requirement into a logical formula. Then an alternative option is to add an action to the model which can only be performed if the requirement is not satisfied. Assume that we want to verify that the variable paid in the coffee machine model never becomes greater than 50 in state ‘wait’; then we add a loop transition (a transition from a state to itself) to ‘wait’ with a guard ‘paid > 50’ that performs the action alarm. Verifying the requirement then is a matter of specifying in a simple logic formula that the action alarm can be performed after zero or more arbitrary actions: htrue ∗ · alarmitrue. If the model checker reports that the formula is true, it is guaranteed that the requirement is not true; the model checker might provide a witnessing trace which specifies an action sequence that leads to the performance of action alarm. This trace can be inspected to find the flaw in the system. On the other hand, if the model checker reports that the formula is false, the model is guaranteed to satisfy the requirement. Some model checkers also can be instructed to detect certain actions during state space generation; then a message is printed to the screen or to an output file for each such action that is detected during state space generation. Whether this method is suitable heavily depends on the model and the requirement in question.

2.0.3

Model checking tools

As already said, there are various model checking tools available. Some of the most known tools are SMV, SPIN, CADP, mCRL2, and Uppaal. In this project mCRL2 and Uppaal are 16

Page 18

investigated as a model checking environment for the formal models representing the firmware designs of Vitatron. In sections 2.1 and 2.2 these tools are introduced.

2.0.4

The state space explosion problem

The generated state space can become very large for many real-world problems. This is a well-known problem in the field of model checking and is called the state space explosion problem. Not only the time and space resources to generate such large state spaces can be a problem, but also the model checking on a large state space is a difficult job even for the most efficient algorithms. Most model checkers provide techniques to enable model checking without generating the complete state space. Such techniques can have drastic influence on the time and space required for model checking and can be of various kinds: • “on-the-fly”-verification of properties during state space generation. In some cases it is not even necessary to explore the complete state space when verifying a property; this happens when a witness or, on the contrary, a counterexample is found during the process of verification. This technique is used by the pbes2bool tool in mCRL2 (see section 2.1.3) and also in Uppaal (see section 2.2). Also SPIN and CADP are “on-the-fly”model checking tools. • Symbolic model checking; algorithms for symbolic model checking avoid ever generating and storing the state space. Instead, they generally represent the state space using a formula in propositional logic. On such a formula, properties can be verified purely by manipulations of the formula. See [16] for more information about symbolic model checking. Recently also the use of resolution provers has become popular in the field of model checking. Symbolic model checking forms the basis of the tool SMV and is also used by the model checking tools in the mCRL2 toolset (see section 2.1.3). • Partial order reduction or τ -confluence can be used to reduce the number of independent executions of concurrent processes that need to be considered. The basic idea is that if it does not matter for the property that you want to check whether a or b is executed first, then it is useless to consider both the ab and the ba executions. • Abstraction; when using this technique, you first simplify the model by abstracting from the internal behavior of the model that is not relevant for the property that is verified. The simplified system usually does not satisfy exactly the same properties as the original one, but generally, it is required that the abstraction is sound (properties that are proved on the abstraction are true of the original system). However, most often, the abstraction is not complete (not all true properties of the original system are true of the abstraction).

2.1 mCRL2 mCRL2 is a formal model specification language with an associated toolset. The toolset is available at [2]. mCRL2 stands for milli Common Representation Language 2 and is the successor of µCRL. The language and its toolset are developed at the department of Mathematics and Computer Science of the TU/e, in collaboration with LaQuSo and CWI. 17