Difference between pages "Code Generation Tutorial" and "Event-B Statemachines"

From Event-B
(Difference between pages)
Jump to navigationJump to search
imported>Andy
 
imported>Vitaly
(New page: frame|left ==Overview== Event-B Statemachines Plug-in is part of the iUML-B experimental tool that focuses on UML-B and Event-B integration. The plug-in provides ...)
 
Line 1: Line 1:
'''This Page is Under Construction!!!!'''
+
[[Image:IUMLB_big.png|frame|left]]
  
=== Tutorial Overview ===
+
==Overview==
  
The aim of the tutorial is to allow users to explore the approach with a relatively simple example. The example uses a shared buffer with reader and writer processes. The tutorial is presented in three stages, making use of the example projects from the download site. There are two translations performed, one is to a common language model (IL1). The second is to an Event-B project which includes a model of the implementation. There is a PrettyPrinter for Ada source code, which uses the common language model. An overview of Tasking Event-B can be found at http://wiki.event-b.org/index.php/Tasking_Event-B_Overview.
+
Event-B Statemachines Plug-in is part of the iUML-B experimental tool that focuses on UML-B and Event-B integration. The plug-in provides a way of adding state machines directly to Event-B machines and is capable of translating former to Event-B language. It also offers a UML-like diagram editor for state machines, as well as state machine animation, which can be installed as additional plug-in that runs on top of ProB Animator.
  
A typical Event-B development may be refined to the point where it is ready for implementation, but the Event-B language is not expressive enough to fully describe the implementation. Tasking Event-B facilitates this final step to implementation, by extending Event-B with the necessary constructs. Event-B machines that are to be implemented (and their seen Contexts) are selected and added to a ''Tasking Development''; the Tasking Development files have the file extension ''.tasking''. The machines in the Tasking Development are then extended with implementation details.
+
==Installation==
  
The example/tutorial projects are,
+
The Event-B Statemachines plug-in is available for installation from Rodin update site under Modelling Extensions category. Animation plug-in for it is available from Verification and Validation category. Both plug-ins require EMF and GMF frameworks, Event-B EMF framework, ProB, OCL and QVT - all of these dependencies will be installed automatically upon plug-in installation.
  
{| border="1"
+
==Using the tool==
|SharedBuffer20100819Demo
 
|An example project with a completed Tasking Development and IL1 model (post IL1 translation, but before Event-B translation).
 
|-
 
|Sharedbuffer20100819Tasking
 
|Same as the example project above, but with Event-B model translations. The difference being that this development includes a model of the implementation. These are refinements that include a program counter to describe flow of execution in each task.
 
|-
 
|SharedBuffer20100819Tutorial
 
|A bare project for step 1 of the tutorial.
 
|-
 
|Sharedbuffer20100819Tutorial2
 
|A partially completed tasking development for steps 2 and 3 of the tutorial.
 
|}
 
  
== Preliminaries ==
+
The tool consists of a standard UML-like graphical editor for state machine diagrams, and integration to Event-B Explorer and a translator to Event-B language. Some of these may seem familiar to you if you have experience with UML editors or UML-B plug-in for Rodin.
Before further discussion of the modelling aspects, we take a look at the PrettyPrint viewers. The PrettyPrinters make the viewing of IL1 and tasking models easier; it also provides a route to generate source code. The source code can easily be pasted from the IL1 Pretty Printer window into an the Ada source file .
 
==== The PrettyPrint View of a Tasking Development ====
 
To open the Tasking PrettyPrint viewer,
 
* from the top-menu select ''Window/Show View/Other/Tasking Pretty Printer''.
 
  
Note that the Tasking PrettyPrinter may have to be closed when editing the Tasking Development, since it can give rise to exceptions. The PrettyPrinter would need further work to make it robust, however it is intended only as a short-term solution.
+
====Event-B Explorer====
  
* Open the ''SharedBuffer20100819Demo'' Project and switch to the Resource Perspective.
+
[[Image:New_statemachine.png|thumbnail|State machine in Event-B Explorer]]
* Open the ''.tasking'' model and inspect it. Clicking on the Main, Machine or Event nodes updates the pretty print window.
 
  
==== Viewing Source Code ====
+
To start the modelling all you have to do is to select a machine in Event-B Explorer that you would like to extend with state machines and click on ''Create new statemachine'' from explorer's toolbar. An input dialog will appear asking you for name of a new state machine. After that you should be able to see a new state machine appearing as a child of machine in explorer.
aka. The PrettyPrint View of an IL1 Model.
 
  
To view Ada source code,
+
The explorer also shows the contents of state machines, including states, transitions and annotations. You can customise the amount if information you would like to see by going to explorer's menu (a small triangle at the top right-hand side) ''> Customize View.. > Filters'' tab. There are three filters defined for state machines: ''Annotation Filter, Transition Filter, State Filter'' - that hide corresponding elements in explorer (state filter hides simple states, like initial, final or ANY).
* from the top-menu select ''Window/Show View/Other/IL1 Pretty Printer''.
 
* Open the ''SharedBuffer20100819Demo'' Project and switch to the Resource Perspective.
 
* Open the ''.il1'' model and inspect it. Clicking on the Protected, Main Entry, or Task nodes updates the pretty print window.
 
  
==== Cleaning the Tasking Development ====
+
In addition, there are ''Open'' and ''Delete'' actions available for state machine in context menu of explorer. These allow to open a state machine in editor (shortcut is double-click) and delete a state machine (shortcut is Delete key). In the machine context menu there are two more actions related to state machines: ''Refine with statemachines'' and ''Delete generated'' - which allow correspondingly to create a refinement of machine with state machine refinements (not available yet from standard ''Refine'' action of Rodin) and to delete all Event-B elements generated by state machines (required only for experimental purposes if generated things/diagrams get corrupted).
If the ''.tasking'' file has errors, then it may need cleaning. To do this right-click on the ''Main'' node, select ''Epsilon Translation/CleanUp''. If a model has errors it can still be viewed by clicking on the ''Selection'' tab at the bottom of the tasking editor window.
 
  
== The Tutorial ==
+
====Diagram Editor====
The steps needed to generate code from an Event-B model, in this tutorial, are as follows,
 
* Step 1 - Create the tasking development. [http://wiki.event-b.org/index.php/Code_Generation_Tutorial#Creating_The_Tasking_Development Create the tasking development].
 
* Step 2 - Add annotations.
 
* Step 3 - Invoke translators.
 
  
==== Creating The Tasking Development ====
+
[[Image:Statemachine editor.png|thumbnail|left|State machine diagram editor]]
* Change to the Event-B Perspective.
 
* Open the ''SharedBuffer20100819Tutorial'' Project.
 
* Select the following Machines: Reader, Writer and Shared.
 
* Right-click and select ''Make Tasking Development/Generate Tasking Development''.
 
  
The new Tasking Development will not be visible in the Event-B perspective, change to the resource perspective, open and inspect the new ''.tasking'' file. The Tasking Development contains (the EMF representation of) the machines that we wish to provide implementations for. In order to introduce the new concepts we have prepared a partially complete development.  
+
To edit a state machine in diagram editor you simply double-click it. The tool creates a diagram file for you with the same name as root state machine.
  
Change to the Project ''SharedBuffer20100819Tutorial2'' to begin the next step.
+
Working with the editor is straightforward. The element creation tools are available from palette, divided into three categories: ''States'', ''State Features'' and ''State Links''. When a diagram element is selected on canvas the Properties View shows its available properties (if you cannot find it, please go to Rodin's menu ''Window > Show View > Properties''). After a state machine is complete it can be validated to make sure it has no semantic errors and translated to Event-B. When translated, it can be animated with ProB.
  
==== Providing the Annotations for Implementations ====
 
* Close any Tasking Pretty Print Viewers that remain open. The incomplete model will give rise to exceptions.
 
* Go to the to the Resource Perspective.
 
* Open and inspect the ''.tasking'' machine.
 
  
The ''WriterTsk'' and ''SharedObj'' machines are incomplete. We will take the steps to necessary to provide implementation details.
 
  
===== The WriterTsk Machine =====
 
In the partially complete tutorial project we already identified the ''WriterTsk'' as an ''Auto Task'' Tasking Machine, by adding the ''Auto Task'' extension. ''Auto Tasks'' are tasks that will be declared and defined in the ''Main'' procedure of the implementation. The effect of this is that the ''Auto Tasks'' are created when the program first loads, and then activated (made ready to run) before the ''Main'' procedure body runs. We have added the ''Periodic Task'' extension to the ''Auto Task'', and set a period of 250 milliseconds. We will now complete the sequence that has been partially defined in the task body.
 
  
*'''Add Synchronisation between TWrite and SWrite'''.
 
** Expand the ''Auto Task Machine'' node.
 
** Expand the ''Seq'' sub-tree.
 
** Right-click on the ''Seq'' node and select ''New Child/Left Branch EventWrapper''.
 
** Provide the event label ''w1'' using the properties view.
 
** Right-click on Event Wrapper and select ''New Child/ Synch Events''.
 
** Select ''Synch Events'' and go to the drop-down menu of the ''Local Event'' property.
 
** At this point the drop-down box displays a number of event names, select the ''TWrite'' event.
 
** Go to the drop-down menu of the ''Remote Event'' property.
 
** From the list of events select the ''SWrite'' event.
 
  
The Synch Events construct is used to implement [http://wiki.event-b.org/index.php/Tasking_Event-B_Overview#Control_Constructs Event Synchronisation]. The next step wraps an event in an Event Wrapper in order to update the local state; there is no synchronisation as such but we will re-use the constructs that already exist.
 
  
*'''Add the Wrapped Event TcalcWVal'''.
 
** Expand the sub-tree of the second ''Seq'' node.
 
** Right-click on the ''Seq'' node and select ''New Child/Left Branch EventWrapper''.
 
** Provide the event label ''w2'' using the properties view.
 
** Right-click on Event Wrapper and select ''New Child/ Synch Events''.
 
** Select ''Synch Events'' and go to the drop-down menu of the ''Local Event'' property.
 
** From the list of events select the ''TcalcWVal'' event.
 
  
We have now completed the task body, and it just remains to complete provide details for the ''TWrite'' event. The ''TWrite'' event in ''WriterTsk'' is to be synchronized with the ''SWrite'' event in the ''SharedObj''.
 
*'''Add Event Extensions'''.
 
** Right-click on the ''TWrite'' Event node.
 
** Select ''New Child/Extension''.
 
** Right-click on the ''Extension'' node and select ''New Child/Implementation'' from the menu.
 
** Go to the Implementation properties view and set the ''Implementation Type'' property to ''ProcedureSynch''.
 
  
*'''Identify Incoming and Outgoing parameters'''.
 
** Right-click on the ''outAP'' node and add an ''Extension''.
 
** Right-click on the ''Extension'' and select''New Child/Parameter Type''.
 
** Go to the ''Parameter Type'' properties view and set the ''Parameter Type'' property to ''actualOut''.
 
** Right-click on the ''inAP'' node and add an ''Extension''.
 
** Right-click on the ''Extension'' and select''New Child/Parameter Type''.
 
** Go to the ''Parameter Type'' properties view and set the ''Parameter Type'' property to ''actualIn''.
 
  
===== The Shared Machine =====
 
  
The next step is to identify the ''SharedObj'' machine as a ''Shared Machine''. The ''SharedObj'' Machine will be extended using the Event-B EMF extension mechanism.
+
=====Elements=====
* Right-click on the ''SharedObj'' Machine node in the ''.tasking'' file.
 
* Select ''New Child/Extension''.
 
* Right-click on the ''Extension'' node and select ''New Child/Shared Machine'' from the menu.
 
  
We now show how to extend the ''SWrite'' event of the Shared Machine with details about its implementation. The ''SWrite'' event in ''SharedObj'' is to be synchronized with the ''TWrite'' event in the ''WriterTsk''.
+
The diagram allows to create the following ''State'' elements:
* '''Identify SWrite as a Syncronisation'''.
+
* State
** Right-click on the ''SWrite'' Event node.
+
* Refined State (shall not be used)
** Select ''New Child/Extension''.
+
* Initial (state)
** Right-click on the ''Extension'' node and select ''New Child/Implementation'' from the menu.
+
* Final (state)
** Go to the Implementation properties view and set the ''Implementation Type'' property to ''ProcedureSynch''.
+
* ANY (state)
  
* '''Identify incoming and outgoing parameters'''.
+
A state can have nested state machines, added from ''State Features'', which correspond to UML parallel substates, also called parallel (or orthogonal) regions.
** Right-click on the ''inFP'' node and add an ''Extension''.
 
** Right-click on the ''Extension'' and select''New Child/Parameter Type''.
 
** Go to the ''Parameter Type'' properties view and set the ''Parameter Type'' property to ''formalIn''.
 
** Right-click on the ''outFP'' node and add an ''Extension''.
 
** Right-click on the ''Extension'' and select''New Child/Parameter Type''.
 
** Go to the ''Parameter Type'' properties view and set the ''Parameter Type'' property to ''formalOut''.
 
  
To summarise, for a Shared Machine definition:
+
Finally, states can have transitions from one to another, created from ''State Links''. Transitions can also be created from popup arrows on states and link to either existing states or to ones created from the context menu.
# Add the ''SharedMachine'' Machine type.
+
 
# For each event, define the Event Type.
+
=====Context Menu=====
# For each event parameter, define the Parameter Type.
+
 
 +
The context menu of a diagram includes four specific actions:  
 +
* ''Validate'' - to run the validation check on state machine model
 +
* ''Translate to Event-B'' - to run the translation of state machine to Event-B language
 +
* ''Start Animation'' - to run ProB animation and animate the diagram
 +
* ''Stop Animation'' - to stop the animation and return to Event-B perspective
 +
 
 +
[[Category:Plugin]] [[Category:User documentation]]

Revision as of 11:30, 10 May 2011

IUMLB big.png

Overview

Event-B Statemachines Plug-in is part of the iUML-B experimental tool that focuses on UML-B and Event-B integration. The plug-in provides a way of adding state machines directly to Event-B machines and is capable of translating former to Event-B language. It also offers a UML-like diagram editor for state machines, as well as state machine animation, which can be installed as additional plug-in that runs on top of ProB Animator.

Installation

The Event-B Statemachines plug-in is available for installation from Rodin update site under Modelling Extensions category. Animation plug-in for it is available from Verification and Validation category. Both plug-ins require EMF and GMF frameworks, Event-B EMF framework, ProB, OCL and QVT - all of these dependencies will be installed automatically upon plug-in installation.

Using the tool

The tool consists of a standard UML-like graphical editor for state machine diagrams, and integration to Event-B Explorer and a translator to Event-B language. Some of these may seem familiar to you if you have experience with UML editors or UML-B plug-in for Rodin.

Event-B Explorer

State machine in Event-B Explorer

To start the modelling all you have to do is to select a machine in Event-B Explorer that you would like to extend with state machines and click on Create new statemachine from explorer's toolbar. An input dialog will appear asking you for name of a new state machine. After that you should be able to see a new state machine appearing as a child of machine in explorer.

The explorer also shows the contents of state machines, including states, transitions and annotations. You can customise the amount if information you would like to see by going to explorer's menu (a small triangle at the top right-hand side) > Customize View.. > Filters tab. There are three filters defined for state machines: Annotation Filter, Transition Filter, State Filter - that hide corresponding elements in explorer (state filter hides simple states, like initial, final or ANY).

In addition, there are Open and Delete actions available for state machine in context menu of explorer. These allow to open a state machine in editor (shortcut is double-click) and delete a state machine (shortcut is Delete key). In the machine context menu there are two more actions related to state machines: Refine with statemachines and Delete generated - which allow correspondingly to create a refinement of machine with state machine refinements (not available yet from standard Refine action of Rodin) and to delete all Event-B elements generated by state machines (required only for experimental purposes if generated things/diagrams get corrupted).

Diagram Editor

State machine diagram editor

To edit a state machine in diagram editor you simply double-click it. The tool creates a diagram file for you with the same name as root state machine.

Working with the editor is straightforward. The element creation tools are available from palette, divided into three categories: States, State Features and State Links. When a diagram element is selected on canvas the Properties View shows its available properties (if you cannot find it, please go to Rodin's menu Window > Show View > Properties). After a state machine is complete it can be validated to make sure it has no semantic errors and translated to Event-B. When translated, it can be animated with ProB.






Elements

The diagram allows to create the following State elements:

  • State
  • Refined State (shall not be used)
  • Initial (state)
  • Final (state)
  • ANY (state)

A state can have nested state machines, added from State Features, which correspond to UML parallel substates, also called parallel (or orthogonal) regions.

Finally, states can have transitions from one to another, created from State Links. Transitions can also be created from popup arrows on states and link to either existing states or to ones created from the context menu.

Context Menu

The context menu of a diagram includes four specific actions:

  • Validate - to run the validation check on state machine model
  • Translate to Event-B - to run the translation of state machine to Event-B language
  • Start Animation - to run ProB animation and animate the diagram
  • Stop Animation - to stop the animation and return to Event-B perspective