ConnectRTCTest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 #
4 ## ConnectRTCTest.py
5 
12 
13 from rtc_handle import *
14 from BasicDataType_idl import *
15 import time
16 import commands
17 import SDOPackage
18 
19 env = RtmEnv(sys.argv, ["localhost:9898"])
20 list0 = env.name_space["localhost:9898"].list_obj()
21 env.name_space['localhost:9898'].rtc_handles.keys()
22 
23 time.sleep(2)
24 
25 ns = env.name_space['localhost:9898']
26 
27 compo0 = ns.rtc_handles["ConsoleIn0.rtc"]
28 compo1 = ns.rtc_handles["ConsoleOut0.rtc"]
29 
30 def mem_rss():
31  (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
32  return output.split()[7]
33 
34 ## file and console out
35 def print_file_and_cons(out_data, out_flag=0):
36  ## out_flag:1 is file out only
37  if out_flag == 1:
38  fout.write(out_data + '\n')
39  fout.flush()
40  ## out_flag:2 is console out only
41  elif out_flag == 2:
42  print out_data
43  ## out_flag:0 is console and file out (default)
44  else:
45  print out_data
46  fout.write(out_data + '\n')
47  fout.flush()
48  return
49 
50 ## memory leak check
51 def leak_check(rss_start, rss_end):
52  if rss_start != rss_end:
53  fodat = " result: memory leak was found !!!"
54  else:
55  fodat = " result: memory leak was not found."
56  print_file_and_cons(fodat)
57  return
58 
59 ## file out setting
60 test_case = "ConnectRTCTest"
61 fout = open(test_case + ".log", 'w')
62 
63 fodat = "=== " + test_case + " start ==="
65 
66 loop_cnt = 1000
67 ## -----------------------------------------------------------------------------
68 consin_ports = compo0.rtc_ref.get_ports()
69 #print "List consin_ports=%d" % len(consin_ports)
70 consout_ports = compo1.rtc_ref.get_ports()
71 #print "List consout_ports=%d" % len(consout_ports)
72 
73 ##--------------------------------------------------------------------
74 # Connector Porfile: corba_cdr, push, flush <<< In -> Out
75 conprof = RTC.ConnectorProfile("connector0", "123", [consin_ports[0],consout_ports[0]], [SDOPackage.NameValue("dataport.interface_type",any.to_any("corba_cdr")),SDOPackage.NameValue("dataport.dataflow_type",any.to_any("push")),SDOPackage.NameValue("dataport.subscription_type",any.to_any("flush"))])
76 
77 # Connector Porfile: corba_cdr, push, flush <<< Out -> In
78 #conprof = RTC.ConnectorProfile("connector0", "123", [consout_ports[0],consin_ports[0]], [SDOPackage.NameValue("dataport.interface_type",any.to_any("corba_cdr")),SDOPackage.NameValue("dataport.dataflow_type",any.to_any("push")),SDOPackage.NameValue("dataport.subscription_type",any.to_any("flush"))])
79 
80 ##--------------------------------------------------------------------
81 # Connector Porfile: corba_cdr, push, new <<< In -> Out
82 #conprof = RTC.ConnectorProfile("connector0", "123", [consin_ports[0],consout_ports[0]], [SDOPackage.NameValue("dataport.interface_type",any.to_any("corba_cdr")),SDOPackage.NameValue("dataport.dataflow_type",any.to_any("push")),SDOPackage.NameValue("dataport.subscription_type",any.to_any("new"))])
83 
84 # Connector Porfile: corba_cdr, push, new <<< Out -> In
85 #conprof = RTC.ConnectorProfile("connector0", "123", [consout_ports[0],consin_ports[0]], [SDOPackage.NameValue("dataport.interface_type",any.to_any("corba_cdr")),SDOPackage.NameValue("dataport.dataflow_type",any.to_any("push")),SDOPackage.NameValue("dataport.subscription_type",any.to_any("new"))])
86 
87 ##--------------------------------------------------------------------
88 # Connector Porfile: corba_cdr, push, periodic <<< In -> Out
89 #conprof = RTC.ConnectorProfile("connector0", "123", [consin_ports[0],consout_ports[0]], [SDOPackage.NameValue("dataport.interface_type",any.to_any("corba_cdr")),SDOPackage.NameValue("dataport.dataflow_type",any.to_any("push")),SDOPackage.NameValue("dataport.subscription_type",any.to_any("periodic")),SDOPackage.NameValue("dataport.publisher.push_rate",any.to_any(2000))])
90 
91 # Connector Porfile: corba_cdr, push, periodic <<< Out -> In
92 #conprof = RTC.ConnectorProfile("connector0", "123", [consout_ports[0],consin_ports[0]], [SDOPackage.NameValue("dataport.interface_type",any.to_any("corba_cdr")),SDOPackage.NameValue("dataport.dataflow_type",any.to_any("push")),SDOPackage.NameValue("dataport.subscription_type",any.to_any("periodic")),SDOPackage.NameValue("dataport.publisher.push_rate",any.to_any(2000))])
93 
94 ##--------------------------------------------------------------------
95 #print "ConnectorProfile=\n",conprof
96 
97 ## -----------------------------------------------------------------------------
98 fodat = "get_ports()"
100 
101 for i in range(loop_cnt):
102  # RTObject::get_ports()
103  #consin_ports[0].connect(conprof)
104  compo1.rtc_ref.get_ports()
105  #consin_ports[0].disconnect(conprof.connector_id) # set used
106 
107  if i == 0:
108  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
109  fodat = " %05d: %s KB start" % (1, rss0)
110  print_file_and_cons(fodat,1)
111  rss1 = mem_rss() ; j1 = i
112  if rss0 != rss1:
113  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
114  print_file_and_cons(fodat,1)
115  rss0 = rss1 ; j0 = j1
116 
117 rssEnd = mem_rss()
118 fodat = " %05d: %s KB end" % (i+1, rssEnd)
119 print_file_and_cons(fodat,1)
120 leak_check(rssStart, rssEnd)
121 ## -----------------------------------------------------------------------------
122 fodat = "get_port_profile()"
123 print_file_and_cons(fodat)
124 
125 for i in range(loop_cnt):
126  # PortService::get_port_profile()
127  #consin_ports[0].connect(conprof)
128  consin_ports[0].get_port_profile()
129  #consin_ports[0].disconnect(conprof.connector_id) # set used
130 
131  if i == 0:
132  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
133  fodat = " %05d: %s KB start" % (1, rss0)
134  print_file_and_cons(fodat,1)
135  rss1 = mem_rss() ; j1 = i
136  if rss0 != rss1:
137  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
138  print_file_and_cons(fodat,1)
139  rss0 = rss1 ; j0 = j1
140 
141 rssEnd = mem_rss()
142 fodat = " %05d: %s KB end" % (i+1, rssEnd)
143 print_file_and_cons(fodat,1)
144 leak_check(rssStart, rssEnd)
145 ## -----------------------------------------------------------------------------
146 fodat = "notify_connect() and notify_disconnect()"
147 print_file_and_cons(fodat)
148 
149 for i in range(loop_cnt):
150  # PortService::notify_connect(inout ConnectorProfile connector_profile)
151  ret0 = consin_ports[0].notify_connect(conprof)
152  #print "ret0=",ret0
153  # PortService::notify_disconnect(in UniqueIdentifier connector_id)
154  ret1 = consin_ports[0].notify_disconnect(conprof.connector_id) # set used
155  #if ret1 != RTC.RTC_OK:
156  # print "ret1=",ret1
157 
158  if i == 0:
159  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
160  fodat = " %05d: %s KB start" % (1, rss0)
161  print_file_and_cons(fodat,1)
162  rss1 = mem_rss() ; j1 = i
163  if rss0 != rss1:
164  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
165  print_file_and_cons(fodat,1)
166  rss0 = rss1 ; j0 = j1
167 
168 rssEnd = mem_rss()
169 fodat = " %05d: %s KB end" % (i+1, rssEnd)
170 print_file_and_cons(fodat,1)
171 leak_check(rssStart, rssEnd)
172 ## -----------------------------------------------------------------------------
173 fodat = "get_connector_profiles()"
174 print_file_and_cons(fodat)
175 
176 for i in range(loop_cnt):
177  # PortService::get_connector_profiles()
178  consin_ports[0].connect(conprof)
179  consin_ports[0].get_connector_profiles()
180  consin_ports[0].disconnect(conprof.connector_id) # set used
181 
182  if i == 0:
183  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
184  fodat = " %05d: %s KB start" % (1, rss0)
185  print_file_and_cons(fodat,1)
186  rss1 = mem_rss() ; j1 = i
187  if rss0 != rss1:
188  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
189  print_file_and_cons(fodat,1)
190  rss0 = rss1 ; j0 = j1
191 
192 rssEnd = mem_rss()
193 fodat = " %05d: %s KB end" % (i+1, rssEnd)
194 print_file_and_cons(fodat,1)
195 leak_check(rssStart, rssEnd)
196 ## -----------------------------------------------------------------------------
197 fodat = "get_connector_profile()"
198 print_file_and_cons(fodat)
199 
200 for i in range(loop_cnt):
201  # PortService::get_connector_profile(in UniqueIdentifier connector_id)
202  consin_ports[0].connect(conprof)
203  consin_ports[0].get_connector_profile(conprof.connector_id)
204  consin_ports[0].disconnect(conprof.connector_id) # set used
205 
206  if i == 0:
207  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
208  fodat = " %05d: %s KB start" % (1, rss0)
209  print_file_and_cons(fodat,1)
210  rss1 = mem_rss() ; j1 = i
211  if rss0 != rss1:
212  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
213  print_file_and_cons(fodat,1)
214  rss0 = rss1 ; j0 = j1
215 
216 rssEnd = mem_rss()
217 fodat = " %05d: %s KB end" % (i+1, rssEnd)
218 print_file_and_cons(fodat,1)
219 leak_check(rssStart, rssEnd)
220 ## -----------------------------------------------------------------------------
221 fodat = "connect() and disconnect()"
222 print_file_and_cons(fodat)
223 
224 for i in range(loop_cnt):
225  # PortService::connect(inout ConnectorProfile connector_profile)
226  ret0 = consin_ports[0].connect(conprof)
227  #print "ret0=",ret0
228  ret1 = consin_ports[0].disconnect(conprof.connector_id) # set used
229  #if ret1 != RTC.RTC_OK:
230  # print "ret1=",ret1
231 
232  if i == 0:
233  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
234  fodat = " %05d: %s KB start" % (1, rss0)
235  print_file_and_cons(fodat,1)
236  rss1 = mem_rss() ; j1 = i
237  if rss0 != rss1:
238  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
239  print_file_and_cons(fodat,1)
240  rss0 = rss1 ; j0 = j1
241 
242 rssEnd = mem_rss()
243 fodat = " %05d: %s KB end" % (i+1, rssEnd)
244 print_file_and_cons(fodat,1)
245 leak_check(rssStart, rssEnd)
246 ## -----------------------------------------------------------------------------
247 fodat = "connect() and disconnect_all()"
248 print_file_and_cons(fodat)
249 
250 for i in range(loop_cnt):
251  # PortService::connect(inout ConnectorProfile connector_profile)
252  ret0 = consin_ports[0].connect(conprof)
253  #print "ret0=",ret0
254  # PortService::disconnect_all()
255  consin_ports[0].disconnect_all()
256 
257  if i == 0:
258  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
259  fodat = " %05d: %s KB start" % (1, rss0)
260  print_file_and_cons(fodat,1)
261  rss1 = mem_rss() ; j1 = i
262  if rss0 != rss1:
263  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
264  print_file_and_cons(fodat,1)
265  rss0 = rss1 ; j0 = j1
266 
267 rssEnd = mem_rss()
268 fodat = " %05d: %s KB end" % (i+1, rssEnd)
269 print_file_and_cons(fodat,1)
270 leak_check(rssStart, rssEnd)
271 ## -----------------------------------------------------------------------------
272 
273 fodat = "=== " + test_case + " end ==="
274 print_file_and_cons(fodat)
275 fout.close()
def print_file_and_cons(out_data, out_flag=0)
file and console out
def leak_check(rss_start, rss_end)
memory leak check


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:50