DataPortTest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 #
4 ## DataPortTest.py
5 
12 
13 from rtc_handle import *
14 from BasicDataType_idl import *
15 import time
16 import commands
17 import SDOPackage
18 from omniORB import *
19 from omniORB import any
20 from omniORB import CORBA
21 import OpenRTM
22 
23 env = RtmEnv(sys.argv, ["localhost:9898"])
24 list0 = env.name_space["localhost:9898"].list_obj()
25 env.name_space['localhost:9898'].rtc_handles.keys()
26 
27 time.sleep(2)
28 
29 ns = env.name_space['localhost:9898']
30 
31 compo0 = ns.rtc_handles["ConsoleIn0.rtc"]
32 compo1 = ns.rtc_handles["ConsoleOut0.rtc"]
33 
34 #compo0 = ns.rtc_handles["SequenceInComponent0.rtc"]
35 #compo1 = ns.rtc_handles["SequenceOutComponent0.rtc"]
36 
37 def mem_rss():
38  (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
39  return output.split()[7]
40 
41 ## file and console out
42 def print_file_and_cons(out_data, out_flag=0):
43  ## out_flag:1 is file out only
44  if out_flag == 1:
45  fout.write(out_data + '\n')
46  fout.flush()
47  ## out_flag:2 is console out only
48  elif out_flag == 2:
49  print out_data
50  ## out_flag:0 is console and file out (default)
51  else:
52  print out_data
53  fout.write(out_data + '\n')
54  fout.flush()
55  return
56 
57 ## memory leak check
58 def leak_check(rss_start, rss_end):
59  if rss_start != rss_end:
60  fodat = " result: memory leak was found !!!"
61  else:
62  fodat = " result: memory leak was not found."
63  print_file_and_cons(fodat)
64  return
65 
66 ## file out setting
67 test_case = "DataPortTest"
68 fout = open(test_case + ".log", 'w')
69 
70 fodat = "=== " + test_case + " start ==="
72 
73 consin_ports = compo0.rtc_ref.get_ports()
74 #print "List consin_ports=%d" % len(consin_ports)
75 consout_ports = compo1.rtc_ref.get_ports()
76 #print "List consout_ports=%d" % len(consout_ports)
77 
78 loop_cnt = 1000
79 ##--------------------------------------------------------------------
80 # dataflow_type: push
81 
82 # Connector Porfile: corba_cdr, push, flush <<< In -> Out
83 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"))])
84 
85 # Connector Porfile: corba_cdr, push, flush <<< Out -> In
86 #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"))])
87 
88 ##--------------------------------------------------------------------
89 # Connector Porfile: corba_cdr, push, new <<< In -> Out
90 #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"))])
91 
92 # Connector Porfile: corba_cdr, push, new <<< Out -> In
93 #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"))])
94 
95 ##--------------------------------------------------------------------
96 # Connector Porfile: corba_cdr, push, periodic <<< In -> Out
97 #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"))])
98 
99 # Connector Porfile: corba_cdr, push, periodic <<< Out -> In
100 #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"))])
101 
102 ##--------------------------------------------------------------------
103 #print "ConnectorProfile=\n",conprof
104 
105 ##--------------------------------------------------------------------
106 # dataflow_type: pull
107 # Connector Porfile: corba_cdr, pull, flush <<< Out -> In
108 conprof2 = 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("pull")),SDOPackage.NameValue("dataport.subscription_type",any.to_any("flush"))])
109 
110 #print "ConnectorProfile2=\n",conprof2
111 
112 #ec1 = compo0.rtc_ref.get_owned_contexts()
113 #ec2 = compo1.rtc_ref.get_owned_contexts()
114 #ec1[0].activate_component(compo0.rtc_ref)
115 #ec2[0].activate_component(compo1.rtc_ref)
116 
117 ## -----------------------------------------------------------------------------
118 fodat = "put()"
119 print_file_and_cons(fodat)
120 
121 for i in range(loop_cnt):
122  # DataflowType:push接続
123  # InportCdr::put(in CdrData data)
124  ret0,conprof0 = consin_ports[0].connect(conprof)
125  # print " connect() ret=",ret0
126  if ret0 != RTC.RTC_OK:
127  fodat = " connect() error ret=" + str(ret0)
128  print_file_and_cons(fodat)
129  # print " conprof0.properties=",conprof0.properties
130  # print " prop[0]=",conprof0.properties[0].value #corba_cdr
131  # print " prop[1]=",conprof0.properties[1].value #push
132  # print " prop[2]=",conprof0.properties[2].value #flush,new,periodic
133  # print " prop[3]=",conprof0.properties[3].value #little,big
134  # print " prop[4]=",conprof0.properties[4].value #IOR:
135  # print " prop[5]=",conprof0.properties[5].value #InportCdr
136  ior = any.from_any(conprof0.properties[4].value, keep_structs=True)
137  # print " ior=",ior
138  inportobj = env.orb.string_to_object(ior)
139  inportcdr = inportobj._narrow(OpenRTM.InPortCdr)
140  data = RTC.TimedLong(RTC.Time(0,0),12345)
141  data0 = cdrMarshal(any.to_any(data).typecode(), data, 1)
142  ret1 = inportcdr.put(data0)
143  # print " put() ret=" + str(ret1)
144  #if ret1 != OpenRTM.PORT_OK:
145  # if ret1 == OpenRTM.BUFFER_FULL: #9件目からBUFFER_FULLになる # fodat = " put() ret=BUFFER_FULL count=%d" % (i+1) # print_file_and_cons(fodat) # else: # fodat = " put() ret=" + str(ret1) + " count=%d" % (i+1) # print_file_and_cons(fodat) time.sleep(0.1) ret2 = consin_ports[0].disconnect(conprof.connector_id) # set used #if ret2 != RTC.RTC_OK: # fodat = " disconnect() error ret=" + str(ret2) # print_file_and_cons(fodat) if i == 0: rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0 fodat = " %05d: %s KB start" % (1, rss0) print_file_and_cons(fodat,1) rss1 = mem_rss() ; j1 = i if rss0 != rss1: fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) ) print_file_and_cons(fodat,1) rss0 = rss1 ; j0 = j1 rssEnd = mem_rss() fodat = " %05d: %s KB end" % (i+1, rssEnd) print_file_and_cons(fodat,1) leak_check(rssStart, rssEnd) ## ----------------------------------------------------------------------------- fodat = "get()" print_file_and_cons(fodat) for i in range(loop_cnt): # DataflowType:pull接続 # OutportCdr::get(out CdrData data) ret10,conprof10 = consout_ports[0].connect(conprof2) # print " connect() ret=",ret10 if ret10 != RTC.RTC_OK: fodat = " connect() error ret=" + str(ret10) print_file_and_cons(fodat) # print " conprof10.properties=",conprof10.properties # print " prop[0]=",conprof10.properties[0].value #corba_cdr # print " prop[1]=",conprof10.properties[1].value #pull # print " prop[2]=",conprof10.properties[2].value #flush,new,periodic # print " prop[3]=",conprof10.properties[3].value #little,big # print " prop[4]=",conprof10.properties[4].value #IOR: # print " prop[5]=",conprof10.properties[5].value #OutportCdr ior10 = any.from_any(conprof10.properties[4].value, keep_structs=True) # print " ior10=",ior10 outportobj = env.orb.string_to_object(ior10) outportcdr = outportobj._narrow(OpenRTM.OutPortCdr) # data set ret11,data1 = outportcdr.get() # print " get() ret=" + str(ret11) # BUFFER_EMPTY #if ret11 != OpenRTM.PORT_OK: # fodat = " get() ret=" + str(ret11) + " count=%d" % (i+1) # print_file_and_cons(fodat) #else: # value12 = cdrUnmarshal(any.to_any(123).typecode(),data1[0],1) # #print " data1=",value12 time.sleep(0.1) ret12 = consin_ports[0].disconnect(conprof2.connector_id) # set used #if ret12 != RTC.RTC_OK: # fodat = " disconnect() error ret=" + str(ret12) # print_file_and_cons(fodat) if i == 0: rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0 fodat = " %05d: %s KB start" % (1, rss0) print_file_and_cons(fodat,1) rss1 = mem_rss() ; j1 = i if rss0 != rss1: fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) ) print_file_and_cons(fodat,1) rss0 = rss1 ; j0 = j1 rssEnd = mem_rss() fodat = " %05d: %s KB end" % (i+1, rssEnd) print_file_and_cons(fodat,1) leak_check(rssStart, rssEnd) ## ----------------------------------------------------------------------------- #ec2[0].deactivate_component(compo1.rtc_ref) #ec1[0].deactivate_component(compo0.rtc_ref) fodat = "=== " + test_case + " end ===" print_file_and_cons(fodat) fout.close()
146  # fodat = " put() ret=BUFFER_FULL count=%d" % (i+1)
147  # print_file_and_cons(fodat)
148  # else:
149  # fodat = " put() ret=" + str(ret1) + " count=%d" % (i+1)
150  # print_file_and_cons(fodat)
151  time.sleep(0.1)
152  ret2 = consin_ports[0].disconnect(conprof.connector_id) # set used
153  #if ret2 != RTC.RTC_OK:
154  # fodat = " disconnect() error ret=" + str(ret2)
155  # print_file_and_cons(fodat)
156 
157  if i == 0:
158  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
159  fodat = " %05d: %s KB start" % (1, rss0)
160  print_file_and_cons(fodat,1)
161  rss1 = mem_rss() ; j1 = i
162  if rss0 != rss1:
163  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
164  print_file_and_cons(fodat,1)
165  rss0 = rss1 ; j0 = j1
166 
167 rssEnd = mem_rss()
168 fodat = " %05d: %s KB end" % (i+1, rssEnd)
169 print_file_and_cons(fodat,1)
170 leak_check(rssStart, rssEnd)
171 ## -----------------------------------------------------------------------------
172 fodat = "get()"
173 print_file_and_cons(fodat)
174 
175 for i in range(loop_cnt):
176  # DataflowType:pull接続
177  # OutportCdr::get(out CdrData data)
178  ret10,conprof10 = consout_ports[0].connect(conprof2)
179  # print " connect() ret=",ret10
180  if ret10 != RTC.RTC_OK:
181  fodat = " connect() error ret=" + str(ret10)
182  print_file_and_cons(fodat)
183  # print " conprof10.properties=",conprof10.properties
184  # print " prop[0]=",conprof10.properties[0].value #corba_cdr
185  # print " prop[1]=",conprof10.properties[1].value #pull
186  # print " prop[2]=",conprof10.properties[2].value #flush,new,periodic
187  # print " prop[3]=",conprof10.properties[3].value #little,big
188  # print " prop[4]=",conprof10.properties[4].value #IOR:
189  # print " prop[5]=",conprof10.properties[5].value #OutportCdr
190  ior10 = any.from_any(conprof10.properties[4].value, keep_structs=True)
191  # print " ior10=",ior10
192 
193  outportobj = env.orb.string_to_object(ior10)
194  outportcdr = outportobj._narrow(OpenRTM.OutPortCdr)
195  # data set
196 
197  ret11,data1 = outportcdr.get()
198  # print " get() ret=" + str(ret11) # BUFFER_EMPTY
199  #if ret11 != OpenRTM.PORT_OK:
200  # fodat = " get() ret=" + str(ret11) + " count=%d" % (i+1)
201  # print_file_and_cons(fodat)
202  #else:
203  # value12 = cdrUnmarshal(any.to_any(123).typecode(),data1[0],1)
204  # #print " data1=",value12
205  time.sleep(0.1)
206  ret12 = consin_ports[0].disconnect(conprof2.connector_id) # set used
207  #if ret12 != RTC.RTC_OK:
208  # fodat = " disconnect() error ret=" + str(ret12)
209  # print_file_and_cons(fodat)
210 
211  if i == 0:
212  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
213  fodat = " %05d: %s KB start" % (1, rss0)
214  print_file_and_cons(fodat,1)
215  rss1 = mem_rss() ; j1 = i
216  if rss0 != rss1:
217  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
218  print_file_and_cons(fodat,1)
219  rss0 = rss1 ; j0 = j1
220 
221 rssEnd = mem_rss()
222 fodat = " %05d: %s KB end" % (i+1, rssEnd)
223 print_file_and_cons(fodat,1)
224 leak_check(rssStart, rssEnd)
225 ## -----------------------------------------------------------------------------
226 #ec2[0].deactivate_component(compo1.rtc_ref)
227 #ec1[0].deactivate_component(compo0.rtc_ref)
228 
229 fodat = "=== " + test_case + " end ==="
230 print_file_and_cons(fodat)
231 fout.close()
def leak_check(rss_start, rss_end)
memory leak check
Definition: DataPortTest.py:58
def print_file_and_cons(out_data, out_flag=0)
file and console out
Definition: DataPortTest.py:42


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