SetMemberSDOPackageTest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 #
00004 ## SetMemberSDOPackageTest.py
00005 ##
00006 ## メモリーリークチェック
00007 ## SDOPackage.idlで定義されているオペレーション
00008 ## OrganizationのMemberのセットと取得に関するオペレーション
00009 #
00010 # $Id: SetMemberSDOPackageTest.py 1541 2009-08-31 07:21:12Z hakuta $
00011 #
00012 
00013 from rtc_handle import *
00014 from BasicDataType_idl import *
00015 from omniORB import any
00016 import time
00017 import commands
00018 import SDOPackage
00019 import socket
00020 import RTM
00021 
00022 env = RtmEnv(sys.argv, ["localhost:9898"])
00023 
00024 ## Get Manager object reference
00025 mgr_name = socket.gethostname()+".host_cxt/manager.mgr"
00026 naming = CorbaNaming(env.orb, "localhost:9898")
00027 manager = naming.resolve(mgr_name)._narrow(RTM.Manager)
00028 ## Create Composite RTC
00029 manager.create_component("PeriodicECSharedComposite?instance_name=a&exported_ports=ConsoleIn0.out,ConsoleOut0.in")
00030 
00031 time.sleep(2)
00032 
00033 listo = env.name_space["localhost:9898"].list_obj()
00034 env.name_space['localhost:9898'].rtc_handles.keys()
00035 
00036 
00037 ns = env.name_space['localhost:9898']
00038 
00039 consin0 = ns.rtc_handles["ConsoleIn0.rtc"]
00040 consout0 = ns.rtc_handles["ConsoleOut0.rtc"]
00041 seqin0 = ns.rtc_handles["SequenceInComponent0.rtc"]
00042 a0 = ns.rtc_handles["a.rtc"]
00043 org = a0.rtc_ref.get_owned_organizations()[0]
00044 
00045 def mem_rss():
00046     (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
00047     return output.split()[7]
00048 
00049 ## file and console out
00050 def print_file_and_cons(out_data, out_flag=0):
00051     ## out_flag:1 is file out only
00052     if out_flag == 1:
00053       fout.write(out_data + '\n')
00054       fout.flush()
00055     ## out_flag:2 is console out only
00056     elif out_flag == 2:
00057       print out_data
00058     ## out_flag:0 is console and file out (default)
00059     else:
00060       print out_data
00061       fout.write(out_data + '\n')
00062       fout.flush()
00063     return
00064 
00065 ## memory leak check
00066 def leak_check(rss_start, rss_end):
00067     if rss_start != rss_end:
00068         fodat = "  result: memory leak was found !!!"
00069     else:
00070         fodat = "  result: memory leak was not found."
00071     print_file_and_cons(fodat)
00072     return
00073 
00074 ## file out setting
00075 test_case = "SetMemberSDOPackageTest"
00076 fout = open(test_case + ".log", 'w')
00077 
00078 fodat = "=== " + test_case + " start ==="
00079 print_file_and_cons(fodat)
00080 
00081 loop_cnt = 1000
00082 ## -----------------------------------------------------------------------------
00083 fodat = "set_members()"
00084 print_file_and_cons(fodat)
00085 
00086 for i in range(loop_cnt):
00087     ## Organization::set_members (in SDOList sdos); 
00088     #org.set_members ([consin0.rtc_ref,consout0.rtc_ref])
00089     org.set_members ([consin0.rtc_ref])
00090 
00091     if i == 0:
00092         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00093         fodat = "   %05d: %s KB start" % (1, rss0)
00094         print_file_and_cons(fodat,1)
00095     rss1 = mem_rss() ; j1 = i
00096     if rss0 != rss1:
00097         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00098         print_file_and_cons(fodat,1)
00099         rss0 = rss1 ; j0 = j1
00100 
00101 rssEnd = mem_rss()
00102 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00103 print_file_and_cons(fodat,1)
00104 leak_check(rssStart, rssEnd)
00105 ## -----------------------------------------------------------------------------
00106 fodat = "get_members()"
00107 print_file_and_cons(fodat)
00108 
00109 for i in range(loop_cnt):
00110     ## Organization::get_members ();
00111     org.get_members ()
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()


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:07