test_common_msgs is a test package to verify that as messages are moved and migrated they continue to function.
To add a new message to the test, edit the file: test_common_msgs_migration.py
You will need to add 3 functions to TestCommonMsgsMigration. One which creates an original instance of your message. One which creates a new instance of your message. And one which actually runs the test.
As an example, consider the DiagnosticStatus message:
def get_old_diagnostic_status(self): diagnostic_status_classes = self.load_saved_classes('DiagnosticStatus.saved') diagnostic_status = diagnostic_status_classes['diagnostic_msgs/DiagnosticStatus'] diagnostic_value = diagnostic_status_classes['diagnostic_msgs/KeyValue'] diagnostic_value = diagnostic_status_classes['diagnostic_msgs/DiagnosticString'] return diagnostic_status(0, "abcdef", "ghijkl", [diagnostic_value(42.42, 'foo')], [diagnostic_value('xxxxx', 'bar')]) def get_new_diagnostic_status(self): diagnostic_status = load_current_class('diagnostic_msgs/DiagnosticStatus') diagnostic_value = load_current_class('diagnostic_msgs/KeyValue') diagnostic_value = load_current_class('diagnostic_msgs/DiagnosticString') return diagnostic_status(0, "abcdef", "ghijkl", [diagnostic_value(42.42, 'foo')], [diagnostic_value('xxxxx', 'bar')]) def test_diagnostic_status(self): self.do_test('diagnostic_status', self.get_old_diagnostic_status, self.get_new_diagnostic_status)
In get_old_diagnostic_status, we first load the old relevant classes from a saved message file. This allows us to continue generating messages of this type even when the system changed.
To create the saved instance of the message in the first place, we use the rosbagmigration savemsg.py utility:
rosrun rosbagmigration savemsg.py diagnostic_msgs/DiagnosticStatus > DiagnosticStatus.saved
We then extract any classes we need out of the map, and use them to create an instance of the message. This function should never have to be changed.
In the new_message_generator we instead just load the current versions of the class from our running system, making use of the load_current_class helper function. This should always be the most up-to-date version of the message that you will be migrating to in a live system.
Just like in old message generator, we create an instance and populate the fields as appropriate. These fields should be populated to the intended post-migration values corresponding to the old message generator.
Finally, we create a function, starting with "test_" to test the migration. All that needs to happen here is running self.do_test, and passing it a name, and the old and new generator.
The old_generator will be used to create a message. This message will be put it in a bag file, migrated, and then extracted from the new file. The migrated version will be compared to the output of the new message generator.