SDOPackageTest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 #
00004 ## SDOPackageTest.py
00005 ##
00006 ## メモリーリークチェック
00007 ## SDOPackage.idlで定義されているオペレーション
00008 ## ステートレスなオペレーション
00009 #
00010 # $Id: SDOPackageTest.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 
00020 env = RtmEnv(sys.argv, ["localhost:9898"])
00021 listo = env.name_space["localhost:9898"].list_obj()
00022 env.name_space['localhost:9898'].rtc_handles.keys()
00023 
00024 time.sleep(2)
00025 
00026 ns = env.name_space['localhost:9898']
00027 
00028 consin0 = ns.rtc_handles["ConsoleIn0.rtc"]
00029 
00030 def mem_rss():
00031     (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
00032     return output.split()[7]
00033 
00034 ## file and console out
00035 def print_file_and_cons(out_data, out_flag=0):
00036     ## out_flag:1 is file out only
00037     if out_flag == 1:
00038       fout.write(out_data + '\n')
00039       fout.flush()
00040     ## out_flag:2 is console out only
00041     elif out_flag == 2:
00042       print out_data
00043     ## out_flag:0 is console and file out (default)
00044     else:
00045       print out_data
00046       fout.write(out_data + '\n')
00047       fout.flush()
00048     return
00049 
00050 ## memory leak check
00051 def leak_check(rss_start, rss_end):
00052     if rss_start != rss_end:
00053         fodat = "  result: memory leak was found !!!"
00054     else:
00055         fodat = "  result: memory leak was not found."
00056     print_file_and_cons(fodat)
00057     return
00058 
00059 ## file out setting
00060 test_case = "SDOPackageTest"
00061 fout = open(test_case + ".log", 'w')
00062 
00063 fodat = "=== " + test_case + " start ==="
00064 print_file_and_cons(fodat)
00065 
00066 loop_cnt = 1000
00067 ## -----------------------------------------------------------------------------
00068 ## SDOSystemElement::get_monitoring (); 
00069 ###consin0.rtc_ref.get_monitoring ()             # not implemented.
00070 ## SDOSystemElement::get_status (in string nme); 
00071 ###consin0.rtc_ref.get_status (in string nme)    # can not test. because m_sdoStatus is not set.
00072 
00073 ## -----------------------------------------------------------------------------
00074 fodat = "get_owned_organizations()"
00075 print_file_and_cons(fodat)
00076 
00077 for i in range(loop_cnt):
00078     ## SDOSystemElement::get_owned_organizations() 
00079     consin0.rtc_ref.get_owned_organizations()
00080 
00081     if i == 0:
00082         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00083         fodat = "   %05d: %s KB start" % (1, rss0)
00084         print_file_and_cons(fodat,1)
00085     rss1 = mem_rss() ; j1 = i
00086     if rss0 != rss1:
00087         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00088         print_file_and_cons(fodat,1)
00089         rss0 = rss1 ; j0 = j1
00090 
00091 rssEnd = mem_rss()
00092 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00093 print_file_and_cons(fodat,1)
00094 leak_check(rssStart, rssEnd)
00095 ## -----------------------------------------------------------------------------
00096 fodat = "get_sdo_id()"
00097 print_file_and_cons(fodat)
00098 
00099 for i in range(loop_cnt):
00100     ## SDOSystemElement::get_sdo_id(); 
00101     consin0.rtc_ref.get_sdo_id()
00102 
00103     if i == 0:
00104         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00105         fodat = "   %05d: %s KB start" % (1, rss0)
00106         print_file_and_cons(fodat,1)
00107     rss1 = mem_rss() ; j1 = i
00108     if rss0 != rss1:
00109         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00110         print_file_and_cons(fodat,1)
00111         rss0 = rss1 ; j0 = j1
00112 
00113 rssEnd = mem_rss()
00114 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00115 print_file_and_cons(fodat,1)
00116 leak_check(rssStart, rssEnd)
00117 ## -----------------------------------------------------------------------------
00118 fodat = "get_sdo_type()"
00119 print_file_and_cons(fodat)
00120 
00121 for i in range(loop_cnt):
00122     ## SDOSystemElement::get_sdo_type(); 
00123     consin0.rtc_ref.get_sdo_type()
00124 
00125     if i == 0:
00126         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00127         fodat = "   %05d: %s KB start" % (1, rss0)
00128         print_file_and_cons(fodat,1)
00129     rss1 = mem_rss() ; j1 = i
00130     if rss0 != rss1:
00131         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00132         print_file_and_cons(fodat,1)
00133         rss0 = rss1 ; j0 = j1
00134 
00135 rssEnd = mem_rss()
00136 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00137 print_file_and_cons(fodat,1)
00138 leak_check(rssStart, rssEnd)
00139 ## -----------------------------------------------------------------------------
00140 fodat = "get_device_profile()"
00141 print_file_and_cons(fodat)
00142 
00143 for i in range(loop_cnt):
00144     ## SDOSystemElement::get_device_profile (); 
00145     consin0.rtc_ref.get_device_profile ()
00146 
00147     if i == 0:
00148         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00149         fodat = "   %05d: %s KB start" % (1, rss0)
00150         print_file_and_cons(fodat,1)
00151     rss1 = mem_rss() ; j1 = i
00152     if rss0 != rss1:
00153         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00154         print_file_and_cons(fodat,1)
00155         rss0 = rss1 ; j0 = j1
00156 
00157 rssEnd = mem_rss()
00158 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00159 print_file_and_cons(fodat,1)
00160 leak_check(rssStart, rssEnd)
00161 ## -----------------------------------------------------------------------------
00162 fodat = "get_configuration()"
00163 print_file_and_cons(fodat)
00164 
00165 for i in range(loop_cnt):
00166     ## SDOSystemElement::get_configuration (); 
00167     config = consin0.rtc_ref.get_configuration ()
00168 
00169     if i == 0:
00170         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00171         fodat = "   %05d: %s KB start" % (1, rss0)
00172         print_file_and_cons(fodat,1)
00173     rss1 = mem_rss() ; j1 = i
00174     if rss0 != rss1:
00175         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00176         print_file_and_cons(fodat,1)
00177         rss0 = rss1 ; j0 = j1
00178 
00179 rssEnd = mem_rss()
00180 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00181 print_file_and_cons(fodat,1)
00182 leak_check(rssStart, rssEnd)
00183 ## -----------------------------------------------------------------------------
00184 fodat = "get_status_list()"
00185 print_file_and_cons(fodat)
00186 
00187 for i in range(loop_cnt):
00188     ## SDOSystemElement::get_status_list (); 
00189     consin0.rtc_ref.get_status_list ()
00190 
00191     if i == 0:
00192         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00193         fodat = "   %05d: %s KB start" % (1, rss0)
00194         print_file_and_cons(fodat,1)
00195     rss1 = mem_rss() ; j1 = i
00196     if rss0 != rss1:
00197         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00198         print_file_and_cons(fodat,1)
00199         rss0 = rss1 ; j0 = j1
00200 
00201 rssEnd = mem_rss()
00202 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00203 print_file_and_cons(fodat,1)
00204 leak_check(rssStart, rssEnd)
00205 ## -----------------------------------------------------------------------------
00206 fodat = "set_device_profile()"
00207 print_file_and_cons(fodat)
00208 
00209 for i in range(loop_cnt):
00210     ## Configuration::set_device_profile (in DeviceProfile dProfile); 
00211     devProf = SDOPackage.DeviceProfile("test","","","0.1.0",[])
00212     config.set_device_profile (devProf)
00213 
00214     if i == 0:
00215         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00216         fodat = "   %05d: %s KB start" % (1, rss0)
00217         print_file_and_cons(fodat,1)
00218     rss1 = mem_rss() ; j1 = i
00219     if rss0 != rss1:
00220         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00221         print_file_and_cons(fodat,1)
00222         rss0 = rss1 ; j0 = j1
00223 
00224 rssEnd = mem_rss()
00225 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00226 print_file_and_cons(fodat,1)
00227 leak_check(rssStart, rssEnd)
00228 ## -----------------------------------------------------------------------------
00229 fodat = "get_configuration_parameters()"
00230 print_file_and_cons(fodat)
00231 
00232 for i in range(loop_cnt):
00233     ## Configuration::get_configuration_parameters (); 
00234     config.get_configuration_parameters ()
00235 
00236     if i == 0:
00237         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00238         fodat = "   %05d: %s KB start" % (1, rss0)
00239         print_file_and_cons(fodat,1)
00240     rss1 = mem_rss() ; j1 = i
00241     if rss0 != rss1:
00242         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00243         print_file_and_cons(fodat,1)
00244         rss0 = rss1 ; j0 = j1
00245 
00246 rssEnd = mem_rss()
00247 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00248 print_file_and_cons(fodat,1)
00249 leak_check(rssStart, rssEnd)
00250 ## -----------------------------------------------------------------------------
00251 fodat = "get_configuration_parameter_values()"
00252 print_file_and_cons(fodat)
00253 
00254 for i in range(loop_cnt):
00255     ## Configuration::get_configuration_parameter_values (); 
00256     config.get_configuration_parameter_values ()
00257 
00258     if i == 0:
00259         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00260         fodat = "   %05d: %s KB start" % (1, rss0)
00261         print_file_and_cons(fodat,1)
00262     rss1 = mem_rss() ; j1 = i
00263     if rss0 != rss1:
00264         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00265         print_file_and_cons(fodat,1)
00266         rss0 = rss1 ; j0 = j1
00267 
00268 rssEnd = mem_rss()
00269 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00270 print_file_and_cons(fodat,1)
00271 leak_check(rssStart, rssEnd)
00272 ## -----------------------------------------------------------------------------
00273 fodat = "get_configuration_parameter_value()"
00274 print_file_and_cons(fodat)
00275 
00276 for i in range(loop_cnt):
00277     ## Configuration::get_configuration_parameter_value (in string name); 
00278     config.get_configuration_parameter_value ("test")
00279 
00280     if i == 0:
00281         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00282         fodat = "   %05d: %s KB start" % (1, rss0)
00283         print_file_and_cons(fodat,1)
00284     rss1 = mem_rss() ; j1 = i
00285     if rss0 != rss1:
00286         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00287         print_file_and_cons(fodat,1)
00288         rss0 = rss1 ; j0 = j1
00289 
00290 rssEnd = mem_rss()
00291 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00292 print_file_and_cons(fodat,1)
00293 leak_check(rssStart, rssEnd)
00294 ## -----------------------------------------------------------------------------
00295 fodat = "set_configuration_parameter()"
00296 print_file_and_cons(fodat)
00297 
00298 for i in range(loop_cnt):
00299     ## Configuration::set_configuration_parameter (in string name,in any value); 
00300     config.set_configuration_parameter ("test",any.to_any("value"))
00301 
00302     if i == 0:
00303         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00304         fodat = "   %05d: %s KB start" % (1, rss0)
00305         print_file_and_cons(fodat,1)
00306     rss1 = mem_rss() ; j1 = i
00307     if rss0 != rss1:
00308         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00309         print_file_and_cons(fodat,1)
00310         rss0 = rss1 ; j0 = j1
00311 
00312 rssEnd = mem_rss()
00313 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00314 print_file_and_cons(fodat,1)
00315 leak_check(rssStart, rssEnd)
00316 ## -----------------------------------------------------------------------------
00317 fodat = "get_configuration_sets()"
00318 print_file_and_cons(fodat)
00319 
00320 for i in range(loop_cnt):
00321     ## Configuration::get_configuration_sets ();
00322     config.get_configuration_sets ()
00323 
00324     if i == 0:
00325         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00326         fodat = "   %05d: %s KB start" % (1, rss0)
00327         print_file_and_cons(fodat,1)
00328     rss1 = mem_rss() ; j1 = i
00329     if rss0 != rss1:
00330         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00331         print_file_and_cons(fodat,1)
00332         rss0 = rss1 ; j0 = j1
00333 
00334 rssEnd = mem_rss()
00335 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00336 print_file_and_cons(fodat,1)
00337 leak_check(rssStart, rssEnd)
00338 ## -----------------------------------------------------------------------------
00339 
00340 fodat = "=== " + test_case + " end ==="
00341 print_file_and_cons(fodat)
00342 fout.close()


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