OrganizationSDOPackageTest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 #
4 ## OrganizationSDOPackageTest.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 import socket
20 import RTM
21 
22 env = RtmEnv(sys.argv, ["localhost:9898"])
23 
24 ## Get Manager object reference
25 mgr_name = socket.gethostname()+".host_cxt/manager.mgr"
26 naming = CorbaNaming(env.orb, "localhost:9898")
27 manager = naming.resolve(mgr_name)._narrow(RTM.Manager)
28 ## Create Composite RTC.
29 manager.create_component("PeriodicECSharedComposite?instance_name=a&exported_ports=ConsoleIn0.out,ConsoleOut0.in")
30 
31 time.sleep(2)
32 
33 listo = env.name_space["localhost:9898"].list_obj()
34 env.name_space['localhost:9898'].rtc_handles.keys()
35 
36 ns = env.name_space['localhost:9898']
37 
38 a0 = ns.rtc_handles["a.rtc"]
39 org = a0.rtc_ref.get_owned_organizations()[0]
40 nv = SDOPackage.NameValue("Test", any.to_any(100))
41 
42 def mem_rss():
43  (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
44  return output.split()[7]
45 
46 ## file and console out
47 def print_file_and_cons(out_data, out_flag=0):
48  ## out_flag:1 is file out only
49  if out_flag == 1:
50  fout.write(out_data + '\n')
51  fout.flush()
52  ## out_flag:2 is console out only
53  elif out_flag == 2:
54  print out_data
55  ## out_flag:0 is console and file out (default)
56  else:
57  print out_data
58  fout.write(out_data + '\n')
59  fout.flush()
60  return
61 
62 ## memory leak check
63 def leak_check(rss_start, rss_end):
64  if rss_start != rss_end:
65  fodat = " result: memory leak was found !!!"
66  else:
67  fodat = " result: memory leak was not found."
68  print_file_and_cons(fodat)
69  return
70 
71 ## file out setting
72 test_case = "OrganizationSDOPackageTest"
73 fout = open(test_case + ".log", 'w')
74 
75 fodat = "=== " + test_case + " start ==="
77 
78 loop_cnt = 1000
79 ## -----------------------------------------------------------------------------
80 fodat = "get_organization_id()"
82 
83 for i in range(loop_cnt):
84  ## Organization::get_organization_id ();
85  id = org.get_organization_id()
86 
87  if i == 0:
88  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
89  fodat = " %05d: %s KB start" % (1, rss0)
90  print_file_and_cons(fodat,1)
91  rss1 = mem_rss() ; j1 = i
92  if rss0 != rss1:
93  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
94  print_file_and_cons(fodat,1)
95  rss0 = rss1 ; j0 = j1
96 
97 rssEnd = mem_rss()
98 fodat = " %05d: %s KB end" % (i+1, rssEnd)
99 print_file_and_cons(fodat,1)
100 leak_check(rssStart, rssEnd)
101 ## -----------------------------------------------------------------------------
102 fodat = "get_organization_property()"
103 print_file_and_cons(fodat)
104 
105 for i in range(loop_cnt):
106  ## Organization::get_organization_property ();
107  prop = org.get_organization_property()
108 
109  if i == 0:
110  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
111  fodat = " %05d: %s KB start" % (1, rss0)
112  print_file_and_cons(fodat,1)
113  rss1 = mem_rss() ; j1 = i
114  if rss0 != rss1:
115  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
116  print_file_and_cons(fodat,1)
117  rss0 = rss1 ; j0 = j1
118 
119 rssEnd = mem_rss()
120 fodat = " %05d: %s KB end" % (i+1, rssEnd)
121 print_file_and_cons(fodat,1)
122 leak_check(rssStart, rssEnd)
123 ## -----------------------------------------------------------------------------
124 fodat = "get_owner()"
125 print_file_and_cons(fodat)
126 
127 for i in range(loop_cnt):
128  ## Organization::get_owner ();
129  org.get_owner()
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 = "get_organizations()"
147 print_file_and_cons(fodat)
148 
149 for i in range(loop_cnt):
150  ## SDOSystemElement::get_organizations ();
151  a0.rtc_ref.get_organizations()
152 
153  if i == 0:
154  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
155  fodat = " %05d: %s KB start" % (1, rss0)
156  print_file_and_cons(fodat,1)
157  rss1 = mem_rss() ; j1 = i
158  if rss0 != rss1:
159  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
160  print_file_and_cons(fodat,1)
161  rss0 = rss1 ; j0 = j1
162 
163 rssEnd = mem_rss()
164 fodat = " %05d: %s KB end" % (i+1, rssEnd)
165 print_file_and_cons(fodat,1)
166 leak_check(rssStart, rssEnd)
167 ## -----------------------------------------------------------------------------
168 fodat = "add_organization_property() and get_organization_property_value() and \nremove_organization_property()"
169 print_file_and_cons(fodat)
170 
171 for i in range(loop_cnt):
172  ## Organization::add_organization_property (in OrganizationProperty organization_property);
173  org.add_organization_property(SDOPackage.OrganizationProperty([nv]))
174 
175  ## Organization::get_organization_property_value (in string name);
176  org.get_organization_property_value("Test")
177 
178  ## Organization::remove_organization_property ( in string name );
179  org.remove_organization_property("Test")
180 
181  if i == 0:
182  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
183  fodat = " %05d: %s KB start" % (1, rss0)
184  print_file_and_cons(fodat,1)
185  rss1 = mem_rss() ; j1 = i
186  if rss0 != rss1:
187  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
188  print_file_and_cons(fodat,1)
189  rss0 = rss1 ; j0 = j1
190 
191 rssEnd = mem_rss()
192 fodat = " %05d: %s KB end" % (i+1, rssEnd)
193 print_file_and_cons(fodat,1)
194 leak_check(rssStart, rssEnd)
195 ## -----------------------------------------------------------------------------
196 fodat = "set_organization_property_value()"
197 print_file_and_cons(fodat)
198 
199 for i in range(loop_cnt):
200  ## Organization::set_organization_property_value (in string name,in any value);
201  org.set_organization_property_value("Test2",any.to_any(200))
202 
203  if i == 0:
204  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
205  fodat = " %05d: %s KB start" % (1, rss0)
206  print_file_and_cons(fodat,1)
207  rss1 = mem_rss() ; j1 = i
208  if rss0 != rss1:
209  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
210  print_file_and_cons(fodat,1)
211  rss0 = rss1 ; j0 = j1
212 
213 rssEnd = mem_rss()
214 fodat = " %05d: %s KB end" % (i+1, rssEnd)
215 print_file_and_cons(fodat,1)
216 leak_check(rssStart, rssEnd)
217 ## -----------------------------------------------------------------------------
218 fodat = "set_owner()"
219 print_file_and_cons(fodat)
220 
221 for i in range(loop_cnt):
222  ## Organization::set_owner (in SDOSystemElement sdo);
223  org.set_owner(a0.rtc_ref)
224 
225  if i == 0:
226  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
227  fodat = " %05d: %s KB start" % (1, rss0)
228  print_file_and_cons(fodat,1)
229  rss1 = mem_rss() ; j1 = i
230  if rss0 != rss1:
231  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
232  print_file_and_cons(fodat,1)
233  rss0 = rss1 ; j0 = j1
234 
235 rssEnd = mem_rss()
236 fodat = " %05d: %s KB end" % (i+1, rssEnd)
237 print_file_and_cons(fodat,1)
238 leak_check(rssStart, rssEnd)
239 ## -----------------------------------------------------------------------------
240 
241 fodat = "=== " + test_case + " end ==="
242 print_file_and_cons(fodat)
243 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 Thu Jun 6 2019 19:25:59