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 import time
00016 import commands
00017
00018 env = RtmEnv(sys.argv, ["localhost:9898"])
00019 list0 = env.name_space["localhost:9898"].list_obj()
00020 env.name_space['localhost:9898'].rtc_handles.keys()
00021
00022 ns = env.name_space['localhost:9898']
00023
00024 time.sleep(2)
00025
00026 compo1 = ns.rtc_handles["ConsoleIn0.rtc"]
00027 compo0 = ns.rtc_handles["ConsoleOut0.rtc"]
00028 seqin0 = ns.rtc_handles["SequenceInComponent0.rtc"]
00029
00030 ec = compo0.rtc_ref.get_owned_contexts()
00031
00032 def mem_rss():
00033 (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
00034 return output.split()[7]
00035
00036
00037 def print_file_and_cons(out_data, out_flag=0):
00038
00039 if out_flag == 1:
00040 fout.write(out_data + '\n')
00041 fout.flush()
00042
00043 elif out_flag == 2:
00044 print out_data
00045
00046 else:
00047 print out_data
00048 fout.write(out_data + '\n')
00049 fout.flush()
00050 return
00051
00052
00053 def leak_check(rss_start, rss_end):
00054 if rss_start != rss_end:
00055 fodat = " result: memory leak was found !!!"
00056 else:
00057 fodat = " result: memory leak was not found."
00058 print_file_and_cons(fodat)
00059 return
00060
00061
00062 test_case = "AttachDetachRTCTest"
00063 fout = open(test_case + ".log", 'w')
00064
00065 fodat = "=== " + test_case + " start ==="
00066 print_file_and_cons(fodat)
00067
00068 loop_cnt = 1000
00069
00070 fodat = "attach_context() and detach_context()"
00071 print_file_and_cons(fodat)
00072
00073 for i in range(loop_cnt):
00074
00075 ec_id = compo0.rtc_ref.attach_context(ec[0])
00076
00077
00078
00079 retcode = compo0.rtc_ref.detach_context(ec_id)
00080
00081
00082 if i == 0:
00083 rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00084 fodat = " %05d: %s KB start" % (1, rss0)
00085 print_file_and_cons(fodat,1)
00086 rss1 = mem_rss() ; j1 = i
00087 if rss0 != rss1:
00088 fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00089 print_file_and_cons(fodat,1)
00090 rss0 = rss1 ; j0 = j1
00091
00092 rssEnd = mem_rss()
00093 fodat = " %05d: %s KB end" % (i+1, rssEnd)
00094 print_file_and_cons(fodat,1)
00095 leak_check(rssStart, rssEnd)
00096
00097
00098 fodat = "=== " + test_case + " end ==="
00099 print_file_and_cons(fodat)
00100 fout.close()