ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Can I emulate ROS node level "design by contract" with self_test?

asked 2017-10-02 09:57:54 -0600

thinwybk gravatar image

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?

edit retag flag offensive close merge delete


I guess this will depend on what it is you want to test / what is in your contract.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-02 10:27:59 -0600 )edit

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)...

thinwybk gravatar image thinwybk  ( 2017-10-04 03:24:46 -0600 )edit

... 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

thinwybk gravatar image thinwybk  ( 2017-10-04 03:28:39 -0600 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-04 04:36:51 -0600 )edit

I know. I am just thinking about if self_test could be used to support design by contract, built-in-selftesting, etc.

thinwybk gravatar image thinwybk  ( 2017-10-04 04:53:41 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-10-15 05:03:48 -0600

thinwybk gravatar image

self_test is not suitable to emulate "Design By Contract".

However self_test is not required to emulate DbC with self_test at all but would be overhead instead. It is sufficient to implement "assert" functions for parameter values, topics message values, service request/response message values and action goal/result/feedback topic message values and call them in corresponding "sections" of nodes. For "asserting" different alternatives come to mind: diagnostics status.summaryf(diagnostic_msgs::DiagnosticStatus::ERROR, "DbC violation" or logging rospy.logerr("DbC violation").

edit flag offensive delete link more

Question Tools



Asked: 2017-10-02 09:57:54 -0600

Seen: 242 times

Last updated: Oct 15 '17