Package rostest :: Module rostest_parent

Source Code for Module rostest.rostest_parent

  1  # Software License Agreement (BSD License) 
  2  # 
  3  # Copyright (c) 2008, Willow Garage, Inc. 
  4  # All rights reserved. 
  5  # 
  6  # Redistribution and use in source and binary forms, with or without 
  7  # modification, are permitted provided that the following conditions 
  8  # are met: 
  9  # 
 10  #  * Redistributions of source code must retain the above copyright 
 11  #    notice, this list of conditions and the following disclaimer. 
 12  #  * Redistributions in binary form must reproduce the above 
 13  #    copyright notice, this list of conditions and the following 
 14  #    disclaimer in the documentation and/or other materials provided 
 15  #    with the distribution. 
 16  #  * Neither the name of Willow Garage, Inc. nor the names of its 
 17  #    contributors may be used to endorse or promote products derived 
 18  #    from this software without specific prior written permission. 
 19  # 
 20  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 21  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 22  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 23  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 24  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 25  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 26  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 27  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 28  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 29  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 30  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  # POSSIBILITY OF SUCH DAMAGE. 
 32  # 
 33  # Revision $Id$ 
 34   
 35  import logging 
 36  import sys 
 37   
 38  import rosgraph 
 39  import roslaunch.config 
 40  from roslaunch.core import printlog_bold, RLException 
 41  import roslaunch.launch 
 42  import roslaunch.pmon 
 43  import roslaunch.server 
 44  import roslaunch.xmlloader  
 45   
 46  import roslaunch.parent 
 47   
 48  from rosmaster.master import Master 
 49  from rospy import logwarn 
 50   
51 -class ROSTestLaunchParent(roslaunch.parent.ROSLaunchParent):
52
53 - def __init__(self, config, roslaunch_files, port=0, reuse_master=False, clear=False):
54 if config is None: 55 raise Exception("config not initialized") 56 # we generate a run_id for each test 57 if reuse_master: 58 param_server = rosgraph.Master('/roslaunch') 59 try: 60 run_id = param_server.getParam('/run_id') 61 except Exception as e: 62 # The user asked us to connect to an existing ROS master, and 63 # we can't. Throw an exception and die 64 raise Exception("Could not connect to existing ROS master. " 65 + "Original exception was: %s" % str(e)) 66 except: 67 # oh boy; we got something that wasn't an exception. 68 # Throw an exception and die 69 raise Exception("Could not connect to existing ROS master.") 70 71 if clear: 72 params = param_server.getParamNames() 73 # whitelist of parameters to keep 74 whitelist = ['/run_id', '/rosversion', '/rosdistro'] 75 for i in reversed(range(len(params))): 76 param = params[i] 77 if param in whitelist: 78 del params[i] 79 elif param.startswith('/roslaunch/'): 80 del params[i] 81 for param in params: 82 param_server.deleteParam(param) 83 else: 84 run_id = roslaunch.core.generate_run_id() 85 super(ROSTestLaunchParent, self).__init__(run_id, roslaunch_files, is_core=False, is_rostest=True) 86 self.config = config 87 self.port = port 88 self.reuse_master = reuse_master 89 self.master = None
90
91 - def _load_config(self):
92 # disable super, just in case, though this shouldn't get called 93 pass
94
95 - def setUp(self):
96 """ 97 initializes self.config and xmlrpc infrastructure 98 """ 99 self._start_infrastructure() 100 if not self.reuse_master: 101 self.master = Master(port=self.port) 102 self.master.start() 103 self.config.master.uri = self.master.uri 104 self._init_runner()
105
106 - def tearDown(self):
107 if self.runner is not None: 108 runner = self.runner 109 runner.stop() 110 if self.master is not None: 111 self.master.stop() 112 self.master = None 113 self._stop_infrastructure()
114
115 - def launch(self):
116 """ 117 perform launch of nodes, does not launch tests. rostest_parent 118 follows a different pattern of init/run than the normal 119 roslaunch, which is why it does not reuse start()/spin() 120 """ 121 if self.runner is not None: 122 return self.runner.launch() 123 else: 124 raise Exception("no runner to launch")
125
126 - def run_test(self, test):
127 """ 128 run the test, blocks until completion 129 """ 130 if self.runner is not None: 131 # run the test, blocks until completion 132 return self.runner.run_test(test) 133 else: 134 raise Exception("no runner")
135