ConnectRTCTest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 #
00004 ## ConnectRTCTest.py
00005 ##
00006 ## メモリーリークチェック
00007 ## RTC.idlで定義されているオペレーション
00008 ## ポートに関するオペレーション
00009 #
00010 # $Id: ConnectRTCTest.py 1541 2009-08-31 07:21:12Z hakuta $
00011 #
00012 
00013 from rtc_handle import *
00014 from BasicDataType_idl import *
00015 import time
00016 import commands
00017 import SDOPackage
00018 
00019 env = RtmEnv(sys.argv, ["localhost:9898"])
00020 list0 = env.name_space["localhost:9898"].list_obj()
00021 env.name_space['localhost:9898'].rtc_handles.keys()
00022 
00023 time.sleep(2)
00024 
00025 ns = env.name_space['localhost:9898']
00026 
00027 compo0 = ns.rtc_handles["ConsoleIn0.rtc"]
00028 compo1 = ns.rtc_handles["ConsoleOut0.rtc"]
00029 
00030 def mem_rss():
00031     (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
00032     return output.split()[7]
00033 
00034 ## file and console out
00035 def print_file_and_cons(out_data, out_flag=0):
00036     ## out_flag:1 is file out only
00037     if out_flag == 1:
00038       fout.write(out_data + '\n')
00039       fout.flush()
00040     ## out_flag:2 is console out only
00041     elif out_flag == 2:
00042       print out_data
00043     ## out_flag:0 is console and file out (default)
00044     else:
00045       print out_data
00046       fout.write(out_data + '\n')
00047       fout.flush()
00048     return
00049 
00050 ## memory leak check
00051 def leak_check(rss_start, rss_end):
00052     if rss_start != rss_end:
00053         fodat = "  result: memory leak was found !!!"
00054     else:
00055         fodat = "  result: memory leak was not found."
00056     print_file_and_cons(fodat)
00057     return
00058 
00059 ## file out setting
00060 test_case = "ConnectRTCTest"
00061 fout = open(test_case + ".log", 'w')
00062 
00063 fodat = "=== " + test_case + " start ==="
00064 print_file_and_cons(fodat)
00065 
00066 loop_cnt = 1000
00067 ## -----------------------------------------------------------------------------
00068 consin_ports = compo0.rtc_ref.get_ports()
00069 #print "List consin_ports=%d" % len(consin_ports)
00070 consout_ports = compo1.rtc_ref.get_ports()
00071 #print "List consout_ports=%d" % len(consout_ports)
00072 
00073 ##--------------------------------------------------------------------
00074 # Connector Porfile: corba_cdr, push, flush <<<  In -> Out
00075 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"))])
00076 
00077 # Connector Porfile: corba_cdr, push, flush <<<  Out -> In
00078 #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"))])
00079 
00080 ##--------------------------------------------------------------------
00081 # Connector Porfile: corba_cdr, push, new <<<  In -> Out
00082 #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"))])
00083 
00084 # Connector Porfile: corba_cdr, push, new <<<  Out -> In
00085 #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"))])
00086 
00087 ##--------------------------------------------------------------------
00088 # Connector Porfile: corba_cdr, push, periodic <<<  In -> Out
00089 #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")),SDOPackage.NameValue("dataport.publisher.push_rate",any.to_any(2000))])
00090 
00091 # Connector Porfile: corba_cdr, push, periodic <<<  Out -> In
00092 #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")),SDOPackage.NameValue("dataport.publisher.push_rate",any.to_any(2000))])
00093 
00094 ##--------------------------------------------------------------------
00095 #print "ConnectorProfile=\n",conprof
00096 
00097 ## -----------------------------------------------------------------------------
00098 fodat = "get_ports()"
00099 print_file_and_cons(fodat)
00100 
00101 for i in range(loop_cnt):
00102     # RTObject::get_ports()
00103     #consin_ports[0].connect(conprof)
00104     compo1.rtc_ref.get_ports()
00105     #consin_ports[0].disconnect(conprof.connector_id)   # set used
00106 
00107     if i == 0:
00108         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00109         fodat = "   %05d: %s KB start" % (1, rss0)
00110         print_file_and_cons(fodat,1)
00111     rss1 = mem_rss() ; j1 = i
00112     if rss0 != rss1:
00113         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00114         print_file_and_cons(fodat,1)
00115         rss0 = rss1 ; j0 = j1
00116 
00117 rssEnd = mem_rss()
00118 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00119 print_file_and_cons(fodat,1)
00120 leak_check(rssStart, rssEnd)
00121 ## -----------------------------------------------------------------------------
00122 fodat = "get_port_profile()"
00123 print_file_and_cons(fodat)
00124 
00125 for i in range(loop_cnt):
00126     # PortService::get_port_profile()
00127     #consin_ports[0].connect(conprof)
00128     consin_ports[0].get_port_profile()
00129     #consin_ports[0].disconnect(conprof.connector_id)   # set used
00130 
00131     if i == 0:
00132         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00133         fodat = "   %05d: %s KB start" % (1, rss0)
00134         print_file_and_cons(fodat,1)
00135     rss1 = mem_rss() ; j1 = i
00136     if rss0 != rss1:
00137         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00138         print_file_and_cons(fodat,1)
00139         rss0 = rss1 ; j0 = j1
00140 
00141 rssEnd = mem_rss()
00142 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00143 print_file_and_cons(fodat,1)
00144 leak_check(rssStart, rssEnd)
00145 ## -----------------------------------------------------------------------------
00146 fodat = "notify_connect() and notify_disconnect()"
00147 print_file_and_cons(fodat)
00148 
00149 for i in range(loop_cnt):
00150     # PortService::notify_connect(inout ConnectorProfile connector_profile)
00151     ret0 = consin_ports[0].notify_connect(conprof)
00152     #print "ret0=",ret0
00153     # PortService::notify_disconnect(in UniqueIdentifier connector_id)
00154     ret1 = consin_ports[0].notify_disconnect(conprof.connector_id)    # set used
00155     #if ret1 != RTC.RTC_OK:
00156     #    print "ret1=",ret1
00157 
00158     if i == 0:
00159         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00160         fodat = "   %05d: %s KB start" % (1, rss0)
00161         print_file_and_cons(fodat,1)
00162     rss1 = mem_rss() ; j1 = i
00163     if rss0 != rss1:
00164         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00165         print_file_and_cons(fodat,1)
00166         rss0 = rss1 ; j0 = j1
00167 
00168 rssEnd = mem_rss()
00169 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00170 print_file_and_cons(fodat,1)
00171 leak_check(rssStart, rssEnd)
00172 ## -----------------------------------------------------------------------------
00173 fodat = "get_connector_profiles()"
00174 print_file_and_cons(fodat)
00175 
00176 for i in range(loop_cnt):
00177     # PortService::get_connector_profiles()
00178     consin_ports[0].connect(conprof)
00179     consin_ports[0].get_connector_profiles()
00180     consin_ports[0].disconnect(conprof.connector_id)   # set used
00181 
00182     if i == 0:
00183         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00184         fodat = "   %05d: %s KB start" % (1, rss0)
00185         print_file_and_cons(fodat,1)
00186     rss1 = mem_rss() ; j1 = i
00187     if rss0 != rss1:
00188         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00189         print_file_and_cons(fodat,1)
00190         rss0 = rss1 ; j0 = j1
00191 
00192 rssEnd = mem_rss()
00193 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00194 print_file_and_cons(fodat,1)
00195 leak_check(rssStart, rssEnd)
00196 ## -----------------------------------------------------------------------------
00197 fodat = "get_connector_profile()"
00198 print_file_and_cons(fodat)
00199 
00200 for i in range(loop_cnt):
00201     # PortService::get_connector_profile(in UniqueIdentifier connector_id)
00202     consin_ports[0].connect(conprof)
00203     consin_ports[0].get_connector_profile(conprof.connector_id)
00204     consin_ports[0].disconnect(conprof.connector_id)               # set used
00205 
00206     if i == 0:
00207         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00208         fodat = "   %05d: %s KB start" % (1, rss0)
00209         print_file_and_cons(fodat,1)
00210     rss1 = mem_rss() ; j1 = i
00211     if rss0 != rss1:
00212         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00213         print_file_and_cons(fodat,1)
00214         rss0 = rss1 ; j0 = j1
00215 
00216 rssEnd = mem_rss()
00217 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00218 print_file_and_cons(fodat,1)
00219 leak_check(rssStart, rssEnd)
00220 ## -----------------------------------------------------------------------------
00221 fodat = "connect() and disconnect()"
00222 print_file_and_cons(fodat)
00223 
00224 for i in range(loop_cnt):
00225     # PortService::connect(inout ConnectorProfile connector_profile)
00226     ret0 = consin_ports[0].connect(conprof)
00227     #print "ret0=",ret0
00228     ret1 = consin_ports[0].disconnect(conprof.connector_id)    # set used
00229     #if ret1 != RTC.RTC_OK:
00230     #    print "ret1=",ret1
00231 
00232     if i == 0:
00233         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00234         fodat = "   %05d: %s KB start" % (1, rss0)
00235         print_file_and_cons(fodat,1)
00236     rss1 = mem_rss() ; j1 = i
00237     if rss0 != rss1:
00238         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00239         print_file_and_cons(fodat,1)
00240         rss0 = rss1 ; j0 = j1
00241 
00242 rssEnd = mem_rss()
00243 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00244 print_file_and_cons(fodat,1)
00245 leak_check(rssStart, rssEnd)
00246 ## -----------------------------------------------------------------------------
00247 fodat = "connect() and disconnect_all()"
00248 print_file_and_cons(fodat)
00249 
00250 for i in range(loop_cnt):
00251     # PortService::connect(inout ConnectorProfile connector_profile)
00252     ret0 = consin_ports[0].connect(conprof)
00253     #print "ret0=",ret0
00254     # PortService::disconnect_all()
00255     consin_ports[0].disconnect_all()
00256 
00257     if i == 0:
00258         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00259         fodat = "   %05d: %s KB start" % (1, rss0)
00260         print_file_and_cons(fodat,1)
00261     rss1 = mem_rss() ; j1 = i
00262     if rss0 != rss1:
00263         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00264         print_file_and_cons(fodat,1)
00265         rss0 = rss1 ; j0 = j1
00266 
00267 rssEnd = mem_rss()
00268 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00269 print_file_and_cons(fodat,1)
00270 leak_check(rssStart, rssEnd)
00271 ## -----------------------------------------------------------------------------
00272 
00273 fodat = "=== " + test_case + " end ==="
00274 print_file_and_cons(fodat)
00275 fout.close()


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:15