ConfigurationSDOPackageTest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 #
00004 ## ConfigurationSDOPackageTest.py
00005 ##
00006 ## メモリーリークチェック
00007 ## SDOPackage.idlで定義されているオペレーション
00008 ## Configurationに関するオペレーション
00009 #
00010 # $Id: ConfigurationSDOPackageTest.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 ns = env.name_space['localhost:9898']
00037 
00038 consin0 = ns.rtc_handles["ConsoleIn0.rtc"]
00039 consout0 = ns.rtc_handles["ConsoleOut0.rtc"]
00040 
00041 a0 = ns.rtc_handles["a.rtc"]
00042 org = a0.rtc_ref.get_owned_organizations()[0]
00043 config = a0.rtc_ref.get_configuration()
00044 configset = config.get_configuration_sets()
00045 id = configset[0].id
00046 
00047 config.add_configuration_set(configset[0]) 
00048 
00049 def mem_rss():
00050     (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
00051     return output.split()[7]
00052 
00053 ## file and console out
00054 def print_file_and_cons(out_data, out_flag=0):
00055     ## out_flag:1 is file out only
00056     if out_flag == 1:
00057       fout.write(out_data + '\n')
00058       fout.flush()
00059     ## out_flag:2 is console out only
00060     elif out_flag == 2:
00061       print out_data
00062     ## out_flag:0 is console and file out (default)
00063     else:
00064       print out_data
00065       fout.write(out_data + '\n')
00066       fout.flush()
00067     return
00068 
00069 ## memory leak check
00070 def leak_check(rss_start, rss_end):
00071     if rss_start != rss_end:
00072         fodat = "  result: memory leak was found !!!"
00073     else:
00074         fodat = "  result: memory leak was not found."
00075     print_file_and_cons(fodat)
00076     return
00077 
00078 ## file out setting
00079 test_case = "ConfigurationSDOPackageTest"
00080 fout = open(test_case + ".log", 'w')
00081 
00082 fodat = "=== " + test_case + " start ==="
00083 print_file_and_cons(fodat)
00084 
00085 loop_cnt = 1000
00086 ## -----------------------------------------------------------------------------
00087 fodat = "add_configuration_set() and remove_configuration_set()"
00088 print_file_and_cons(fodat)
00089 
00090 for i in range(loop_cnt):
00091     ## Configuration::add_configuration_set (in ConfigurationSet configuration_set); 
00092     config.add_configuration_set(configset[0]) 
00093 
00094     ## Configuration::remove_configuration_set (in UniqueIdentifier config_id); 
00095     config.remove_configuration_set(id) 
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 = "activate_configuration_set() and get_active_configuration_set()"
00113 
00114 print_file_and_cons(fodat)
00115 
00116 for i in range(loop_cnt):
00117     ## Configuration::activate_configuration_set (in UniqueIdentifier config_id); 
00118     config.activate_configuration_set(id) 
00119 
00120     ## Configuration::get_active_configuration_set ();
00121     config.get_active_configuration_set()
00122 
00123     if i == 0:
00124         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00125         fodat = "   %05d: %s KB start" % (1, rss0)
00126         print_file_and_cons(fodat,1)
00127     rss1 = mem_rss() ; j1 = i
00128     if rss0 != rss1:
00129         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00130         print_file_and_cons(fodat,1)
00131         rss0 = rss1 ; j0 = j1
00132 
00133 rssEnd = mem_rss()
00134 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00135 print_file_and_cons(fodat,1)
00136 leak_check(rssStart, rssEnd)
00137 ## -----------------------------------------------------------------------------
00138 fodat = "get_configuration_set()"
00139 print_file_and_cons(fodat)
00140 
00141 for i in range(loop_cnt):
00142     ## Configuration::get_configuration_set (in UniqueIdentifier config_id); 
00143     config.get_configuration_set(id) 
00144 
00145     if i == 0:
00146         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00147         fodat = "   %05d: %s KB start" % (1, rss0)
00148         print_file_and_cons(fodat,1)
00149     rss1 = mem_rss() ; j1 = i
00150     if rss0 != rss1:
00151         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00152         print_file_and_cons(fodat,1)
00153         rss0 = rss1 ; j0 = j1
00154 
00155 rssEnd = mem_rss()
00156 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00157 print_file_and_cons(fodat,1)
00158 leak_check(rssStart, rssEnd)
00159 ## -----------------------------------------------------------------------------
00160 fodat = "set_configuration_set_values()"
00161 print_file_and_cons(fodat)
00162 
00163 for i in range(loop_cnt):
00164     ## Configuration::set_configuration_set_values (in ConfigurationSet configuration_set); 
00165     config.set_configuration_set_values (configset[0]) 
00166 
00167     if i == 0:
00168         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00169         fodat = "   %05d: %s KB start" % (1, rss0)
00170         print_file_and_cons(fodat,1)
00171     rss1 = mem_rss() ; j1 = i
00172     if rss0 != rss1:
00173         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00174         print_file_and_cons(fodat,1)
00175         rss0 = rss1 ; j0 = j1
00176 
00177 rssEnd = mem_rss()
00178 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00179 print_file_and_cons(fodat,1)
00180 leak_check(rssStart, rssEnd)
00181 ## -----------------------------------------------------------------------------
00182 
00183 fodat = "=== " + test_case + " end ==="
00184 print_file_and_cons(fodat)
00185 fout.close()
00186 
00187 config.remove_configuration_set(id) 


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Aug 27 2015 14:16:37