Go to the documentation of this file.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 env = RtmEnv(sys.argv, ["localhost:9898"])
00022
00023 mgr_name=socket.gethostname()+".host_cxt/manager.mgr"
00024 naming = CorbaNaming(env.orb,"localhost:9898")
00025 manager = naming.resolve(mgr_name)._narrow(RTM.Manager)
00026
00027 time.sleep(2)
00028
00029 def mem_rss():
00030 (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
00031 return output.split()[7]
00032
00033
00034 def print_file_and_cons(out_data, out_flag=0):
00035
00036 if out_flag == 1:
00037 fout.write(out_data + '\n')
00038 fout.flush()
00039
00040 elif out_flag == 2:
00041 print out_data
00042
00043 else:
00044 print out_data
00045 fout.write(out_data + '\n')
00046 fout.flush()
00047 return
00048
00049
00050 def leak_check(rss_start, rss_end):
00051 if rss_start != rss_end:
00052 fodat = " result: memory leak was found !!!"
00053 else:
00054 fodat = " result: memory leak was not found."
00055 print_file_and_cons(fodat)
00056 return
00057
00058
00059 test_case = "CreateDeleteRTCTest"
00060 fout = open(test_case + ".log", 'w')
00061
00062 fodat = "=== " + test_case + " start ==="
00063 print_file_and_cons(fodat)
00064
00065 loop_cnt = 1000
00066
00067 fodat = "load_module() and unload_module()"
00068 print_file_and_cons(fodat)
00069
00070 for i in range(loop_cnt):
00071
00072 try:
00073
00074 retcode = manager.unload_module(".//ConsoleOut.so")
00075 except:
00076 pass
00077
00078
00079
00080
00081 retcode = manager.load_module("ConsoleOut.so", "ConsoleOutInit")
00082
00083
00084 if i == 0:
00085 rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00086 fodat = " %05d: %s KB start" % (1, rss0)
00087 print_file_and_cons(fodat,1)
00088 rss1 = mem_rss() ; j1 = i
00089 if rss0 != rss1:
00090 fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00091 print_file_and_cons(fodat,1)
00092 rss0 = rss1 ; j0 = j1
00093
00094 rssEnd = mem_rss()
00095 fodat = " %05d: %s KB end" % (i+1, rssEnd)
00096 print_file_and_cons(fodat,1)
00097 leak_check(rssStart, rssEnd)
00098
00099 fodat = "create_component() and delete_component()"
00100 print_file_and_cons(fodat)
00101
00102 for i in range(loop_cnt):
00103
00104 ret0 = manager.delete_component("ConsoleOut0")
00105
00106
00107
00108
00109 obj0 = manager.create_component("ConsoleOut")
00110
00111
00112
00113 if i == 0:
00114 rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00115 fodat = " %05d: %s KB start" % (1, rss0)
00116 print_file_and_cons(fodat,1)
00117 rss1 = mem_rss() ; j1 = i
00118 if rss0 != rss1:
00119 fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00120 print_file_and_cons(fodat,1)
00121 rss0 = rss1 ; j0 = j1
00122
00123 rssEnd = mem_rss()
00124 fodat = " %05d: %s KB end" % (i+1, rssEnd)
00125 print_file_and_cons(fodat,1)
00126 leak_check(rssStart, rssEnd)
00127
00128
00129 fodat = "=== " + test_case + " end ==="
00130 print_file_and_cons(fodat)
00131 fout.close()
00132
00133 manager.delete_component("ConsoleOut0")
00134
00135