Table of Contents Previous Chapter 3 Tutorial: A First Example

3 Tutorial: A First Example

Generating and Starting a Validator

In addition to simulating a system, it is also possible to validate the system using the SDT Validator. A validator can be used to automatically find errors and inconsistencies in a system, or to verify the system against requirements.

In the same way as for a simulator, you must generate an executable validator and start it with a suitable user interface.

-----------------------------------------------------------------------
Note:                                                                    
In order to generate a validator that behaves as stated in the exercis   
es, you should copy all SDL diagrams that are included in the distri     
bution to your work directory (~/demon_game). These diagrams are         
by default stored in a subdirectory to the SDT installation directory.   
The name of the directory should be                                      
$sdtrelease/examples/demongame                                           
If you generate a validator from the diagrams that you have created,     
the scheduling of processes (i.e. the execution order) may differ.       
-----------------------------------------------------------------------

What You Will Learn

Quick Start of a Validator

A validator can be generated and started in the same way as described earlier for the simulator, i.e., by using the Make dialog and the Tools menu in the Organizer. However, we will now show a quicker way.

  1. Make sure the system diagram icon is selected in the Organizer.
  2. Click the Validate quick button. The following things will now happen, in rapid succession:

The Validator UI looks like this:

Figure\x11 124 : The Main Window of the Validator UI. 
-----
(fig)  
       
-----
As you can see, the graphical user interface of a validator is very similar to a simulator GUI, which you have learned to use in the previous exercises. However, the button modules to the left are different and a few extra menus are available.

A validator contains the same type of monitor system as a simulator. The only difference is the set of available commands.

When a validator is started, the static process instances in the system are created (in this case Main and Demon), but their initial transitions are not executed. The process in turn to be executed is the Main process. You can check this by viewing the process ready queue:

  1. In the button module View, click the Ready Q button. The first entry in the ready queue is Main, waiting to execute its start transition.
  2. If required, resize the Validator UI window so that all button modules are visible. You may also reduce the width of the text area. In the exercises to come, you will have a number of windows open at the same time.

Basics of a Validator

Before you start working with the validator exercises, you should have an understanding about the basic concepts of the SDT Validator.

Navigating in a Behavior Tree

In this first exercise, we will explore the state space of the Demongame system by manually navigating in the behavior tree. The validator will then behave in a way similar to when running a simulator. However, there are also important differences, which will be pointed out.

By default, the validator is set up in a way that results in a state space as small as possible. In this set-up, a transition between two states in the behavior tree always corresponds to a complete transition in the SDL process graphs. Also, the number of possible branches from a state is limited to a minimum.

What You Will Learn

Setting Up the Exploration

When interactively exploring the behavior tree, a validator tool called the Navigator is used.

  1. Start the Navigator by clicking the Navigator button in the Explore module. The Navigator window is opened:
    Figure\x11 126 : The Navigator Tool. 
    -----
    (fig)  
           
    -----
    
    The Navigator shows part of the behavior tree around the current system state. In general, the upper box represents the behavior tree transition leading to the current state, i.e., the transition that just has been executed. The boxes below represent the possible tree transitions from the current state. They are labelled Next 1, Next 2, etc. and have not yet been executed.
    Since the system now is in its start state, there is no up node. The only next node is the start transition of Main.
  2. To be able to see the printed trace familiar from simulation, open the Command Window from the View menu. (The trace is not printed in the main window of the validator.)
  3. To switch on GR trace of SDL symbols, select Toggle SDL Trace from the Commands menu in the Validator window; SDL trace is now enabled. However, an SDL Editor will not be opened until the first transition is executed.

Using the Navigator

  1. In the Navigator, execute the next transition by double-clicking on the Next 1 node. The following happens, in order:
  2. If needed, move and resize all opened windows to make them completely visible and still fit on the screen together.
  3. Double-click the Next 1 node to execute the next transition. The start transition of Demon is traced in the Command window and in the SDL Editor.
    At this stage, neither of the two active processes can continue without signal input; Main awaits the signal Newgame from the environment, and Demon awaits the sending of the timer signal T. These are the two transitions from the current state now shown in the Navigator as Next 1 and Next 2. As you can see, the transitions in the boxes are described by the same type of information as in a printed trace.
    Figure\x11 129 : Transition Descriptions in the Navigator. 
    -----
    (fig)  
           
    -----
    
    This means that the validator gives information of all possible transitions from the current system state, even though they have not been executed yet. (This information cannot easily be obtained when running a simulator.)
  4. Send the timer signal by double-clicking the Next 2 node. The Command window tells us that the timer signal is sent and the Navigator shows that the next transition is the input of the timer T.
  5. Execute the next transition by double-clicking the Next 1 node. This is where the dynamic error in the Demongame system occurs, as explained in the simulator tutorial earlier (see "Dynamic Errors" on page 143). Instead of showing the next transition, the Navigator displays the error message in the next box.
    Figure\x11 130 : The Dynamic Error. 
    -----
    (fig)  
           
    -----
    
  6. Double-click the Up 1 node to go back to the previous state. Repeat this action again to go to the state we were in after step 3 above. This way of backing up in the execution is not possible when running a simulator, as you may have noticed when running the Simulator tutorial.
    You should also note that the Next 2 node is marked with three asterisks "***." This is used to indicate that this is the transition we have been backing up through:
    Figure\x11 132 : Marking a Transition that has been Backed Through. 
    -----
    (fig)  
           
    -----
    
  7. Execute the Next 1 transition instead with a double click. The printed trace shows that the signal Newgame was sent from the environment. The Main process is ready to receive the signal. Note that you do not have to send the signal yourself; this is taken care of automatically by the validator.
  8. Execute the next transition. The printed trace and the SDL trace show that Main now is in the state Game_On. The Navigator displays the start transition of the newly created Game process.
  9. Execute the start transition of Game. The Navigator will now show the different signal inputs that are required to continue execution: Endgame, Probe, Result, and the timer T.
    Figure\x11 133 : Signal Inputs Required for Continued Execution. 
    -----
    (fig)  
           
    -----
    
    If the number of transitions from a state is large, it may be difficult to see them all in the Navigator when a tree structure is used. To overcome this problem, the display can be changed to a list structure.
  10. Click the Structure quick button to see how the list structure looks like. Now it is easier to see the possible signals.

    Figure\x11 134 : The List Structure. 
    -----
    (fig)  
           
    -----
    
  11. Change back to the tree structure.
    We will not continue further down in the behavior tree in this exercise. Figure 135 on page 188 shows the part of the behavior tree we have explored so far. The nodes in the figure represent states of the complete SDL system. Each node lists the active process instances that have changed since the previous system state, what process state they are in and the content of their input queues. The arrows between the nodes represent the possible tree transitions. They are tagged with a number and the SDL action that causes the transition. The arrow numbers are the same numbers as printed in the Next nodes in the Navigator.
    Note that this is a somewhat different view of the behavior tree compared to the Navigator. In the Navigator, the nodes represent the tree transitions and the process states are not shown.
    Figure\x11 135 : A Demongame Behavior Tree. 
    -----
    (fig)  
           
    -----
    

More Tracing and Viewing Possibilities

In this exercise, we will take a look at some of the additional tracing and viewing possibilities of the validator.

What You Will Learn

Using the View Commands

  1. Make sure you are still in the same state as after the last step in the previous exercise.
    To see a complete printed trace from the start state to the current state, you can use the Print-Trace command. As parameter, it takes the number of levels back to print the trace from.
  2. On the input line of the Validator UI, enter the command pr-tr 9 (you can use any large number). The trace is printed in the text area of the main window. This trace gives an overview of what has happened in the SDL system so far.
  3. The validator supports the same viewing commands as the SDT simulator. Click the Timer List button in the View module to list the active timer set by the Demon process.
  4. Examine the GameP variable in the Main process by clicking the Variable button and making selections in the dialogs.
    --------------------------------------------------------------------
    Note:                                                                 
    The first dialog asks for a process, which the corresponding simula   
    tor command does not. The reason is that the validator has no con     
    cept of process scope, so you have to select the process explicitly.  
    --------------------------------------------------------------------
    

Using MSC Trace

In addition to textual and graphical traces, the validator can also perform an MSC trace.

  1. First, turn off SDL trace by selecting Toggle SDL Trace from the Commands menu. Then, turn on MSC trace from the same menu. An MSC Editor is opened, showing a Message Sequence Chart for the trace from the start state to the current state.
    Figure\x11 136 : The Current MSC Trace. 
    -----
    (fig)  
           
    -----
    
  2. When the MSC appears, execute, with a double-click, one of the signal transitions in the Navigator, e.g. Probe. The message is appended to the MSC.
    Figure\x11 137 : Appending Probe to the MSC. 
    -----
    (fig)  
           
    -----
    
  3. Go up a few levels in the Navigator.
    Note how the selection in the MSC Editor changes to reflect the MSC event corresponding to the current state!
  4. Go down again, but select a different path than before, i.e., send one of the other signals.
    Note how the MSC diagram is redrawn to show the new behavior of the system!
  5. Toggle MSC trace off in the Commands menu. Unless other MSC diagrams were opened, the MSC Editor is closed.

Going to a State Using Path Commands

You can use the commands Print-Path and Goto-Path to return to a state where you have been before.

  1. Execute the command Print-Path from the input line. The output represents the path taken in the behavior tree from the start state to the current state.
Command : print-path
1 1 1 1 1 3 0
  1. Go up a few levels in the Navigator.
  2. In the text area, locate the path printed by the Print-Path command above (you may have to scroll the text area). With the mouse, select the numbers in the path by dragging the mouse to the end of the line. Make sure you select the final zero.
  3. In the input line, enter goto-path and a space character. Paste in the path numbers by positioning the mouse pointer at the end of the entered text and clicking the middle mouse button. Hit <Return> to execute the command. You now end up in the previous state.

Validating an SDL System

In the previous exercises, we have navigated manually in the behavior tree. We have also found an error situation by studying the Navigator and the printed trace in the Command window.

In this exercise, we will show how to find errors and possible problems by automatically exploring the state space of the Demongame system. This is referred to as validating an SDL system.

What You Will Learn

Performing a Bit State Exploration

Automatic state space exploration can be performed using different algorithms. The algorithm called bit state exploration can be used to efficiently validate reasonably large SDL systems. It uses a data structure called a hash table to represent the system states that are generated during the exploration.

An automatic state space exploration always starts from the current system state. Since we want to explore the complete Demongame system, we must first go back to the start state of the behavior tree.

  1. Go to the top of the tree by clicking the Top button in the Explore module.
  2. Start a bit state exploration by clicking the Bit-State button. After a few seconds, a tool called the Report Viewer is opened. We will soon describe this window; in the meantime, just move it away from the main window.
  3. For a small system such as Demongame, the exploration is finished almost immediately and some statistics are printed in the text area. They should look something like:
** Starting bit state exploration **
Search depth    : 100
Hash table size : 1000000 bytes
** Bit state exploration statistics **
No of reports: 1.
Generated states: 2569.
Truncated paths: 156.
Unique system states: 1887.
Size of hash table: 8000000 (1000000 bytes)
No of bits set in hash table: 3642
Collision risk: 0 %
Max depth: 100
Current depth: -1
Min state size: 68
Max state size: 124
Symbol coverage : 100.00
Of the printed information, you should note the following:

Examining Reports

The error situations reported from a state space exploration can be examined in the Report Viewer. The Report Viewer window displays the reports in the form of boxes in a tree structure.

Figure\x11 138 : The Report Viewer. 
-----
(fig)  
       
-----
  1. To expand the report, double-click on the report type box Output. You will now see a box reporting the error we have found manually earlier. In addition, the tree depth of the error situation is shown.
    Figure\x11 139 : An Expanded Report. 
    -----
    (fig)  
           
    -----
    
    If you look in the Navigator and Command windows, you can see that the validator is still in the start state of the system, even though a state space exploration has been performed. We will now go to the state where the error has occurred.
  2. Double-click the report box in the Report Viewer. The following things will now happen:
  3. Move up two steps by using the Up button. Of the two transitions possible from this state, the one that is part of the path leading to the error is indicated by three asterisks "***" (see Figure 132 on page 186). This is the transition chosen when using the Down button.
  4. Move up to the top of the tree (click the Top button in the Explore module). Move down again to the error by using the Down button repeatedly.
    Note that you do not have to chose which way to go when the tree branches. The path to the error is remembered by the validator until you manually chose another transition.

Exploring a Larger State Space

We will now run a more advanced bit state exploration, with a different setting of the state space options. This will make the state space much larger, so that more error situations can be found.

  1. Go back to the top of the behavior tree (use the Top button).
  2. In the Explore module, click the Advanced button. This sets a number of the available state space options in one step, as you can see by the commands executed in the text area:
Command : def-sched all
Command : def-prio 1 1 1 1 1
Command : def-max-input-port 2
Max input port length is set to 2.
Command : def-rep-log maxq off
No log for MaxQueueLength reports
Note that the Navigator now shows two possible transitions from the start state; this is an immediate effect of the larger state space.
  1. In addition, we will increase the search depth of the exploration from 100 (the default) to 200. From the Options2 menu, select Bit-State: Depth. In the dialog, enter 200 and click OK.
    Figure\x11 140 : Specifying Depth = 200. 
    -----
    (fig)  
           
    -----
    
    Since the behavior tree becomes much larger with these option settings, the exploration will take longer to finish. We will therefore show how to stop the exploration manually.
  2. Start a new bit state exploration. In the text area, a status message is printed every 20,000 transitions that are executed. Stop the exploration after one of the first status messages by pushing the Break button in the Explore module. The text area should now display something like this:
*** Break at user input ***
** Bit state exploration statistics **
No of reports: 2.
Generated states: 72000.
Truncated paths: 2472.
Unique system states: 25905.
Size of hash table: 8000000 (1000000 bytes)
No of bits set in hash table: 50554
Collision risk: 0 %
Max depth: 200
Current depth: 161
Min state size: 68
Max state size: 168
Symbol coverage : 100.00
Command : 
Note the following differences in the printed information compared to the previous exploration:
  1. In the Report Viewer, open the two report type boxes to see both reports with a double-click on each. The Report Viewer window should now look something like:
    Figure\x11 141 : The Two Reports as Displayed in the Window. 
    -----
    (fig)  
           
    -----
    
  2. For now, just note on which depth each of the reported situations occurred; do not double-click any of the reports.
  3. Continue the exploration by clicking the Bit-State button again. A dialog is opened, asking if you would like to continue the interrupted exploration or restart it from the beginning.
    Figure\x11 142 : Continuing the Exploration. 
    -----
    (fig)  
           
    -----
    
  4. In the dialog, select Continue and click OK. Wait for the exploration to finish by itself.
  5. In the Report Viewer, open the two reports again. Note that the depth values have changed. This is because only one occurrence of each report is printed; the one found at the lowest depth so far.
  6. Go to the state where an unsuccessful create of the Game process was reported (double-click the Create report).
    Figure\x11 143 : The Report about an Unsuccessful Process Create. 
    -----
    (fig)  
           
    -----
    
  7. To see what caused the unsuccessful create, look at the MSC trace.
    At the receipt of the last Newgame signal, the Main process attempts to create a Game process. However, the already active Game process has not yet consumed the previous GameOver signal, and has therefore not been terminated. Since you cannot have more than one instance of the Game process in the Demongame system, the process create could not be executed!

Checking the Validation Coverage

If the symbol coverage after an automatic state space exploration is less than 100%, the Coverage Viewer can be used to check what parts of the system that have not been executed. To attain a symbol coverage less than 100% for the Demongame system, we will set up the exploration in a special way.

  1. Go to the top of the tree.
  2. First, we need to restore the smaller, default state space. Click the Default button in the Explore module. Note that the Navigator changes back to display only a single possible transition from the top node.
  3. To avoid reaching all system states, we will reduce the search depth of the exploration from 100 to just 10. Use the Bit-State: Depth menu choice from the Options2 menu and specify a maximum depth of 10.
  4. Start a bit state exploration. The printed statistics should now inform you that the symbol coverage is about 82%.
  5. To find out which parts of the Demongame system that have not been reached, open the Coverage Viewer from the Commands menu.
    A symbol coverage tree is displayed, showing all symbols which have not been executed yet.
  6. Change to a transition coverage tree by clicking the Coverage Type quick button.

    Figure\x11 144 : The Transition Coverage Tree. 
    -----
    (fig)  
           
    -----
    
    You can now see that none of the transitions from the state Winning in the Game process has been executed. To explore this part of the system in the validator, you can go to the state Winning and start a new exploration from there. How to do this is explained in the following exercises.

Going to a State Using User-Defined Rules

To go to a particular system state, you could use the Navigator to manually find the state by studying the transition descriptions and the printed trace in the Command window. This can be both tedious and difficult, especially for larger systems than Demongame. Instead, we will show an easier way: by using a user-defined rule.

When performing state space exploration, the validator checks a number of predefined rules in each system state that is reached. It is when such a rule is satisfied that a report is generated.

In this exercise, we will show how to define a new rule to be checked during state space exploration. The rule will be used to find the state Winning in the Game process.

  1. Make sure you still are at the top of the behavior tree.
  2. Define a new rule by selecting Define Rule from the Commands menu. In the dialog that appears, enter the rule definition
    state(Game:1)=Winning
    Figure\x11 145 : Specifying a New Rule. 
    -----
    (fig)  
           
    -----
    
    This very simple rule says that the state of the process instance Game:1 must be equal to Winning. By defining the rule, a report will be generated when a state space exploration reaches a state that satisfies the rule.
  3. Start a bit state exploration. Since we have not changed any of the options since the last exploration the same statistics will be printed, with the exception that an additional report is generated.
  4. From the Report Viewer, go to the reported situation where the user-defined rule was satisfied. You have now reached the first place in the behavior tree where the Game process is in the state Winning. We will now start another type of state space exploration from this state; a random walk.

Performing a Random Walk

Apart from bit state exploration, there is another exploration method known as random walk. A random walk simply explores the behavior tree by repeatedly choosing a random path down the tree. This is mainly useful for SDL systems where the state space can be very large. For a small system like Demongame, it can be as effective as other exploration methods.

  1. First, we have to clear the user-defined rule and the current reports. Enter the commands clear-rule and clear-reports on the input line.
  2. Start a random walk exploration from the current state by clicking the Random walk button. From the printed statistics, you can see that the symbol coverage now has become 100%.
  3. Open the Coverage Viewer from the Commands menu. Note that all symbols have been executed at least 4 times.
    To see that a random walk for the whole Demongame system gives a full coverage of all symbols, do as follows:
  4. Reset the system by clicking the Reset button in the Explore module. You are now back at the top of the tree.
  5. Perform a random walk. The symbol coverage should be 100%.
  6. Open the Coverage Viewer from the Commands menu. Change to transition coverage and display the whole tree. Note that all transitions have executed a large number of times. When the exploration selects a random path down the tree, there is no mechanism to avoid that already explored paths are explored once more. Therefore, the same transition may be executed any number of times.
  7. Exit the Coverage Viewer from the File menu.

Verifying a Message Sequence Chart

Another main area of use for a validator is to verify a Message Sequence Chart. To verify an MSC is to check if there is a possible execution path for the SDL system that satisfies the MSC. This is done by loading the MSC and performing a state space exploration set up in a way suitable for verifying MSCs.

What You Will Learn

Verifying a System Level MSC

In this exercise, we will verify one MSC made on the system level, i.e., an MSC that only defines signals to and from the environment. The MSC is included in the SDT distribution and is shown in the figure below. The name of the MSC file is systemlevel.msc and is located in the same directory as the remaining files for the DemonGame example.

Figure\x11 146 : A System Level MSC. 
-----
(fig)  
       
-----
  1. From the operating system prompt, make sure you can locate the MSC mentioned above (systemlevel.msc). Make a copy of the MSC and put it in your tutorial directory.
  2. Reset the system by clicking the Reset button in the Explore module.
  3. Start an MSC verification by clicking the Verify MSC button. A file selection dialog is opened, in which you select the MSC to verify.
  4. Select systemlevel.msc and click OK. A state space exploration is immediately started, which is guided by the loaded MSC.
    In the printed statistics, note that the exploration is completed without any truncated paths. This is because the loaded MSC restricts the size of the behavior tree; only the parts dealing with the events in the MSC are executed. The maximum depth of it is not more than 13.
    The last line printed tells if the MSC was verified or violated:
** MSC SystemLevel verified **
The MSC was verified, i.e., the behavior described in the MSC was indeed possible. In the Report Viewer, however, one of the reports is a violation of the loaded MSC, while the other one is a verification of the MSC. The exploration may very well find states that violate the MSC; it is the existence of states that verify the MSC that determines the result of the verification.
Figure\x11 147 : One Violation and one Verification of the MSC. 
-----
(fig)  
       
-----
  1. Go to the state where the MSC was verified. The printed trace in the Command window shows that the Main process has received the Endgame signal, and sent the GameOver signal to the Game process:
*   OUTPUT of GameOver. Receiver: Game:1
*     Signal GameOver received by Game:1
  1. Take a look at the MSC trace and compare it with the loaded MSC in Figure 146 on page 204. Note that the loaded MSC only defines signals to and from the environment and therefore is less detailed than the MSC trace. An MSC trace in the validator is always made on the process level.
    Figure\x11 148 : The MSC Trace. 
    -----
    (fig)  
           
    -----
    

Exiting the Validator UI

The validator tutorial is now finished. Close the validator windows in the following way:

  1. To close the Navigator and the Report Viewer, click the Close quick button in these windows.

  2. To close the Command window, select Close from the File menu.
  3. Exit the Validator UI from the File menu. Since you have changed some of the options, you are asked in a dialog whether to save the changes.
    Figure\x11 149 : Saving Changed Options. 
    -----
    (fig)  
           
    -----
    
  4. If you select Yes and click OK, the option settings are saved in a file called .valinit. This file is read each time the Validator UI is started from the same directory, or when the validator is restarted or reset from the Validator UI. You should select No and click OK.

To Conclude...

You have now learned the basics of SDT; we hope you have enjoyed the "tour". The example you have been practising on, the system DemonGame, is however rather simple. To deepen your knowledge about SDT, you may practise on a number of exercises that illustrate the advantages of SDL-92 when adopting an object-oriented design methodology. These exercises are described in chapter 4, Tutorial: An SDL-92 Example.

 
Table of Contents Next Chapter