1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
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
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
63
64 raise Exception("Could not connect to existing ROS master. "
65 + "Original exception was: %s" % str(e))
66 except:
67
68
69 raise Exception("Could not connect to existing ROS master.")
70
71 if clear:
72 params = param_server.getParamNames()
73
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
94
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
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
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
127 """
128 run the test, blocks until completion
129 """
130 if self.runner is not None:
131
132 return self.runner.run_test(test)
133 else:
134 raise Exception("no runner")
135