ServiceProfileSDOPackageTest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 #
4 ## ServiceProfileSDOPackageTest.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 SDOPackage__POA
20 import socket
21 import RTM
22 
23 ## Dummy class of SDOService_impl.
24 class SDOServiceMock(SDOPackage__POA.SDOService):
25  def __init__(self):
26  pass
27 
28 env = RtmEnv(sys.argv, ["localhost:9898"])
29 
30 ## Get Manager object reference
31 mgr_name = socket.gethostname()+".host_cxt/manager.mgr"
32 naming = CorbaNaming(env.orb, "localhost:9898")
33 manager = naming.resolve(mgr_name)._narrow(RTM.Manager)
34 ## Create Composite RTC.
35 manager.create_component("PeriodicECSharedComposite?instance_name=a&exported_ports=ConsoleIn0.out,ConsoleOut0.in")
36 
37 time.sleep(2)
38 
39 listo = env.name_space["localhost:9898"].list_obj()
40 env.name_space['localhost:9898'].rtc_handles.keys()
41 
42 ns = env.name_space['localhost:9898']
43 
44 
45 a0 = ns.rtc_handles["a.rtc"]
46 config = a0.rtc_ref.get_configuration()
47 svcprofs = a0.rtc_ref.get_service_profiles()
48 
49 sdomock = SDOServiceMock()._this()
50 svcProf = SDOPackage.ServiceProfile("ID 1", "INTERFACE_TYPE 1", [], sdomock)
51 
52 def mem_rss():
53  (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
54  return output.split()[7]
55 
56 ## file and console out
57 def print_file_and_cons(out_data, out_flag=0):
58  ## out_flag:1 is file out only
59  if out_flag == 1:
60  fout.write(out_data + '\n')
61  fout.flush()
62  ## out_flag:2 is console out only
63  elif out_flag == 2:
64  print out_data
65  ## out_flag:0 is console and file out (default)
66  else:
67  print out_data
68  fout.write(out_data + '\n')
69  fout.flush()
70  return
71 
72 ## memory leak check
73 def leak_check(rss_start, rss_end):
74  if rss_start != rss_end:
75  fodat = " result: memory leak was found !!!"
76  else:
77  fodat = " result: memory leak was not found."
78  print_file_and_cons(fodat)
79  return
80 
81 ## file out setting
82 test_case = "ServiceProfileSDOPackageTest"
83 fout = open(test_case + ".log", 'w')
84 
85 fodat = "=== " + test_case + " start ==="
87 
88 loop_cnt = 1000
89 ## -----------------------------------------------------------------------------
90 fodat = "add_service_profile()"
92 
93 for i in range(loop_cnt):
94  ## Configuration::add_service_profile (in ServiceProfile sProfile);
95  config.add_service_profile(svcProf)
96 
97  if i == 0:
98  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
99  fodat = " %05d: %s KB start" % (1, rss0)
100  print_file_and_cons(fodat,1)
101  rss1 = mem_rss() ; j1 = i
102  if rss0 != rss1:
103  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
104  print_file_and_cons(fodat,1)
105  rss0 = rss1 ; j0 = j1
106 
107 rssEnd = mem_rss()
108 fodat = " %05d: %s KB end" % (i+1, rssEnd)
109 print_file_and_cons(fodat,1)
110 leak_check(rssStart, rssEnd)
111 ## -----------------------------------------------------------------------------
112 fodat = "get_service_profiles()"
113 print_file_and_cons(fodat)
114 
115 for i in range(loop_cnt):
116  ## SDOSystemElement::get_service_profiles ();
117  a0.rtc_ref.get_service_profiles()
118 
119  if i == 0:
120  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
121  fodat = " %05d: %s KB start" % (1, rss0)
122  print_file_and_cons(fodat,1)
123  rss1 = mem_rss() ; j1 = i
124  if rss0 != rss1:
125  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
126  print_file_and_cons(fodat,1)
127  rss0 = rss1 ; j0 = j1
128 
129 rssEnd = mem_rss()
130 fodat = " %05d: %s KB end" % (i+1, rssEnd)
131 print_file_and_cons(fodat,1)
132 leak_check(rssStart, rssEnd)
133 ## -----------------------------------------------------------------------------
134 fodat = "get_service_profile()"
135 print_file_and_cons(fodat)
136 
137 for i in range(loop_cnt):
138  ## SDOSystemElement::get_service_profile (in UniqueIdentifier id);
139  a0.rtc_ref.get_service_profile("ID 1")
140 
141  if i == 0:
142  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
143  fodat = " %05d: %s KB start" % (1, rss0)
144  print_file_and_cons(fodat,1)
145  rss1 = mem_rss() ; j1 = i
146  if rss0 != rss1:
147  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
148  print_file_and_cons(fodat,1)
149  rss0 = rss1 ; j0 = j1
150 
151 rssEnd = mem_rss()
152 fodat = " %05d: %s KB end" % (i+1, rssEnd)
153 print_file_and_cons(fodat,1)
154 leak_check(rssStart, rssEnd)
155 ## -----------------------------------------------------------------------------
156 fodat = "get_sdo_service()"
157 print_file_and_cons(fodat)
158 
159 for i in range(loop_cnt):
160  ## SDOSystemElement::get_sdo_service (in UniqueIdentifier id);
161  a0.rtc_ref.get_sdo_service("ID 1")
162 
163  if i == 0:
164  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
165  fodat = " %05d: %s KB start" % (1, rss0)
166  print_file_and_cons(fodat,1)
167  rss1 = mem_rss() ; j1 = i
168  if rss0 != rss1:
169  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
170  print_file_and_cons(fodat,1)
171  rss0 = rss1 ; j0 = j1
172 
173 rssEnd = mem_rss()
174 fodat = " %05d: %s KB end" % (i+1, rssEnd)
175 print_file_and_cons(fodat,1)
176 leak_check(rssStart, rssEnd)
177 ## -----------------------------------------------------------------------------
178 fodat = "remove_service_profile()"
179 print_file_and_cons(fodat)
180 
181 for i in range(loop_cnt):
182  ## Configuration::remove_service_profile (in UniqueIdentifier id);
183  config.remove_service_profile("ID 1")
184 
185  if i == 0:
186  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
187  fodat = " %05d: %s KB start" % (1, rss0)
188  print_file_and_cons(fodat,1)
189  rss1 = mem_rss() ; j1 = i
190  if rss0 != rss1:
191  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
192  print_file_and_cons(fodat,1)
193  rss0 = rss1 ; j0 = j1
194 
195 rssEnd = mem_rss()
196 fodat = " %05d: %s KB end" % (i+1, rssEnd)
197 print_file_and_cons(fodat,1)
198 leak_check(rssStart, rssEnd)
199 ## -----------------------------------------------------------------------------
200 
201 fodat = "=== " + test_case + " end ==="
202 print_file_and_cons(fodat)
203 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:26:00