# Bag migration tests scripts
In order to generate the data and rules for bag migration tests, two scripts are provided:
* **generate_data** : Generates *.bag* files with messages (data) to run the bag migration tests.
* **generate_rules** : Help in the process of creating rules between two message generations.
The next sections explain how to use these scripts in detail. The rest are auxiliary scripts that should NOT be used directly.
Before running any of these scripts you need to build the **test_rosbag** package at least once in your workspace and `source` the environment workspace setup file. This can be done running the following from the root of the workspace:
``` bash
$ catkin_make_isolated
$ source devel_isolated/test_rosbag/setup.bash
```
:warning: Since we use `catkin_make_isolated` in the scripts to build the different message generations, remember the scripts need to be run from the root of the workspace.
## Generate Data
The **generate_data** script generates *.bag* data files for one or multiple messsage generations. The output directory is the **bag_migration_tests/test** folder inside the **test_rosbag** package. It's the user responsibility to move the output *.bag* files to an HTTP server and download them from the **CMakeLists.txt** file as in this example:
``` cmake
catkin_download_test_data(download_data_test_constants_gen1.bag http://download.ros.org/data/test_rosbag/constants_gen1.bag FILENAME test/constants_gen1.bag MD5 77ec8cb20e823ee3f3a87d07ea1132df )
```
Currently, there are the following message generations on the **test_rosbag** package, under the **bag_migration_tests** folder, in these sub-folders:
* **msg_gen1** : Message generation \#1.
* **msg_gen2** : Message generation \#2.
* **msg_gen3** : Message generation \#3.
* **msg_current** : Current message generation.
:warning: Note the **generate_data** script doesn't generate data for the **msg_current** generation because we don't have to. This is because the current generation is never the source of any migration rules, just the target for the latest generation.
This script takes the following positional arguments:
* **generations** : ID of the messages generations to build and generate *.bag* data files for. It defaults to `1 2 3`.
### Examples
1. Generate data for the message generation \#1:
``` bash
$ rosrun test_rosbag generate_data 1
Generating data in '/home/eperdomo/dev/ws/clearpath_ws/src/ros_comm/test/test_rosbag/bag_migration_tests' for generation: 1
```
This will create the following *.bag* files inside the **test_rosbag** package:
``` bash
bag_migration_tests/test/constants_gen1.bag
bag_migration_tests/test/converged_gen1.bag
bag_migration_tests/test/convergent_gen1.bag
bag_migration_tests/test/migrated_addsub_gen1.bag
bag_migration_tests/test/migrated_explicit_gen1.bag
bag_migration_tests/test/migrated_implicit_gen1.bag
bag_migration_tests/test/migrated_mixed_gen1.bag
bag_migration_tests/test/partially_migrated_gen1.bag
bag_migration_tests/test/renamed_gen1.bag
bag_migration_tests/test/subunmigrated_gen1.bag
bag_migration_tests/test/unmigrated_gen1.bag
```
Each of these bag files have a single message of the generation requested, as shown below with `rosbag info`:
``` bash
$ rosbag info $(rospack find test_rosbag)/bag_migration_tests/test/constants_gen1.bag
path: /home/eperdomo/dev/ws/clearpath_ws/src/ros_comm/test/test_rosbag/bag_migration_tests/test/constants_gen1.bag
version: 2.0
duration: 0.0s
start: Dec 31 1969 19:00:00.00 (0.00)
end: Dec 31 1969 19:00:00.00 (0.00)
size: 4.7 KB
messages: 1
compression: none [1/1 chunks]
types: test_rosbag/Constants [06a34bda7d4ea2950ab952e89ca35d7a]
topics: constants 1 msg : test_rosbag/Constants
```
2. Generate data for the message generations \#2 and \#3:
``` bash
$ rosrun test_rosbag generate_data 2 3
Generating data in '/home/eperdomo/dev/ws/clearpath_ws/src/ros_comm/test/test_rosbag/bag_migration_tests' for generation: 2
Generating data in '/home/eperdomo/dev/ws/clearpath_ws/src/ros_comm/test/test_rosbag/bag_migration_tests' for generation: 3
```
This will create the following *.bag* files inside the **test_rosbag** package:
``` bash
bag_migration_tests/test/constants_gen2.bag
bag_migration_tests/test/converged_gen2.bag
bag_migration_tests/test/converged_gen3.bag
bag_migration_tests/test/convergent_gen2.bag
bag_migration_tests/test/migrated_explicit_gen2.bag
bag_migration_tests/test/migrated_explicit_gen3.bag
bag_migration_tests/test/migrated_implicit_gen2.bag
bag_migration_tests/test/migrated_implicit_gen3.bag
bag_migration_tests/test/migrated_mixed_gen2.bag
bag_migration_tests/test/migrated_mixed_gen3.bag
bag_migration_tests/test/partially_migrated_gen2.bag
bag_migration_tests/test/partially_migrated_gen3.bag
bag_migration_tests/test/renamed_gen2.bag
bag_migration_tests/test/renamed_gen3.bag
```
3. Generate data for all the message generations, relying on the default value for the argument:
``` bash
$ rosrun test_rosbag generate_data
Generating data in '/home/eperdomo/dev/ws/clearpath_ws/src/ros_comm/test/test_rosbag/bag_migration_tests' for generation: 1
Generating data in '/home/eperdomo/dev/ws/clearpath_ws/src/ros_comm/test/test_rosbag/bag_migration_tests' for generation: 2
Generating data in '/home/eperdomo/dev/ws/clearpath_ws/src/ros_comm/test/test_rosbag/bag_migration_tests' for generation: 3
```
This will create the following *.bag* files inside the **test_rosbag** package:
``` bash
bag_migration_tests/test/constants_gen1.bag
bag_migration_tests/test/constants_gen2.bag
bag_migration_tests/test/converged_gen1.bag
bag_migration_tests/test/converged_gen2.bag
bag_migration_tests/test/converged_gen3.bag
bag_migration_tests/test/convergent_gen1.bag
bag_migration_tests/test/convergent_gen2.bag
bag_migration_tests/test/migrated_addsub_gen1.bag
bag_migration_tests/test/migrated_explicit_gen1.bag
bag_migration_tests/test/migrated_explicit_gen2.bag
bag_migration_tests/test/migrated_explicit_gen3.bag
bag_migration_tests/test/migrated_implicit_gen1.bag
bag_migration_tests/test/migrated_implicit_gen2.bag
bag_migration_tests/test/migrated_implicit_gen3.bag
bag_migration_tests/test/migrated_mixed_gen1.bag
bag_migration_tests/test/migrated_mixed_gen2.bag
bag_migration_tests/test/migrated_mixed_gen3.bag
bag_migration_tests/test/partially_migrated_gen1.bag
bag_migration_tests/test/partially_migrated_gen2.bag
bag_migration_tests/test/partially_migrated_gen3.bag
bag_migration_tests/test/renamed_gen1.bag
bag_migration_tests/test/renamed_gen2.bag
bag_migration_tests/test/renamed_gen3.bag
bag_migration_tests/test/subunmigrated_gen1.bag
bag_migration_tests/test/unmigrated_gen1.bag
```
## Generate Rules
The **generate_rules** script helps in the process of creating migration rules from one message generation to another. The scripts requires the user input every time a rule is created, since the rule **update** method needs to be implemented and the rule needs to be set to **valid = True**. It also needs the user to tell the new name for moved/renamed messages. The user can also decide to completely remove the rule if the intention is to test what happens when rules are missed.
For convenience, the script loads all the migration rules (*.bmr* files) already available on the **msg_** and **test** sub-folders, under the **bag_migration_tests** folder in the **test_rosbag** package.
This script takes the following positional arguments:
* **source** : Source message generation.
* **target** : Target message generation.
The message generation can be any of the following: `gen1`, `gen2`, `gen3` or `current`. That is, the suffix of all the message generations available in the **test_rosbag** package, under the **bag_migration_tests** folder, with the **msg_** prefix.
The output folder for the generated rules is the folder for the **source** message generation, e.g. **msg_gen1** for `gen1`.
The script proceeds as follows:
1. Builds the **so
评论0