ServiceProfileSDOPackageTest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 #
00004 ## ServiceProfileSDOPackageTest.py
00005 ##
00006 ## メモリーリークチェック
00007 ## SDOPackage.idlで定義されているオペレーション
00008 ## ServiceProfileに関するオペレーション
00009 #
00010 # $Id: ServiceProfileSDOPackageTest.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 SDOPackage__POA
00020 import socket
00021 import RTM
00022 
00023 ## Dummy class of SDOService_impl.
00024 class SDOServiceMock(SDOPackage__POA.SDOService):
00025     def __init__(self):
00026         pass
00027 
00028 env = RtmEnv(sys.argv, ["localhost:9898"])
00029 
00030 ## Get Manager object reference
00031 mgr_name = socket.gethostname()+".host_cxt/manager.mgr"
00032 naming = CorbaNaming(env.orb, "localhost:9898")
00033 manager = naming.resolve(mgr_name)._narrow(RTM.Manager)
00034 ## Create Composite RTC.
00035 manager.create_component("PeriodicECSharedComposite?instance_name=a&exported_ports=ConsoleIn0.out,ConsoleOut0.in")
00036 
00037 time.sleep(2)
00038 
00039 listo = env.name_space["localhost:9898"].list_obj()
00040 env.name_space['localhost:9898'].rtc_handles.keys()
00041 
00042 ns = env.name_space['localhost:9898']
00043 
00044 
00045 a0 = ns.rtc_handles["a.rtc"]
00046 config = a0.rtc_ref.get_configuration()
00047 svcprofs = a0.rtc_ref.get_service_profiles()
00048 
00049 sdomock = SDOServiceMock()._this()
00050 svcProf = SDOPackage.ServiceProfile("ID 1", "INTERFACE_TYPE 1", [], sdomock)
00051 
00052 def mem_rss():
00053     (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
00054     return output.split()[7]
00055 
00056 ## file and console out
00057 def print_file_and_cons(out_data, out_flag=0):
00058     ## out_flag:1 is file out only
00059     if out_flag == 1:
00060       fout.write(out_data + '\n')
00061       fout.flush()
00062     ## out_flag:2 is console out only
00063     elif out_flag == 2:
00064       print out_data
00065     ## out_flag:0 is console and file out (default)
00066     else:
00067       print out_data
00068       fout.write(out_data + '\n')
00069       fout.flush()
00070     return
00071 
00072 ## memory leak check
00073 def leak_check(rss_start, rss_end):
00074     if rss_start != rss_end:
00075         fodat = "  result: memory leak was found !!!"
00076     else:
00077         fodat = "  result: memory leak was not found."
00078     print_file_and_cons(fodat)
00079     return
00080 
00081 ## file out setting
00082 test_case = "ServiceProfileSDOPackageTest"
00083 fout = open(test_case + ".log", 'w')
00084 
00085 fodat = "=== " + test_case + " start ==="
00086 print_file_and_cons(fodat)
00087 
00088 loop_cnt = 1000
00089 ## -----------------------------------------------------------------------------
00090 fodat = "add_service_profile()"
00091 print_file_and_cons(fodat)
00092 
00093 for i in range(loop_cnt):
00094     ## Configuration::add_service_profile (in ServiceProfile sProfile); 
00095     config.add_service_profile(svcProf)
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_service_profiles()"
00113 print_file_and_cons(fodat)
00114 
00115 for i in range(loop_cnt):
00116     ## SDOSystemElement::get_service_profiles (); 
00117     a0.rtc_ref.get_service_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_service_profile()"
00135 print_file_and_cons(fodat)
00136 
00137 for i in range(loop_cnt):
00138     ## SDOSystemElement::get_service_profile (in UniqueIdentifier id); 
00139     a0.rtc_ref.get_service_profile("ID 1")
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_sdo_service()"
00157 print_file_and_cons(fodat)
00158 
00159 for i in range(loop_cnt):
00160     ## SDOSystemElement::get_sdo_service (in UniqueIdentifier id);
00161     a0.rtc_ref.get_sdo_service("ID 1")
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 = "remove_service_profile()"
00179 print_file_and_cons(fodat)
00180 
00181 for i in range(loop_cnt):
00182     ## Configuration::remove_service_profile (in UniqueIdentifier id); 
00183     config.remove_service_profile("ID 1")
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 
00201 fodat = "=== " + test_case + " end ==="
00202 print_file_and_cons(fodat)
00203 fout.close()


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:17