SDOPackageTest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 #
4 ## SDOPackageTest.py
5 
12 
13 from rtc_handle import *
14 from BasicDataType_idl import *
15 from omniORB import any
16 import time
17 import commands
18 import SDOPackage
19 
20 env = RtmEnv(sys.argv, ["localhost:9898"])
21 listo = env.name_space["localhost:9898"].list_obj()
22 env.name_space['localhost:9898'].rtc_handles.keys()
23 
24 time.sleep(2)
25 
26 ns = env.name_space['localhost:9898']
27 
28 consin0 = ns.rtc_handles["ConsoleIn0.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 = "SDOPackageTest"
61 fout = open(test_case + ".log", 'w')
62 
63 fodat = "=== " + test_case + " start ==="
65 
66 loop_cnt = 1000
67 ## -----------------------------------------------------------------------------
68 ## SDOSystemElement::get_monitoring ();
69 ###consin0.rtc_ref.get_monitoring () # not implemented.
70 ## SDOSystemElement::get_status (in string nme);
71 ###consin0.rtc_ref.get_status (in string nme) # can not test. because m_sdoStatus is not set.
72 
73 ## -----------------------------------------------------------------------------
74 fodat = "get_owned_organizations()"
76 
77 for i in range(loop_cnt):
78  ## SDOSystemElement::get_owned_organizations()
79  consin0.rtc_ref.get_owned_organizations()
80 
81  if i == 0:
82  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
83  fodat = " %05d: %s KB start" % (1, rss0)
84  print_file_and_cons(fodat,1)
85  rss1 = mem_rss() ; j1 = i
86  if rss0 != rss1:
87  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
88  print_file_and_cons(fodat,1)
89  rss0 = rss1 ; j0 = j1
90 
91 rssEnd = mem_rss()
92 fodat = " %05d: %s KB end" % (i+1, rssEnd)
93 print_file_and_cons(fodat,1)
94 leak_check(rssStart, rssEnd)
95 ## -----------------------------------------------------------------------------
96 fodat = "get_sdo_id()"
98 
99 for i in range(loop_cnt):
100  ## SDOSystemElement::get_sdo_id();
101  consin0.rtc_ref.get_sdo_id()
102 
103  if i == 0:
104  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
105  fodat = " %05d: %s KB start" % (1, rss0)
106  print_file_and_cons(fodat,1)
107  rss1 = mem_rss() ; j1 = i
108  if rss0 != rss1:
109  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
110  print_file_and_cons(fodat,1)
111  rss0 = rss1 ; j0 = j1
112 
113 rssEnd = mem_rss()
114 fodat = " %05d: %s KB end" % (i+1, rssEnd)
115 print_file_and_cons(fodat,1)
116 leak_check(rssStart, rssEnd)
117 ## -----------------------------------------------------------------------------
118 fodat = "get_sdo_type()"
119 print_file_and_cons(fodat)
120 
121 for i in range(loop_cnt):
122  ## SDOSystemElement::get_sdo_type();
123  consin0.rtc_ref.get_sdo_type()
124 
125  if i == 0:
126  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
127  fodat = " %05d: %s KB start" % (1, rss0)
128  print_file_and_cons(fodat,1)
129  rss1 = mem_rss() ; j1 = i
130  if rss0 != rss1:
131  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
132  print_file_and_cons(fodat,1)
133  rss0 = rss1 ; j0 = j1
134 
135 rssEnd = mem_rss()
136 fodat = " %05d: %s KB end" % (i+1, rssEnd)
137 print_file_and_cons(fodat,1)
138 leak_check(rssStart, rssEnd)
139 ## -----------------------------------------------------------------------------
140 fodat = "get_device_profile()"
141 print_file_and_cons(fodat)
142 
143 for i in range(loop_cnt):
144  ## SDOSystemElement::get_device_profile ();
145  consin0.rtc_ref.get_device_profile ()
146 
147  if i == 0:
148  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
149  fodat = " %05d: %s KB start" % (1, rss0)
150  print_file_and_cons(fodat,1)
151  rss1 = mem_rss() ; j1 = i
152  if rss0 != rss1:
153  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
154  print_file_and_cons(fodat,1)
155  rss0 = rss1 ; j0 = j1
156 
157 rssEnd = mem_rss()
158 fodat = " %05d: %s KB end" % (i+1, rssEnd)
159 print_file_and_cons(fodat,1)
160 leak_check(rssStart, rssEnd)
161 ## -----------------------------------------------------------------------------
162 fodat = "get_configuration()"
163 print_file_and_cons(fodat)
164 
165 for i in range(loop_cnt):
166  ## SDOSystemElement::get_configuration ();
167  config = consin0.rtc_ref.get_configuration ()
168 
169  if i == 0:
170  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
171  fodat = " %05d: %s KB start" % (1, rss0)
172  print_file_and_cons(fodat,1)
173  rss1 = mem_rss() ; j1 = i
174  if rss0 != rss1:
175  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
176  print_file_and_cons(fodat,1)
177  rss0 = rss1 ; j0 = j1
178 
179 rssEnd = mem_rss()
180 fodat = " %05d: %s KB end" % (i+1, rssEnd)
181 print_file_and_cons(fodat,1)
182 leak_check(rssStart, rssEnd)
183 ## -----------------------------------------------------------------------------
184 fodat = "get_status_list()"
185 print_file_and_cons(fodat)
186 
187 for i in range(loop_cnt):
188  ## SDOSystemElement::get_status_list ();
189  consin0.rtc_ref.get_status_list ()
190 
191  if i == 0:
192  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
193  fodat = " %05d: %s KB start" % (1, rss0)
194  print_file_and_cons(fodat,1)
195  rss1 = mem_rss() ; j1 = i
196  if rss0 != rss1:
197  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
198  print_file_and_cons(fodat,1)
199  rss0 = rss1 ; j0 = j1
200 
201 rssEnd = mem_rss()
202 fodat = " %05d: %s KB end" % (i+1, rssEnd)
203 print_file_and_cons(fodat,1)
204 leak_check(rssStart, rssEnd)
205 ## -----------------------------------------------------------------------------
206 fodat = "set_device_profile()"
207 print_file_and_cons(fodat)
208 
209 for i in range(loop_cnt):
210  ## Configuration::set_device_profile (in DeviceProfile dProfile);
211  devProf = SDOPackage.DeviceProfile("test","","","0.1.0",[])
212  config.set_device_profile (devProf)
213 
214  if i == 0:
215  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
216  fodat = " %05d: %s KB start" % (1, rss0)
217  print_file_and_cons(fodat,1)
218  rss1 = mem_rss() ; j1 = i
219  if rss0 != rss1:
220  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
221  print_file_and_cons(fodat,1)
222  rss0 = rss1 ; j0 = j1
223 
224 rssEnd = mem_rss()
225 fodat = " %05d: %s KB end" % (i+1, rssEnd)
226 print_file_and_cons(fodat,1)
227 leak_check(rssStart, rssEnd)
228 ## -----------------------------------------------------------------------------
229 fodat = "get_configuration_parameters()"
230 print_file_and_cons(fodat)
231 
232 for i in range(loop_cnt):
233  ## Configuration::get_configuration_parameters ();
234  config.get_configuration_parameters ()
235 
236  if i == 0:
237  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
238  fodat = " %05d: %s KB start" % (1, rss0)
239  print_file_and_cons(fodat,1)
240  rss1 = mem_rss() ; j1 = i
241  if rss0 != rss1:
242  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
243  print_file_and_cons(fodat,1)
244  rss0 = rss1 ; j0 = j1
245 
246 rssEnd = mem_rss()
247 fodat = " %05d: %s KB end" % (i+1, rssEnd)
248 print_file_and_cons(fodat,1)
249 leak_check(rssStart, rssEnd)
250 ## -----------------------------------------------------------------------------
251 fodat = "get_configuration_parameter_values()"
252 print_file_and_cons(fodat)
253 
254 for i in range(loop_cnt):
255  ## Configuration::get_configuration_parameter_values ();
256  config.get_configuration_parameter_values ()
257 
258  if i == 0:
259  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
260  fodat = " %05d: %s KB start" % (1, rss0)
261  print_file_and_cons(fodat,1)
262  rss1 = mem_rss() ; j1 = i
263  if rss0 != rss1:
264  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
265  print_file_and_cons(fodat,1)
266  rss0 = rss1 ; j0 = j1
267 
268 rssEnd = mem_rss()
269 fodat = " %05d: %s KB end" % (i+1, rssEnd)
270 print_file_and_cons(fodat,1)
271 leak_check(rssStart, rssEnd)
272 ## -----------------------------------------------------------------------------
273 fodat = "get_configuration_parameter_value()"
274 print_file_and_cons(fodat)
275 
276 for i in range(loop_cnt):
277  ## Configuration::get_configuration_parameter_value (in string name);
278  config.get_configuration_parameter_value ("test")
279 
280  if i == 0:
281  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
282  fodat = " %05d: %s KB start" % (1, rss0)
283  print_file_and_cons(fodat,1)
284  rss1 = mem_rss() ; j1 = i
285  if rss0 != rss1:
286  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
287  print_file_and_cons(fodat,1)
288  rss0 = rss1 ; j0 = j1
289 
290 rssEnd = mem_rss()
291 fodat = " %05d: %s KB end" % (i+1, rssEnd)
292 print_file_and_cons(fodat,1)
293 leak_check(rssStart, rssEnd)
294 ## -----------------------------------------------------------------------------
295 fodat = "set_configuration_parameter()"
296 print_file_and_cons(fodat)
297 
298 for i in range(loop_cnt):
299  ## Configuration::set_configuration_parameter (in string name,in any value);
300  config.set_configuration_parameter ("test",any.to_any("value"))
301 
302  if i == 0:
303  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
304  fodat = " %05d: %s KB start" % (1, rss0)
305  print_file_and_cons(fodat,1)
306  rss1 = mem_rss() ; j1 = i
307  if rss0 != rss1:
308  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
309  print_file_and_cons(fodat,1)
310  rss0 = rss1 ; j0 = j1
311 
312 rssEnd = mem_rss()
313 fodat = " %05d: %s KB end" % (i+1, rssEnd)
314 print_file_and_cons(fodat,1)
315 leak_check(rssStart, rssEnd)
316 ## -----------------------------------------------------------------------------
317 fodat = "get_configuration_sets()"
318 print_file_and_cons(fodat)
319 
320 for i in range(loop_cnt):
321  ## Configuration::get_configuration_sets ();
322  config.get_configuration_sets ()
323 
324  if i == 0:
325  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
326  fodat = " %05d: %s KB start" % (1, rss0)
327  print_file_and_cons(fodat,1)
328  rss1 = mem_rss() ; j1 = i
329  if rss0 != rss1:
330  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
331  print_file_and_cons(fodat,1)
332  rss0 = rss1 ; j0 = j1
333 
334 rssEnd = mem_rss()
335 fodat = " %05d: %s KB end" % (i+1, rssEnd)
336 print_file_and_cons(fodat,1)
337 leak_check(rssStart, rssEnd)
338 ## -----------------------------------------------------------------------------
339 
340 fodat = "=== " + test_case + " end ==="
341 print_file_and_cons(fodat)
342 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:56