00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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
00035 def print_file_and_cons(out_data, out_flag=0):
00036
00037 if out_flag == 1:
00038 fout.write(out_data + '\n')
00039 fout.flush()
00040
00041 elif out_flag == 2:
00042 print out_data
00043
00044 else:
00045 print out_data
00046 fout.write(out_data + '\n')
00047 fout.flush()
00048 return
00049
00050
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
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
00070 consout_ports = compo1.rtc_ref.get_ports()
00071
00072
00073
00074
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
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 fodat = "get_ports()"
00099 print_file_and_cons(fodat)
00100
00101 for i in range(loop_cnt):
00102
00103
00104 compo1.rtc_ref.get_ports()
00105
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
00127
00128 consin_ports[0].get_port_profile()
00129
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
00151 ret0 = consin_ports[0].notify_connect(conprof)
00152
00153
00154 ret1 = consin_ports[0].notify_disconnect(conprof.connector_id)
00155
00156
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
00178 consin_ports[0].connect(conprof)
00179 consin_ports[0].get_connector_profiles()
00180 consin_ports[0].disconnect(conprof.connector_id)
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
00202 consin_ports[0].connect(conprof)
00203 consin_ports[0].get_connector_profile(conprof.connector_id)
00204 consin_ports[0].disconnect(conprof.connector_id)
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
00226 ret0 = consin_ports[0].connect(conprof)
00227
00228 ret1 = consin_ports[0].disconnect(conprof.connector_id)
00229
00230
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
00252 ret0 = consin_ports[0].connect(conprof)
00253
00254
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()