13. Executing Tester-Generated Test Suites#

Once created with Reactis, test suites may be executed in a variety of different ways. You may:

  1. Load them into Reactis Simulator and run them.

  2. Load them into the Simulink simulation environment of The MathWorks and run them, with or without the help of the graphical rsRunTestsre tool included in the Reactis distribution.

  3. Export them as CSV files for processing by other tools.

This chapter describes these options in more detail.

13.1. Executing Test Suites Using Reactis Simulator#

Reactis Simulator includes facilities for running Tester-generated tests on Simulink / Stateflow models. These were detailed in the Reactis Simulator chapter. Here we briefly outline several of the most common use cases for executing tests in Simulator. Note that in all cases, Reactis will check the values stored in test suites for outputs and test points against those computed by the model. Also recall from the Reactis Simulator chapter, that Simulator offers many different ways to track data item values and coverage as tests execute.

_images/simToolbarC.png

Fig. 13.1 The Reactis Simulator toolbar#

The following uses Figure 13.1 to explain the steps needed to load and run a .rst file named cruise.rst.

  1. Select File > Open Model… and use the resulting dialog to select cruise.slx for loading.

  2. Click button 2 to enable Simulator.

  3. Click button 13 and use the resulting dialog to select cruise.rst for loading. The name of the file will be shown in the title bar of the Simulator window, and the tests will be listed in Source-of-Inputs dialog (window item 11).

  4. Once a test suite is loaded, some possible ways of running tests include:

    • To run a single test:

      a. Click on the Source-of-Inputs dialog button (window item 11).

      b. Select the test to be run. It will appear in the Source-of-Inputs dialog button.

      c. Use buttons 3–9 to step through the test as described in the Labeled Window Items section. The inputs for each simulation step will be taken from the test and the values computed for test points and harness outputs will be compared against those stored in the test suite.

    • To run all tests, one after another:

      a. Click on the Source-of-Inputs dialog button (window item 11).

      b. Click the All button at the bottom left of the dialog.

      c. Use buttons 3–9 to run the tests as described in the Labeled Window Items section. The inputs for each simulation step will be drawn from the tests (beginning with Test 1) and the values computed for test points and harness outputs will be compared against those stored in the test suite. When each test is completed, the simulation is “reset” so that the next test begins in the initial state of the model. Coverage information, however, is not reset, so the final cumulative statistics show the set of targets covered by any test in the suite.

    • To run all tests and generate an HTML report:

      a. Click on the Source-of-Inputs dialog button (window item 11).

      b. Click the All button at the bottom left of the dialog.

      c. Select Simulate > Fast Run with Report… The resulting report lists any runtime errors uncovered (divide-by-zero, overflow, memory errors, missing cases, assertion violations, etc.) or differences between outport values stored in the test suite and those computed by the model. If a runtime error is encountered, the remaining steps of the current test are skipped and Simulator continues execution with the following test. Optionally, you can also direct Reactis to include detailed coverage information (if and when each target was covered) in the report.

13.3. Executing Test Suites on Source Code#

Tester-generated test suites may also be run on source-code implementations of Simulink / Stateflow models; this feature helps automate the important task of determining whether deployed code will conform to models. Reactis currently supports several methods for running tests on source.

Via Reactis Simulator (in Reactis for C Standalone)

The standalone version of Reactis for C (not the Reactis for C Plugin) lets you test and validate standalone C code that is not a part of a Simulink model. Reactis for C shares the same test suite format (.rst) with Reactis for Simulink which greatly simplifies back-to-back testing of C code (foo.c) against a model (foo.slx). To do so:

  1. Generate a test suite foo.rst from foo.slx with Reactis for Simulink.

  2. Load foo.c in Reactis for C

  3. Start Simulator (in Reactis for C) and load foo.rst

  4. Select Simulate > Fast Run with Report… to execute the tests on the C code. Outputs computed by the C code will be compared against those stored in the test suite (which came from the model) and any differences are described in the generated report.

Via Reactis Simulator (in Reactis for Simulink)

You may use the S-function feature of MathWorks’ Simulink environment to embed your source code inside a Simulink block. This wrapper model may then be loaded and run in Simulator with differences between S-function outputs and outputs stored in tests flagged. This is especially useful when using the Reactis for C Plugin, since it allows inspection of the C code as the tests execute and tracking the coverage of the C code.

Via Simulink:

You may use the S-function feature of MathWorks’ Simulink environment to embed your source code inside a Simulink block. Then, as described in the Executing Test Suites in Simulink section, a number of methods for executing tests are available, including the rsRunTests utility provided by Reactis which will execute the tests and automatically flag any differences between the values stored in the tests and those computed by Simulink.

Via user-written test harnesses:

Reactis is also capable of outputting a test suite as a comma separated value (CSV) file for easy processing by external tools. Test steps are listed in an easy-to-process fashion. You may write your own test harnesses to read these files, run your program on the test data, and compare the outputs of the program to those stored in the tests.

Both the .m files and CSV files may be obtained using the Reactis Simulator export facility; see the Exporting Test Suites section for more on how to do this.

In order to write test harnesses that process Reactis-exported CSV files, one must know about the format of these files. The figure below contains a partial listing of a .csv file generated from the cruise-control example used in the Getting Started with Reactis chapter. See the Exporting Test Suites section for a description of the CSV file format.

onOff,accelResume,cancel,decelSet,brake,gas,inacThrDelt,drag,___t___,active,thrDelt,speed,"|InitialSpeed"
0.0,1.0,1.0,1.0,0.0,1.0,-0.1,-0.01,0.0,0.0,0.0,0.0,0.0
1.0,1.0,0.0,1.0,1.0,1.0,0.0,-0.00959914797712953,1.0,0.0,0.0,0.0,0.0
0.0,1.0,0.0,0.0,1.0,0.0,0.1,-0.00866942376836091,2.0,0.0,0.0,0.0,0.0
1.0,1.0,1.0,1.0,1.0,0.0,0.1,-0.00829318652470756,3.0,0.0,0.0,0.191330576231639,0.0

1.0,1.0,1.0,0.0,0.0,1.0,0.1,0.01,0.0,0.0,0.0,50.0,50.0
0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.00942639853457365,1.0,0.0,0.0,50.21,50.0
0.0,0.0,0.0,1.0,1.0,1.0,-0.1,0.00884905410912495,2.0,0.0,0.0,50.2194263985346,50.0

0.0,0.0,1.0,1.0,0.0,1.0,0.1,-0.01,0.0,0.0,0.0,4.21309604376837,4.21309604376837
0.0,1.0,1.0,1.0,0.0,1.0,-0.1,-0.00955227172719837,1.0,0.0,0.0,4.40309604376837,4.21309604376837
1.0,1.0,1.0,0.0,0.0,0.0,0.1,-0.00866896857231075,2.0,0.0,0.0,4.19354377204118,4.21309604376837
0.0,1.0,1.0,1.0,0.0,0.0,0.1,-0.00855659477502143,3.0,0.0,0.0,4.38487480346887,4.21309604376837
1.0,0.0,1.0,0.0,0.0,0.0,-0.1,-0.00773304191244197,4.0,0.0,0.0,4.57631820869384,4.21309604376837
0.0,0.0,1.0,1.0,0.0,1.0,0.1,-0.00700061209826044,5.0,0.0,0.0,4.3685851667814,4.21309604376837

0.0,1.0,0.0,1.0,0.0,1.0,0.1,0.0,0.0,0.0,0.0,22.8683123376438,22.8683123376438