Can I emulate ROS node level "design by contract" with self_test?
I would like to emulate "design by contract" on the ROS node level by using diagnostics/self_test. To check a ROS nodes preconditions probably pretest()
(self_test example) could be used. The ROS nodes postconditions could be checked with posttest()
(self_test example). Could I trigger self_test test function execution when topics are published somehow?
I guess this will depend on what it is you want to test / what is in your contract.
The list of possible preconditions, postconditions and invariants which could be checked is long. The question is how checks could be executed in general. pretest() should work before ROS node startup (e.g. check if dependent on nodes are already running)...
... invariant checking could be done whenever a node received a topic message or a service request which could potentially change the node into an invalid state. The question is if it would be possible with self_test to use kind of callback function mechanism which would allow to execute checks then
I don't think that
self_test
was intended to be used that way (it's more a "runtime testing" tool for diagnostic purposes), but perhaps it could be repurposed.I know. I am just thinking about if self_test could be used to support design by contract, built-in-selftesting, etc.