00001 #!/usr/bin/env python 00002 # -*- coding: euc-jp -*- 00003 # 00004 ## DataPortTest.py 00005 ## 00006 ## メモリーリークチェック 00007 ## DataPort.idlで定義されているオペレーション 00008 ## データポートに関するオペレーション 00009 # 00010 # $Id: DataPortTest.py 1971 2010-06-03 08:46:40Z n-ando $ 00011 # 00012 00013 from rtc_handle import * 00014 from BasicDataType_idl import * 00015 import time 00016 import commands 00017 import SDOPackage 00018 from omniORB import * 00019 from omniORB import any 00020 from omniORB import CORBA 00021 import OpenRTM 00022 00023 env = RtmEnv(sys.argv, ["localhost:9898"]) 00024 list0 = env.name_space["localhost:9898"].list_obj() 00025 env.name_space['localhost:9898'].rtc_handles.keys() 00026 00027 time.sleep(2) 00028 00029 ns = env.name_space['localhost:9898'] 00030 00031 compo0 = ns.rtc_handles["ConsoleIn0.rtc"] 00032 compo1 = ns.rtc_handles["ConsoleOut0.rtc"] 00033 00034 #compo0 = ns.rtc_handles["SequenceInComponent0.rtc"] 00035 #compo1 = ns.rtc_handles["SequenceOutComponent0.rtc"] 00036 00037 def mem_rss(): 00038 (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd") 00039 return output.split()[7] 00040 00041 ## file and console out 00042 def print_file_and_cons(out_data, out_flag=0): 00043 ## out_flag:1 is file out only 00044 if out_flag == 1: 00045 fout.write(out_data + '\n') 00046 fout.flush() 00047 ## out_flag:2 is console out only 00048 elif out_flag == 2: 00049 print out_data 00050 ## out_flag:0 is console and file out (default) 00051 else: 00052 print out_data 00053 fout.write(out_data + '\n') 00054 fout.flush() 00055 return 00056 00057 ## memory leak check 00058 def leak_check(rss_start, rss_end): 00059 if rss_start != rss_end: 00060 fodat = " result: memory leak was found !!!" 00061 else: 00062 fodat = " result: memory leak was not found." 00063 print_file_and_cons(fodat) 00064 return 00065 00066 ## file out setting 00067 test_case = "DataPortTest" 00068 fout = open(test_case + ".log", 'w') 00069 00070 fodat = "=== " + test_case + " start ===" 00071 print_file_and_cons(fodat) 00072 00073 consin_ports = compo0.rtc_ref.get_ports() 00074 #print "List consin_ports=%d" % len(consin_ports) 00075 consout_ports = compo1.rtc_ref.get_ports() 00076 #print "List consout_ports=%d" % len(consout_ports) 00077 00078 loop_cnt = 1000 00079 ##-------------------------------------------------------------------- 00080 # dataflow_type: push 00081 00082 # Connector Porfile: corba_cdr, push, flush <<< In -> Out 00083 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"))]) 00084 00085 # Connector Porfile: corba_cdr, push, flush <<< Out -> In 00086 #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"))]) 00087 00088 ##-------------------------------------------------------------------- 00089 # Connector Porfile: corba_cdr, push, new <<< In -> Out 00090 #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"))]) 00091 00092 # Connector Porfile: corba_cdr, push, new <<< Out -> In 00093 #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"))]) 00094 00095 ##-------------------------------------------------------------------- 00096 # Connector Porfile: corba_cdr, push, periodic <<< In -> Out 00097 #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"))]) 00098 00099 # Connector Porfile: corba_cdr, push, periodic <<< Out -> In 00100 #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"))]) 00101 00102 ##-------------------------------------------------------------------- 00103 #print "ConnectorProfile=\n",conprof 00104 00105 ##-------------------------------------------------------------------- 00106 # dataflow_type: pull 00107 # Connector Porfile: corba_cdr, pull, flush <<< Out -> In 00108 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"))]) 00109 00110 #print "ConnectorProfile2=\n",conprof2 00111 00112 #ec1 = compo0.rtc_ref.get_owned_contexts() 00113 #ec2 = compo1.rtc_ref.get_owned_contexts() 00114 #ec1[0].activate_component(compo0.rtc_ref) 00115 #ec2[0].activate_component(compo1.rtc_ref) 00116 00117 ## ----------------------------------------------------------------------------- 00118 fodat = "put()" 00119 print_file_and_cons(fodat) 00120 00121 for i in range(loop_cnt): 00122 # DataflowType:push接続 00123 # InportCdr::put(in CdrData data) 00124 ret0,conprof0 = consin_ports[0].connect(conprof) 00125 # print " connect() ret=",ret0 00126 if ret0 != RTC.RTC_OK: 00127 fodat = " connect() error ret=" + str(ret0) 00128 print_file_and_cons(fodat) 00129 # print " conprof0.properties=",conprof0.properties 00130 # print " prop[0]=",conprof0.properties[0].value #corba_cdr 00131 # print " prop[1]=",conprof0.properties[1].value #push 00132 # print " prop[2]=",conprof0.properties[2].value #flush,new,periodic 00133 # print " prop[3]=",conprof0.properties[3].value #little,big 00134 # print " prop[4]=",conprof0.properties[4].value #IOR: 00135 # print " prop[5]=",conprof0.properties[5].value #InportCdr 00136 ior = any.from_any(conprof0.properties[4].value, keep_structs=True) 00137 # print " ior=",ior 00138 inportobj = env.orb.string_to_object(ior) 00139 inportcdr = inportobj._narrow(OpenRTM.InPortCdr) 00140 data = RTC.TimedLong(RTC.Time(0,0),12345) 00141 data0 = cdrMarshal(any.to_any(data).typecode(), data, 1) 00142 ret1 = inportcdr.put(data0) 00143 # print " put() ret=" + str(ret1) 00144 #if ret1 != OpenRTM.PORT_OK: 00145 # if ret1 == OpenRTM.BUFFER_FULL: #9件目からBUFFER_FULLになる 00146 # fodat = " put() ret=BUFFER_FULL count=%d" % (i+1) 00147 # print_file_and_cons(fodat) 00148 # else: 00149 # fodat = " put() ret=" + str(ret1) + " count=%d" % (i+1) 00150 # print_file_and_cons(fodat) 00151 time.sleep(0.1) 00152 ret2 = consin_ports[0].disconnect(conprof.connector_id) # set used 00153 #if ret2 != RTC.RTC_OK: 00154 # fodat = " disconnect() error ret=" + str(ret2) 00155 # print_file_and_cons(fodat) 00156 00157 if i == 0: 00158 rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0 00159 fodat = " %05d: %s KB start" % (1, rss0) 00160 print_file_and_cons(fodat,1) 00161 rss1 = mem_rss() ; j1 = i 00162 if rss0 != rss1: 00163 fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) ) 00164 print_file_and_cons(fodat,1) 00165 rss0 = rss1 ; j0 = j1 00166 00167 rssEnd = mem_rss() 00168 fodat = " %05d: %s KB end" % (i+1, rssEnd) 00169 print_file_and_cons(fodat,1) 00170 leak_check(rssStart, rssEnd) 00171 ## ----------------------------------------------------------------------------- 00172 fodat = "get()" 00173 print_file_and_cons(fodat) 00174 00175 for i in range(loop_cnt): 00176 # DataflowType:pull接続 00177 # OutportCdr::get(out CdrData data) 00178 ret10,conprof10 = consout_ports[0].connect(conprof2) 00179 # print " connect() ret=",ret10 00180 if ret10 != RTC.RTC_OK: 00181 fodat = " connect() error ret=" + str(ret10) 00182 print_file_and_cons(fodat) 00183 # print " conprof10.properties=",conprof10.properties 00184 # print " prop[0]=",conprof10.properties[0].value #corba_cdr 00185 # print " prop[1]=",conprof10.properties[1].value #pull 00186 # print " prop[2]=",conprof10.properties[2].value #flush,new,periodic 00187 # print " prop[3]=",conprof10.properties[3].value #little,big 00188 # print " prop[4]=",conprof10.properties[4].value #IOR: 00189 # print " prop[5]=",conprof10.properties[5].value #OutportCdr 00190 ior10 = any.from_any(conprof10.properties[4].value, keep_structs=True) 00191 # print " ior10=",ior10 00192 00193 outportobj = env.orb.string_to_object(ior10) 00194 outportcdr = outportobj._narrow(OpenRTM.OutPortCdr) 00195 # data set 00196 00197 ret11,data1 = outportcdr.get() 00198 # print " get() ret=" + str(ret11) # BUFFER_EMPTY 00199 #if ret11 != OpenRTM.PORT_OK: 00200 # fodat = " get() ret=" + str(ret11) + " count=%d" % (i+1) 00201 # print_file_and_cons(fodat) 00202 #else: 00203 # value12 = cdrUnmarshal(any.to_any(123).typecode(),data1[0],1) 00204 # #print " data1=",value12 00205 time.sleep(0.1) 00206 ret12 = consin_ports[0].disconnect(conprof2.connector_id) # set used 00207 #if ret12 != RTC.RTC_OK: 00208 # fodat = " disconnect() error ret=" + str(ret12) 00209 # print_file_and_cons(fodat) 00210 00211 if i == 0: 00212 rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0 00213 fodat = " %05d: %s KB start" % (1, rss0) 00214 print_file_and_cons(fodat,1) 00215 rss1 = mem_rss() ; j1 = i 00216 if rss0 != rss1: 00217 fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) ) 00218 print_file_and_cons(fodat,1) 00219 rss0 = rss1 ; j0 = j1 00220 00221 rssEnd = mem_rss() 00222 fodat = " %05d: %s KB end" % (i+1, rssEnd) 00223 print_file_and_cons(fodat,1) 00224 leak_check(rssStart, rssEnd) 00225 ## ----------------------------------------------------------------------------- 00226 #ec2[0].deactivate_component(compo1.rtc_ref) 00227 #ec1[0].deactivate_component(compo0.rtc_ref) 00228 00229 fodat = "=== " + test_case + " end ===" 00230 print_file_and_cons(fodat) 00231 fout.close()