This document provides a walk-through tutorial for performing model-based testing of a ROS node from a RoboChart component. It may be useful to also read through the documentation in robotest-ros-gen, in addition, to this mini-tutorial.
- RoboTool installed using the latest release from the robotool repository.
If running under Wayland, start Eclipe from the command line ensuring it is running in X11 mode, to avoid potential incompatibilities, by setting the
GDK_BACKEND
environment variable toX11
, that is, by using the commandGDK_BACKEND=X11 ./eclipse
. Otherwise, start Eclipse normally. To determine whether you're running under Wayland, you can query the value of the environment variableXDG_SESSION_TYPE
, for example, by running the commandecho $XDG_SESSION_TYPE
in a terminal. - FDR4 installed from https://cocotec.io/fdr/. For installation and activation of FDR4 on modern Linux distributions, including Ubuntu, follow the instructions in the SLEEC-TK repository.
- ROS1 (Noetic), for executing the sample node and running the automatically generated tests.
This repository includes a sample RoboTool project with a sample ROS node for exercising the ROS test generator. We recommend that you import this Git repository in RoboTool first, by:
- Copy the URL of this project into your clipboard.
- Going to
File
>Import
. - Select
Git
>Project from Git (with smart import)
, then click Next. - Select
Clone URI
followed byNext
twice. - Select the inner project
ros-sample
and clickNext
and finallyFinish
.
Inspect the model by opening the graphical representation, if you have not already opened it,
by clicking, for example, on the main.rct
element under RCPackage
in the Model explorer
,
shown on the left.
For this task first ensure FDR4 is installed and has it license active. To ensure the license has been activated open FDR4 on its own and follow the instructions.
To generate forbidden traces:
- Expand the
main.rct
file, in theModel explorer
shown on the left, until the componentState Machine Def stm0
shows up. - Right-click on the component, and select RoboTool. You may need to select it twice in order for the additional options to show up.
- Select
Testgen
. You should be asked to select how many events to include in the forbidden traces. - After the generation has completed, a file of the name
file_main.rtspec
will automatically be re-generated under the foldertest-gen
. Note that files are overwritten without warning.
Inspect the generated forbidden traces and check you understand their correspondence with the RoboChart model. In particular consider:
- Why events carry an
in
orout
parameter. - The correspondence between names in the
rtspec
file and those in the RoboChart model.
If in doubt, you can use Ctrl
followed by a click on an element of the trace. It will open
the corresponding event in the RoboChart textual representation of the model.
Open the file csp-gen/instantiations.csp
and change the line core_nat
from the default to
nametype core_nat = {0..6}
. Re-generate the forbidden traces.
- Consider how the forbidden traces have changed and ensure you understand why.
- Are there values related to the output that are now covered by the list of traces?
Consider the definition of
core_nat
that you changed.
To make the traces in a format suitable for the ROS test generator their syntax needs to be converted.
Open the file test-gen/file_main_target.rtspec
. How do the traces differ from test-gen/file_main.rtspec
?
Transform the traces from one format to the other using a built-in transformation. To do this:
- Expand the folder
utils
in theModel explorer
. - Right-click on
CSPM2RC.launch
and selectRun as
>1 CSPM2RC
. - Some output will be produced on Console and no exceptions should be thrown.
Inspect the re-generated file in test-gen/file_main_target.rtspec
. Consider changing the
core_nat
value, as before, and (1) re-generating the forbidden traces, followed (2) by the
transformation. Ensure you understand the traces.
To generate a test driver for ROS, a rostest
configuration needs to be specified via
one or more files. For this sample, these have already been created in the folder ros
.
Expand the folder ros
and inspect the file map.rostest
and sample.rostest
. The file
map.rostest
defines a mapping between the ROS node sample
and the RoboChart component
stm0
. Inspect both files and use Ctrl
+ click as before to inspect the elements of
the configuration.
To trigger generation of the ROS test code, you can make a small change to the file, e.g.
adding white text and saving it. It will automatically regenerate code under the folder
catkin_ws/src/ros-gen
. Inspect the automatically generated code. In particular
focus on:
- The main source file for a test, such as
catkin_ws/src/ros-gen/map/tests/mm_suite/t0/src/main.cpp
. - The user-configurable file for the test suite under
catkin_ws/src/ros-gen/map/mm_suite/usr/events.cpp
. For this analysis it may be useful to look at the definition of ROS messages undercatkin_ws/src/sample/msg
.
Inspect the Python code for the sample node under catkin_ws/src/sample/src/main.py
.
Consult the ROS wiki
if needed to understand the basic concepts of a publisher/subscriber node.
Install ROS (ideally Noetic under Ubuntu 20.04) and configure the catkin_ws
as the ROS
workspace:
- Open a terminal in that folder and type (or similar):
source /opt/ros/noetic/setup.bash
, followed bycatkin_make
. There should be no errors or warning after running this command. - Then type
source devel/setup.bash
. - Finally run
rostest map_mm_suite map.test
.
Examine the output results and check which traces fail. Can you understand why they fail
when looking at the main.py
program? Can you fix the code, bearing in mind the source
RoboChart model? Rerun the tests whenever you make changes to the sample main.py
.
Write a new node or expand the RoboChart model and enrich your implementation to handle more topics.