| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Chapter 3 Getting Started with ReactisThis chapter provides a quick overview of Reactis. It contains a brief description of each main component of the tool suite in the form of an extended “guided-tour” of the different features of the tool suite. Each “stop” in the tour is indicated by a §. The tour uses as a running example a simple Simulink / Stateflow model of an automobile cruise control that is included in the Reactis distribution. 3.1 A Note on Model PreparationThe cruise-control example included with the distribution does not require any special processing before you run Reactis on it; you may load the file immediately and start the guided tour. However, there is an important preparation step that you should undertake when you are building models for use with Reactis. This section describes this preparatory step and discusses the Simulink operations needed to perform it. Reactis supports a large portion of the discrete-time subset of Simulink and Stateflow. As it processes a Simulink / Stateflow model, it also interacts with MATLAB in order to evaluate MATLAB expressions, including references to workspace data items, that a model may contain. In order for Reactis to process a model, the associated .mdl file must contain links to all MATLAB files used in the model. This may be done using Simulink’s preload-function (PreLoadFcn) facility. Chapter 14 addresses this, and other model-preparation issues, in more detail. In general, including these links in your .mdl file is good modeling practice, since once these links are established a .mdl file may also be loaded into Simulink without having to hand-load the relevant .m files in MATLAB first. This process of associating .m files with a .mdl file typically needs to be done only once, although it should be redone if there is a change in the set of .m files used by a .mdl file. Modifying an .m file that is already linked to a .mdl file does not require updating the links in the .mdl file. Below we describe how the relevant links were established in the cruise-control model file included in the Reactis release. In that example the MATLAB file cruise_constants.m defines two workspace variables that are used in the Simulink / Stateflow model file cruise.mdl. The cruise_constants.m file was attached to cruise.mdl using the following steps.
This saved cruise.mdl file is distributed with Reactis, so you do not need to undertake the above steps yourself in order to load and process this file in Reactis. The above steps are cited only for illustrative purposes. 3.2 Reactis Top LevelThe Reactis top-level window contains menus and a tool bar for
launching applications on Simulink / Stateflow models. Reactis is invoked as
follows.
You now see a Reactis window like the one as shown in Figure 3.1. A model may be selected for analysis as follows.
Loading the model causes the top-level window to change as shown in Figure 3.2. The panel to the right shows the top-level Simulink diagram of the model; the panel to the left shows the model hierarchy. In addition, the title bar now reports the model currently loaded, namely cruise.mdl, and the Reactis info file (.rsi file ) cruise.rsi that contains auxiliary model information used by Reactis. The info file is explained in more detail in the next section (Section 3.3). Nodes in the model hierarchy may be “opened” as follows.
You may click on the + next to subsystems to explore their structure. Subsystems are also tagged with icons indicating whether they are Simulink (SL), Stateflow ( SF), Validator objectives ( 3.3 The Info File EditorReactis does not modify the .mdl file for a model. Instead the tool stores model-specific information that it requires in a .rsi file. The primary way for you to view and edit the data in these files is via the Reactis Info File Editor, as described briefly in this section and in more detail in Chapter 5. The next stop in the guided tour explains how this editor may be invoked on
This starts the Reactis Info File Editor, as shown in Figure 3.3. Note that the contents of the .rsi file may only be modified when Simulator is disabled. When Simulator is running, the Info File Editor operates in read-only mode as indicated by “[read only]” in the editor window’s title bar. .rsi files contain directives that specify the following.
The types that may be specified are the base Simulink / Stateflow types extended with notations to define ranges, subsets and resolutions, and to constrain the allowable changes in value from one simulation step to the next. More precisely, acceptable types can have the following basic forms.
Table 3.1 gives examples of types and the values they contain.
If any change is made to a port type, then “[modified]” appears in the title bars of the Info File Editor and the top-level Reactis window. You may save changes to disk by selecting File -> Save from the Info File Editor or File -> Save Info File from the top-level window. If no .rsi file exists for a model, Reactis will create a default file the first time you open the Info File Editor, or start Simulator or Tester. The default type for each inport is the base type inferred for the port from the model. If you add or remove an inport to your model you can synchronize your .rsi file with the new version of the model by selecting Tools -> Synchronize from the Info File Editor.
3.4 SimulatorReactis Simulator provides a rich array of facilities for viewing the execution of models. The tool can execute both closed-loop and open-loop models (the latter being models that contain inports at the top level). To continue with the guided tour:
This causes a number of the tool-bar buttons that were previously disabled to become enabled. The simulator performs simulations in a step-by-step manner: at each simulation step inputs are generated for each inport, and resultant outputs reported on each outport. In the case of open-loop models, such as the running cruise-control example, you can control how Simulator computes top-level inport values.
To set the source of inputs, use the
Inputs Source dialog located to the left of
3.4.1 Generating Random Inputs
As the random input source is the default, no action needs to be taken
to set this input mode.
During simulation, blocks, signals, states, and transitions in the diagram are highlighted in green as they are entered and executed. The simulation stops automatically when the number of simulation steps reaches the figure contained in the entry box to the left of the Inputs Source dialog. Before then, you may halt the simulation by clicking the
(Stop) button. Simulation is then suspended at the end
of the current simulation step.3.4.2 Tracking Model Coverage
While Simulator is running you may also track coverage
information regarding which parts of your model have been executed and
which have not. These coverage-tracking features work for all input-source
modes. The next portion of the guided tour illustrates how these features are used.
A dialog summarizing coverage (which blocks / states have been entered
and which transitions have fired) now appears, and elements of the
diagram not yet exercised are drawn in red, as shown in Figure
3.5. Note that poor coverage is not uncommon with
random simulation. You may hover over a covered element to determine
the (1) test (in the case being considered here, the “test” is the
current simulation run and is rendered as . in the hovering
information) and (2) step within the test that first exercised the
item. This type of test and step coverage information is displayed
with a message of the form
Details for decision coverage, condition coverage, and MC/DC are
conveyed using a table as shown in Figure 3.6.
The table in this figure gives information for the decision — MC/DC Coverage requires that each condition independently affect the
outcome of the decision in which it resides. When a condition has
met the MC/DC criterion in a set of tests, the sixth and seventh
columns of the table explain how. Each element of these two columns
has the form bb:test/step, where each b reports the
outcome of evaluating one of the conditions in the decision during the
test and step specified. Each b is either It should be noted that the previous scenario relied on randomly generated input data, and replaying the steps outlined above may yield different coverage information than that depicted in Figure 3.6 An alternative way to query coverage information is to invoke the Coverage-Report Browser by selecting Coverage -> Show Report. This is a tool for viewing or exporting coverage information that explains which model elements have been covered along with the test and step where they were first exercised. A simulation run,
and associated coverage statistics, may be reset by clicking the
3.4.3 Reading Inputs from Tests
Simulation inputs may also be drawn from tests in a Reactis test
suite. Such a test suite may be generated automatically by Reactis
Tester, constructed manually in Reactis Simulator, or
imported from a file storing test-data in a comma-separated-value format. By
convention
files storing Reactis test suites have a .rst file-name extension.
A Reactis test suite may be loaded into Simulator as follows.
This causes cruise.rst, the name of a test suite file generated by Reactis Tester, to appear in the title bar and the contents of the Inputs Source dialog to change; it now contains a list of tests that have been loaded. To view this list:
Each test in the suite has a row in the dialog that contains a test number, a sequence number, a name and the number of steps in the test. Clicking the “all” button in the lower left corner specifies that all tests in the suite should be executed one after another. To execute the last test in the suite:
If you look at the bottom-right corner of the window, you can see that the test is being executed, although the results of each execution step are not displayed graphically. When the test execution completes, the exercised parts of the model are drawn in black. If the Run Simulation button (
) is clicked instead,
then the results of each simulation step are rendered graphically,
with the consequence that simulation proceeds more slowly.You may specify that a subset of tests should be run by holding down the control key and clicking on each test to be run with the left mouse button. The tests will be run in the order they are selected. As tests are selected the sequence number column is updated to indicate the execution order of the tests. You may also use the Inputs Source dialog to change the name of a test. To do so, select the test by single clicking on it, then click on the name and, when the cursor appears, type in a new name and press return. 3.4.4 Tracking Values of Data ItemsWhen Simulator is paused1, you may
view the current value of a given data item (Simulink block
or signal line, or Stateflow variable) by hovering over the item
with your mouse cursor.
You may also select data items whose values you wish to track during
simulation using the watched-variable and scope facilities of
Simulator.
The bottom of the Simulator window now changes to that indicated in Figure 3.7.
The watched-variable panel shows the values of watched data items in the current simulation step, as does hovering over a data item with the mouse. Variables may be added to, and deleted from, the watched-variable panel by selecting them and right-clicking to obtain a menu. You may also toggle whether the watched-variable list is displayed or not by selecting the View -> Show Watched Variables menu item. Scopes display the values a given data item has assumed
since the beginning of the current simulation run. To open a scope:
3.4.5 Querying the User for Inputs
The third way for Simulator to obtain values for inports
is for you to provide them. To enter this mode of
operation:
Upon selecting this input mode, a Next Input Values dialog appears, as shown in Figure 3.9, that allows you to specify the input values for the next simulation step. Each top-level inport of the model has a row in the dialog containing five columns; these determine the next input value for the corresponding inport as follows.
When Run Simulation (
3.4.6 Other FeaturesSimulator has several other noteworthy features. You may step both forwards and backwards through a simulation using toolbar buttons:
You may specify the number of steps taken when
Breakpoints may be set by either:
The
3.5 TesterTester may be used to generate a test suite (a
set of tests) automatically from a Simulink / Stateflow model. The tool attempts to
maximize coverage criteria you specify.
To start Tester:
This causes the window shown in Figure 3.10 to appear. Tester employs a three-phase algorithm to generate test suites. In the Preload Phase, a set of previously computed test suites may be loaded; Tester then attempts to extend the preloaded suite(s). In the Random Phase, Tester uses a fast random search strategy to generate test cases. In the Targeted Phase, the tool uses sophisticated algorithms to build tests that exercise previously uncovered parts of the model. By default, the Preload Phase is disabled, and the other two are enabled. Checking boxes to the left of the phase names in the Tester dialog allows you to enable or disable each of the phases. Each phase also has parameters that the you may adjust to tailor the performance of the tool. The only parameter for the Preload Phase is a list of files containing previously generated test suites. The Random phase has two parameters: one for the number of tests to be built and the other for the maximum number of steps in each test for this phase. It should be noted that, upon completion of the random phase, redundant steps are pruned from the tests, so the lengths of the final tests are usually shorter than this parameter. The Targeted Phase has one parameter: the total number of execution steps to take during this phase. The Tester panel also contains a Coverage Objectives section consisting of check boxes that enable you to specify the criteria for guiding test generation. The currently supported targets include Simulink branches and conditionally executed subsystems; Stateflow states, condition actions, and transition actions; conditions, decisions and modified condition / decision coverage (MC/DC), all of which apply both to Simulink and Stateflow; boundary values of top-level inports, including lower and upper bounds in range-constrained inports, all values in enumeration-constrained inports, and boundary values of Relational Operator blocks; the intervals defined by a 1-d or 2-d Lookup Table block; and Validator objectives (assertions and user-defined targets). See Chapter 6 for details. If you are using the Reactis for C Plugin and your model includes C code, then you will also see a checkbox for C Statements. To generate a test suite in the guided tour, retain the default
settings and:
The Tester progress dialog, shown in Figure 3.11, is displayed during test-suite generation. When Tester terminates, a results dialog is shown, and a file cruise.rst containing the suite is produced. The results dialog includes buttons for loading the test suite into the Test-Suite Browser (see below), Reactis Simulator, or a coverage viewer. 3.6 The Test-Suite BrowserThe Test-Suite Browser is used to view the test suites created by Reactis. It may be invoked from either the Tester results dialog or the Reactis top-level window.
A Test-Suite Browser window like the one shown in Figure 3.12
is then displayed. The the Test Data tab of the browser
displays the test selected in the button/dialog located on the right
side of the browser’s tool bar. The main panel in the browser window
shows the indicated test as a matrix, in which the first column gives
the input and output ports of the model and each subsequent column
lists the values for each port for the corresponding simulation step.
The simulation time is displayed in the output row labeled
“ The Test-Suite Browser may also be used to display the entire set of values
passing over a port during a single test or set of tests.
A dialog similar to that shown in Figure 3.13 appears. In the figure, each value assumed by the inport drag is represented by a yellow dot. 3.7 ValidatorReactis Validator is used for checking whether models behave correctly. It enables the early detection of design errors and inconsistencies and reduces the effort required for design reviews. The tool gives you two major capabilities.
Conceptually, assertions may be seen as checking system behavior for potential errors, while user-defined targets monitor system behavior in order to check for the presence of certain desirable executions (tests). Syntactically, Validator assertions and user-defined targets have the same form and are collectively referred to as Validator objectives. Both assertions and user-defined targets play key roles in checking a model against requirements given for its behavior. A typical requirements specification consists of a list of mandatory properties. For example, a requirements document for an automotive cruise control might stipulate that, among other things, whenever the brake pedal is depressed, the cruise control should disengage. Checking whether or not such a requirement holds of a model would require a method for monitoring system behavior to check this property, together with a collection of tests that would, among other things, engage the cruise control and then apply the brake. In Validator, the behavior monitor would be implemented as an assertion, while the test scenario involving engaging the cruise control and then stepping on the brake would be captured as a user-defined target. 3.7.1 Manipulating Validator ObjectivesThis section gives more information about Validator objectives.
After performing these operations, you now see a window like the one
depicted in Figure 3.14. The two kinds of objectives are
represented by different icons; assertions are denoted by a lightning bolt
Objectives in Validator may take one of two forms.
To see an example expression objective, do the following.
A dialog like that shown in Figure 3.15 now appears. This dialog shows an expression intended to capture the following requirement for a the cruise control: “Activating the brake shall immediately cause the cruise control to become inactive.” Note that the dialog consists of four parts:
To see an example diagram objective:
A dialog like the one in Figure 3.16 now appears. This dialog contains five sections.
Wiring information may be viewed by hovering over a diagram objective in the main Reactis model-viewer panel. Diagram-based objectives may be viewed as monitors that read values from the model being observed and raise flags by setting their outport values appropriately (zero for false, non-zero for true). A diagram-based assertion in essence defines one “check” for each of its outports, with such an outport check being violated if it ever assumes the value zero. Similarly, a diagram-based target objective in essence defines one “target” for each outport; such a target is deemed covered if it becomes non-zero. To view the diagram associated with SpdCheck:
These operations open the Stateflow diagram shown in Figure 3.17. This diagram encodes the following requirement: “While it is engaged, the cruise control shall not allow the desired and actual speeds to differ by more than 1 mile per hour for more than three time units.”
To understand how this diagram captures this requirement, note that the SpdCheck diagram has two top-level states, one corresponding to when the cruise control is active and one when it is inactive. The active state has three child states:
Note that the transition action executed as state Error is entered sets the outport ok to 0. This is how an assertion violation is flagged. Diagram objectives give you the full power of Simulink / Stateflow to formulate assertions and targets. The objectives may use any Simulink blocks supported by Reactis, including full Stateflow. The diagrams are created using Simulink and Stateflow in the same way standard models are built; they are stored in a separate .mdl file from the model under validation. Diagram wiring is managed by Reactis, so the model under validation need not be modified at all. As this information is stored in the .rsi file associated with the model, it also persists from one Reactis session to the next. After adding a diagram objective to a model, the diagram is included in the model’s hierarchy tree, just as library links are in a model. See Chapter 9 for more details on using Reactis Validator. 3.7.2 Launching ValidatorTo use Validator to check for assertion violations:
A dialog like the one in Figure 3.18 now appears. The dialog is similar to the Tester launch screen in Figure 3.10 because the algorithms underlying the two tools are very similar. Conceptually, Validator works by generating thorough test suites from the instrumented model using the Tester test-generation algorithm and then applying these tests to the instrumented model to see if any violations occur. Note that when a model is instrumented with Validator objectives, the test-generation algorithm uses the objectives to direct the test construction process. In other words Reactis actively attempts to find tests that violate assertions and cover user-defined targets. Validator stores the test suite it creates in the file specified in this dialog. The tests may then be used to diagnose any assertion violations that arise.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||