00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 from rtc_handle import *
00014 from BasicDataType_idl import *
00015 from CorbaNaming import *
00016 import time
00017 import commands
00018 import socket
00019 import RTM
00020
00021
00022
00023 env = RtmEnv(sys.argv, ["localhost:9898"])
00024 mgr_name=socket.gethostname()+".host_cxt/manager.mgr"
00025 naming = CorbaNaming(env.orb,"localhost:9898")
00026 manager = naming.resolve(mgr_name)._narrow(RTM.Manager)
00027
00028 time.sleep(2)
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 = "ManagerTest"
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 fodat = "get_loadable_modules()"
00069 print_file_and_cons(fodat)
00070
00071 for i in range(loop_cnt):
00072
00073 manager.get_loadable_modules()
00074
00075 if i == 0:
00076 rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00077 fodat = " %05d: %s KB start" % (1, rss0)
00078 print_file_and_cons(fodat,1)
00079 rss1 = mem_rss() ; j1 = i
00080 if rss0 != rss1:
00081 fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00082 print_file_and_cons(fodat,1)
00083 rss0 = rss1 ; j0 = j1
00084
00085 rssEnd = mem_rss()
00086 fodat = " %05d: %s KB end" % (i+1, rssEnd)
00087 print_file_and_cons(fodat,1)
00088 leak_check(rssStart, rssEnd)
00089
00090 fodat = "get_loaded_modules()"
00091 print_file_and_cons(fodat)
00092
00093 for i in range(loop_cnt):
00094
00095 manager.get_loaded_modules()
00096
00097 if i == 0:
00098 rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00099 fodat = " %05d: %s KB start" % (1, rss0)
00100 print_file_and_cons(fodat,1)
00101 rss1 = mem_rss() ; j1 = i
00102 if rss0 != rss1:
00103 fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00104 print_file_and_cons(fodat,1)
00105 rss0 = rss1 ; j0 = j1
00106
00107 rssEnd = mem_rss()
00108 fodat = " %05d: %s KB end" % (i+1, rssEnd)
00109 print_file_and_cons(fodat,1)
00110 leak_check(rssStart, rssEnd)
00111
00112 fodat = "get_factory_profiles()"
00113 print_file_and_cons(fodat)
00114
00115 for i in range(loop_cnt):
00116
00117 manager.get_factory_profiles()
00118
00119 if i == 0:
00120 rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00121 fodat = " %05d: %s KB start" % (1, rss0)
00122 print_file_and_cons(fodat,1)
00123 rss1 = mem_rss() ; j1 = i
00124 if rss0 != rss1:
00125 fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00126 print_file_and_cons(fodat,1)
00127 rss0 = rss1 ; j0 = j1
00128
00129 rssEnd = mem_rss()
00130 fodat = " %05d: %s KB end" % (i+1, rssEnd)
00131 print_file_and_cons(fodat,1)
00132 leak_check(rssStart, rssEnd)
00133
00134 fodat = "get_components()"
00135 print_file_and_cons(fodat)
00136
00137 for i in range(loop_cnt):
00138
00139 manager.get_components()
00140
00141 if i == 0:
00142 rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00143 fodat = " %05d: %s KB start" % (1, rss0)
00144 print_file_and_cons(fodat,1)
00145 rss1 = mem_rss() ; j1 = i
00146 if rss0 != rss1:
00147 fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00148 print_file_and_cons(fodat,1)
00149 rss0 = rss1 ; j0 = j1
00150
00151 rssEnd = mem_rss()
00152 fodat = " %05d: %s KB end" % (i+1, rssEnd)
00153 print_file_and_cons(fodat,1)
00154 leak_check(rssStart, rssEnd)
00155
00156 fodat = "get_component_profiles()"
00157 print_file_and_cons(fodat)
00158
00159 for i in range(loop_cnt):
00160
00161 manager.get_component_profiles()
00162
00163 if i == 0:
00164 rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00165 fodat = " %05d: %s KB start" % (1, rss0)
00166 print_file_and_cons(fodat,1)
00167 rss1 = mem_rss() ; j1 = i
00168 if rss0 != rss1:
00169 fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00170 print_file_and_cons(fodat,1)
00171 rss0 = rss1 ; j0 = j1
00172
00173 rssEnd = mem_rss()
00174 fodat = " %05d: %s KB end" % (i+1, rssEnd)
00175 print_file_and_cons(fodat,1)
00176 leak_check(rssStart, rssEnd)
00177
00178 fodat = "get_profile()"
00179 print_file_and_cons(fodat)
00180
00181 for i in range(loop_cnt):
00182
00183 manager.get_profile()
00184
00185 if i == 0:
00186 rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00187 fodat = " %05d: %s KB start" % (1, rss0)
00188 print_file_and_cons(fodat,1)
00189 rss1 = mem_rss() ; j1 = i
00190 if rss0 != rss1:
00191 fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00192 print_file_and_cons(fodat,1)
00193 rss0 = rss1 ; j0 = j1
00194
00195 rssEnd = mem_rss()
00196 fodat = " %05d: %s KB end" % (i+1, rssEnd)
00197 print_file_and_cons(fodat,1)
00198 leak_check(rssStart, rssEnd)
00199
00200 fodat = "get_configuration()"
00201 print_file_and_cons(fodat)
00202
00203 for i in range(loop_cnt):
00204
00205 manager.get_configuration()
00206
00207 if i == 0:
00208 rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00209 fodat = " %05d: %s KB start" % (1, rss0)
00210 print_file_and_cons(fodat,1)
00211 rss1 = mem_rss() ; j1 = i
00212 if rss0 != rss1:
00213 fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00214 print_file_and_cons(fodat,1)
00215 rss0 = rss1 ; j0 = j1
00216
00217 rssEnd = mem_rss()
00218 fodat = " %05d: %s KB end" % (i+1, rssEnd)
00219 print_file_and_cons(fodat,1)
00220 leak_check(rssStart, rssEnd)
00221
00222 fodat = "set_configuration()"
00223 print_file_and_cons(fodat)
00224
00225 for i in range(loop_cnt):
00226
00227 manager.set_configuration("module.load_path", "./")
00228
00229 if i == 0:
00230 rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00231 fodat = " %05d: %s KB start" % (1, rss0)
00232 print_file_and_cons(fodat,1)
00233 rss1 = mem_rss() ; j1 = i
00234 if rss0 != rss1:
00235 fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00236 print_file_and_cons(fodat,1)
00237 rss0 = rss1 ; j0 = j1
00238
00239 rssEnd = mem_rss()
00240 fodat = " %05d: %s KB end" % (i+1, rssEnd)
00241 print_file_and_cons(fodat,1)
00242 leak_check(rssStart, rssEnd)
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 fodat = "fork()"
00333 print_file_and_cons(fodat)
00334
00335 for i in range(loop_cnt):
00336
00337 manager.fork()
00338
00339 if i == 0:
00340 rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00341 fodat = " %05d: %s KB start" % (1, rss0)
00342 print_file_and_cons(fodat,1)
00343 rss1 = mem_rss() ; j1 = i
00344 if rss0 != rss1:
00345 fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00346 print_file_and_cons(fodat,1)
00347 rss0 = rss1 ; j0 = j1
00348
00349 rssEnd = mem_rss()
00350 fodat = " %05d: %s KB end" % (i+1, rssEnd)
00351 print_file_and_cons(fodat,1)
00352 leak_check(rssStart, rssEnd)
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376 fodat = "restart()"
00377 print_file_and_cons(fodat)
00378
00379 for i in range(loop_cnt):
00380
00381 manager.restart()
00382
00383 if i == 0:
00384 rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00385 fodat = " %05d: %s KB start" % (1, rss0)
00386 print_file_and_cons(fodat,1)
00387 rss1 = mem_rss() ; j1 = i
00388 if rss0 != rss1:
00389 fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00390 print_file_and_cons(fodat,1)
00391 rss0 = rss1 ; j0 = j1
00392
00393 rssEnd = mem_rss()
00394 fodat = " %05d: %s KB end" % (i+1, rssEnd)
00395 print_file_and_cons(fodat,1)
00396 leak_check(rssStart, rssEnd)
00397
00398 fodat = "get_service()"
00399 print_file_and_cons(fodat)
00400
00401 for i in range(loop_cnt):
00402
00403 manager.get_service("test")
00404
00405 if i == 0:
00406 rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00407 fodat = " %05d: %s KB start" % (1, rss0)
00408 print_file_and_cons(fodat,1)
00409 rss1 = mem_rss() ; j1 = i
00410 if rss0 != rss1:
00411 fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00412 print_file_and_cons(fodat,1)
00413 rss0 = rss1 ; j0 = j1
00414
00415 rssEnd = mem_rss()
00416 fodat = " %05d: %s KB end" % (i+1, rssEnd)
00417 print_file_and_cons(fodat,1)
00418 leak_check(rssStart, rssEnd)
00419
00420
00421 fodat = "=== " + test_case + " end ==="
00422 print_file_and_cons(fodat)
00423 fout.close()