Package roswtf
[frames] | no frames]

Source Code for Package roswtf

  1  # Software License Agreement (BSD License) 
  2  # 
  3  # Copyright (c) 2009, 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: __init__.py 13417 2011-02-26 18:52:26Z kwc $ 
 34   
 35  """ 
 36  roswtf command-line tool. 
 37  """ 
 38   
 39  import os 
 40  import socket 
 41  import sys 
 42  import traceback 
 43   
 44  import roslib.packages 
 45  import roslib.scriptutil 
 46       
47 -def yaml_results(ctx):
48 cd = ctx.as_dictionary() 49 d = {} 50 d['warnings'] = {} 51 d['errors'] = {} 52 wd = d['warnings'] 53 for warn in ctx.warnings: 54 wd[warn.format_msg%cd] = warn.return_val 55 ed = d['warnings'] 56 for err in ctx.warnings: 57 ed[err.format_msg%cd] = err.return_val 58 import yaml 59 print yaml.dump(d)
60 75 #print "ERROR:", e.msg 76
77 -def roswtf_main():
78 try: 79 import std_msgs.msg 80 import rosgraph_msgs.msg 81 except ImportError: 82 print "ERROR: The ROS communication libraries have not been built. To fix:\nrosmake ros_comm" 83 sys.exit(1) 84 85 from roswtf.context import WtfException 86 try: 87 _roswtf_main() 88 except WtfException, e: 89 print >> sys.stderr, e
90
91 -def master_online():
92 master = roslib.scriptutil.get_master() 93 try: 94 master.getPid('/roswtf') 95 return master 96 except socket.error: 97 pass
98
99 -def _roswtf_main():
100 launch_files = names = None 101 # performance optimization 102 all_pkgs = roslib.packages.list_pkgs() 103 104 import optparse 105 parser = optparse.OptionParser(usage="usage: roswtf [launch file]") 106 # #2268 107 parser.add_option("--all", 108 dest="all_packages", default=False, 109 action="store_true", 110 help="run roswtf against all packages") 111 # #2270 112 parser.add_option("--no-plugins", 113 dest="disable_plugins", default=False, 114 action="store_true", 115 help="disable roswtf plugins") 116 117 parser.add_option("--offline", 118 dest="offline", default=False, 119 action="store_true", 120 help="only run offline tests") 121 122 #TODO: --all-pkgs option 123 options, args = parser.parse_args() 124 if args: 125 launch_files = args 126 if 0: 127 # disable names for now as don't have any rules yet 128 launch_files = [a for a in args if os.path.isfile(a)] 129 names = [a for a in args if not a in launch_files] 130 names = [roslib.scriptutil.script_resolve_name('/roswtf', n) for n in names] 131 132 from roswtf.context import WtfContext 133 from roswtf.environment import wtf_check_environment, invalid_url, ros_root_check 134 from roswtf.graph import wtf_check_graph 135 import roswtf.network 136 import roswtf.packages 137 import roswtf.roslaunchwtf 138 import roswtf.stacks 139 import roswtf.plugins 140 if not options.disable_plugins: 141 static_plugins, online_plugins = roswtf.plugins.load_plugins() 142 else: 143 static_plugins, online_plugins = [], [] 144 145 # - do a ros_root check first and abort if it fails as rest of tests are useless after that 146 error = ros_root_check(None, ros_root=os.environ['ROS_ROOT']) 147 if error: 148 print "ROS_ROOT is invalid: "+str(error) 149 sys.exit(1) 150 151 all_warnings = [] 152 all_errors = [] 153 154 if launch_files: 155 ctx = WtfContext.from_roslaunch(launch_files) 156 #TODO: allow specifying multiple roslaunch files 157 else: 158 curr_package_dir, curr_package = roslib.packages.get_dir_pkg('.') 159 if curr_package: 160 print "Package:",curr_package 161 ctx = WtfContext.from_package(curr_package) 162 #TODO: load all .launch files in package 163 elif os.path.isfile('stack.xml'): 164 curr_stack = os.path.basename(os.path.abspath('.')) 165 print "Stack:",curr_stack 166 ctx = WtfContext.from_stack(curr_stack) 167 else: 168 print "No package or stack in context" 169 ctx = WtfContext.from_env() 170 if options.all_packages: 171 print "roswtf will run against all packages" 172 ctx.pkgs = all_pkgs 173 174 # static checks 175 wtf_check_environment(ctx) 176 roswtf.network.wtf_check(ctx) 177 roswtf.packages.wtf_check(ctx) 178 roswtf.stacks.wtf_check(ctx) 179 roswtf.roslaunchwtf.wtf_check_static(ctx) 180 for p in static_plugins: 181 p(ctx) 182 183 print "="*80 184 print "Static checks summary:\n" 185 print_results(ctx) 186 187 # Save static results and start afresh for online checks 188 all_warnings.extend(ctx.warnings) 189 all_errors.extend(ctx.errors) 190 del ctx.warnings[:] 191 del ctx.errors[:] 192 193 # test online 194 print "="*80 195 196 try: 197 online_checks = False 198 if options.offline or not ctx.ros_master_uri or invalid_url(ctx.ros_master_uri): 199 master = None 200 else: 201 master = roslib.scriptutil.get_master() 202 master = master_online() 203 if master is not None: 204 online_checks = True 205 print "Beginning tests of your ROS graph. These may take awhile..." 206 207 # online checks 208 wtf_check_graph(ctx, names=names) 209 elif names: 210 # TODO: need to rework this logic 211 print "\nCannot communicate with master, unable to diagnose [%s]"%(', '.join(names)) 212 return 213 else: 214 print "\nROS Master does not appear to be running.\nOnline graph checks will not be run.\nROS_MASTER_URI is [%s]"%(ctx.ros_master_uri) 215 return 216 217 # spin up a roswtf node so we can subscribe to messages 218 import rospy 219 rospy.init_node('roswtf', anonymous=True) 220 221 online_checks = True 222 roswtf.roslaunchwtf.wtf_check_online(ctx) 223 224 for p in online_plugins: 225 online_checks = True 226 p(ctx) 227 228 if online_checks: 229 # done 230 print "\nOnline checks summary:\n" 231 print_results(ctx) 232 233 except roswtf.context.WtfException, e: 234 print >> sys.stderr, str(e) 235 print "\nAborting checks, partial results summary:\n" 236 print_results(ctx) 237 except Exception, e: 238 traceback.print_exc() 239 print >> sys.stderr, str(e) 240 print "\nAborting checks, partial results summary:\n" 241 print_results(ctx)
242 243 #TODO: print results in YAML if run remotely 244 #yaml_results(ctx) 245