![]() |
![]() |
|
02158 Concurrent Programming Fall 2024 |
Lab 2: Verification with SPIN - with comments and solutions |
Home | Plan | Material |
Comments and solutions proposals added in red
The lab will guide you through most of the operations needed to use
SPIN for basic verification.
Assistance for this programming lab will be available in Building 303A, area EAST, Thursday October 3, 15.00-17.00
You should read about the SPIN verification tool in [Spin]. You may find further information about SPIN at spinroot.com, in particular the online reference for the modelling language Promela. You may also like to have a look at the jSpin User Manual.
For these lab instructions it is assumed that you use a combination of SPIN and jSpin as found on the G-bar servers (available through ThinLinc).
If you prefer to use your own computer (which you probably do), you must install SPIN and jSpin in due time before the lab. The installation may be quite challenging (especially on Windows and Mac).
See the course wiki for detailed instructions (and contribute if you can).
If you for some reason cannot make JSpin work, you will have to run SPIN/JSpin on the G-bar servers using the desctiption found here.
The lab is divided into three parts, A, B, and C. In the first two, you are going to experiment with given algorithms. In the third, you should construct and verify an algorithm yourselves.
jspin
Caveat: The jSpin tool saves the
current Promela model under the original name (without any backup!)
whenever it makes any kind of check, simulation or verification.
Therefore you either have to exernally save copies of versions
(espicially correct ones) or undo your changes.
Caveat: The SpinSpider tool also offers to generate a diagram of the reachable state space (ie. the transition graph). Unfortunately, however, this part is quite buggy and is considered deprecated by the author himself. Thus, SpinSpider should be used for checking the validity of the automata corresponding to the Promela model only.
Pressing the Interactive button
starts an simulation where you may choose among enabled transitions
(when more than one is possible) using a pop-up choice bar.
The output of the simulation is presented in the right panel and shows:
The process id, the process name, the line number, the action and the value of variables as before the chosen step.
(Tip: If statements or variable names are cut off, you may increase
their width under the Output menu.)
The selection bar should be closed in order to end the simulation.
It is also possible to run a random simulation by pressing Random. The simulation runs of a limited amount of steps. [The default number is 250, but can be changed with the -u option of spin.]
Ensure that Safety mode is chosen and press the
Verify button. In the bottom panel, the verification steps are
seen:
NOTE: Since the invariant is checked by a
separate process, no assertions need be added.
error: max search depth too smallwhich means that the verification has not been exhaustive because the maximum path length (sequence of distinct states) has been reached.
Caveat: Notice that the verification still
says *** no errors ***, but this is with respect to the limited
search performed. Always check the start of your output for
any error indications as they may render the error count irrelevant.
To make an exhaustive search, the maximum search depth must be increased. This is done in the Settings menu under Max depth. Try to increase it, until the verification completes.
(Tip: increase by a factor of 10 in each attempt.)
Download spin2.pml and open it from
jspin. In this program the
increments and decrements have been broken down to atomic actions
having only one critical reference each.
Inspect the automatas for the refined processes (as above) and recognize the non-atomic operations.
Set the search depth to 50 (as described above) and run the verification. Now, we still get the seach depth error meaning that we did not get to every reachable state. However, this is not important because we discover an error:
pan:1: assertion violated
You can also see, that an error trail has been stored. Try to run a simulation using the trail by pressing the Guided button.
(Tip: Use the Maximize buttton to let the right panel take over the whole upper part letting you see the simulation line by line.)
Under the Options menu, choose C Compiler and in the pop-up window add -DBFS to the existing options.
Now, when you rerun the verification you should find that the error
trail has a length of 9. Run the trail using guided simulation and
see how the invariant is violated.
The following deals with the mutual exclusion algorithm defined in the Exercise Share.2 [Aux p.3] (known from Exercise Class 2 last week).
[In this model, the mutual exclusion is expressed by local
assertions as an alternative to checking a global invariant in an
extra process.]
Ascertain the atomicity of the statements by checking the automata. If
you used the atomic{...} solution, the individuel transtions
are still there, but are red in order to indicate that they are
executed without any interleavings.
Make sure that breadth-first search is still activated (as described in A.12) and try to verify the system. This shows that mutual exclusion still does not hold - something that some of you might have discovered during the Exercise Class.
Run the error trail in the simulator and recognize that the "other flag" may change between the step of setting your own flag and testing the other flag again.
Verify that this algorithm implements mutual exclusion correctly.
To select one of the internal formulas for verification, you may simply
uncomment it. Alternatively, you may uncomment all of them and then
enter the name of the desired formula, eg. obl1,
in the LTL formula text field and click on the LTL name button.
Now, set the verification mode to Acceptance and do the
verification. If selecting by name, check that the proper formula is
chosen by checking the name after the -N option given to spin.
Caveat: The breadt-first search option must not be enabled when doing acceptance verification.
If a liveness property does not hold, the simulation trace will end in a cycle sequence (from <<<<<START OF CYCLE>>>>>) which is understood to be repeated forever. Try to find this sequence and understand how it violates the liveness property.
(Tip: To find the shortest cycle sequence, add the option -i (for iteration) to the Options for Pan. The warning that this options only works for safety properties may be ignored. Actually, the option may work also for liveness properties.)
You should find, that with weak fairness turned on, obligingness and resolution are satisfied, but not fairness, since the other process may freely enter and leave the region inbetween tests.
Without weak fairness none of the properties hold.
NOTE: In general, it does not make sense to turn off weak fairness for a critical region program, since it allows a process to stall in the region and thereby block it, while the other process eagerly tries to enter it. Also, without weak fairness, any process which does not block, may take over the full computation.
[This problem will be part of Mandatory Assignment 2.]
In the following you should propose and verify a solution to the mutual exclusion problem for N processes using a coordinator process. See [Andrews Figure 3.12] for a similar solution to the barrier problem.
(Note: The verification output may ask you to recompile with
-DNFAIR=3. This option should be added to the Options
for C Compiler.)
Caveat: As decribed in the [Spin] note, the x in P[x]@entry is not the index of P[0], but the processs identifier of P[0], which happens to be 0 as well, as P is the first process type to be instantiated.
You will have to provide a solution yourself as part of Mandatory 2
JSpin provides a simple and fairly familiar environment for running SPIN, but does not give direct access to all the features of the underlying SPIN verification program (only indirectly through command-line options). Especially the simulation facilities of jSpin are fairly basic. Therefore you may like to try out alternative approaches before using SPIN for the mandatory assignment.
You may use SPIN from the command line only. This requires you to study the plethora of command line options in order to obtain the desired functionality. But if you succeed with that, it may be quite efficient.
You may use the ispin gui bundled with SPIN. This interface provides access to the many options for controlling SPIN through various menus. The interface requires tcl/tk and other Unix-oriented tools and libraries which may be hard to install in a Windows-based system.
See these instructions on how to install (SPIN and) ispin.
Rather than editing Promela model files in the built-in (but fragile) editor of ispin, you may use an external editor and reopen the Promela files into ispin.
All of these tools require that SPIN and a C compiler are already installed.
This is a front-end developed as an Eclipse RCP tool:
http://lms.uni-mb.si/spinrcp/index.html
This tool is easy to install and is quite stable. Compared to jSpin, it does not attempt to interpret the console output which means that one has to be more careful inspecting the results.
Unfortunately SpinRCP does not run on Java versions greater than 8
Good luck!
Hans Henrik Løvengreen, Oct 3, 2024 |