Ask Your Question

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

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

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 -0500 )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 -0500 )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 -0500 )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 -0500 )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 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



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

Seen: 163 times

Last updated: Oct 15 '17