OrganizationSDOPackageTest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 #
00004 ## OrganizationSDOPackageTest.py
00005 ##
00006 ## メモリーリークチェック
00007 ## SDOPackage.idlで定義されているオペレーション
00008 ## Organizationに関するオペレーション
00009 #
00010 # $Id: OrganizationSDOPackageTest.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 a0 = ns.rtc_handles["a.rtc"]
00039 org = a0.rtc_ref.get_owned_organizations()[0]
00040 nv = SDOPackage.NameValue("Test", any.to_any(100))
00041 
00042 def mem_rss():
00043     (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
00044     return output.split()[7]
00045 
00046 ## file and console out
00047 def print_file_and_cons(out_data, out_flag=0):
00048     ## out_flag:1 is file out only
00049     if out_flag == 1:
00050       fout.write(out_data + '\n')
00051       fout.flush()
00052     ## out_flag:2 is console out only
00053     elif out_flag == 2:
00054       print out_data
00055     ## out_flag:0 is console and file out (default)
00056     else:
00057       print out_data
00058       fout.write(out_data + '\n')
00059       fout.flush()
00060     return
00061 
00062 ## memory leak check
00063 def leak_check(rss_start, rss_end):
00064     if rss_start != rss_end:
00065         fodat = "  result: memory leak was found !!!"
00066     else:
00067         fodat = "  result: memory leak was not found."
00068     print_file_and_cons(fodat)
00069     return
00070 
00071 ## file out setting
00072 test_case = "OrganizationSDOPackageTest"
00073 fout = open(test_case + ".log", 'w')
00074 
00075 fodat = "=== " + test_case + " start ==="
00076 print_file_and_cons(fodat)
00077 
00078 loop_cnt = 1000
00079 ## -----------------------------------------------------------------------------
00080 fodat = "get_organization_id()"
00081 print_file_and_cons(fodat)
00082 
00083 for i in range(loop_cnt):
00084     ## Organization::get_organization_id (); 
00085     id = org.get_organization_id()
00086 
00087     if i == 0:
00088         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00089         fodat = "   %05d: %s KB start" % (1, rss0)
00090         print_file_and_cons(fodat,1)
00091     rss1 = mem_rss() ; j1 = i
00092     if rss0 != rss1:
00093         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00094         print_file_and_cons(fodat,1)
00095         rss0 = rss1 ; j0 = j1
00096 
00097 rssEnd = mem_rss()
00098 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00099 print_file_and_cons(fodat,1)
00100 leak_check(rssStart, rssEnd)
00101 ## -----------------------------------------------------------------------------
00102 fodat = "get_organization_property()"
00103 print_file_and_cons(fodat)
00104 
00105 for i in range(loop_cnt):
00106     ## Organization::get_organization_property (); 
00107     prop = org.get_organization_property()
00108 
00109     if i == 0:
00110         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00111         fodat = "   %05d: %s KB start" % (1, rss0)
00112         print_file_and_cons(fodat,1)
00113     rss1 = mem_rss() ; j1 = i
00114     if rss0 != rss1:
00115         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00116         print_file_and_cons(fodat,1)
00117         rss0 = rss1 ; j0 = j1
00118 
00119 rssEnd = mem_rss()
00120 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00121 print_file_and_cons(fodat,1)
00122 leak_check(rssStart, rssEnd)
00123 ## -----------------------------------------------------------------------------
00124 fodat = "get_owner()"
00125 print_file_and_cons(fodat)
00126 
00127 for i in range(loop_cnt):
00128     ## Organization::get_owner (); 
00129     org.get_owner()
00130 
00131     if i == 0:
00132         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00133         fodat = "   %05d: %s KB start" % (1, rss0)
00134         print_file_and_cons(fodat,1)
00135     rss1 = mem_rss() ; j1 = i
00136     if rss0 != rss1:
00137         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00138         print_file_and_cons(fodat,1)
00139         rss0 = rss1 ; j0 = j1
00140 
00141 rssEnd = mem_rss()
00142 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00143 print_file_and_cons(fodat,1)
00144 leak_check(rssStart, rssEnd)
00145 ## -----------------------------------------------------------------------------
00146 fodat = "get_organizations()"
00147 print_file_and_cons(fodat)
00148 
00149 for i in range(loop_cnt):
00150     ## SDOSystemElement::get_organizations (); 
00151     a0.rtc_ref.get_organizations()
00152 
00153     if i == 0:
00154         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00155         fodat = "   %05d: %s KB start" % (1, rss0)
00156         print_file_and_cons(fodat,1)
00157     rss1 = mem_rss() ; j1 = i
00158     if rss0 != rss1:
00159         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00160         print_file_and_cons(fodat,1)
00161         rss0 = rss1 ; j0 = j1
00162 
00163 rssEnd = mem_rss()
00164 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00165 print_file_and_cons(fodat,1)
00166 leak_check(rssStart, rssEnd)
00167 ## -----------------------------------------------------------------------------
00168 fodat = "add_organization_property() and get_organization_property_value() and \nremove_organization_property()"
00169 print_file_and_cons(fodat)
00170 
00171 for i in range(loop_cnt):
00172     ## Organization::add_organization_property (in OrganizationProperty organization_property); 
00173     org.add_organization_property(SDOPackage.OrganizationProperty([nv]))
00174 
00175     ## Organization::get_organization_property_value (in string name); 
00176     org.get_organization_property_value("Test")
00177 
00178     ## Organization::remove_organization_property ( in string name );
00179     org.remove_organization_property("Test")
00180 
00181     if i == 0:
00182         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00183         fodat = "   %05d: %s KB start" % (1, rss0)
00184         print_file_and_cons(fodat,1)
00185     rss1 = mem_rss() ; j1 = i
00186     if rss0 != rss1:
00187         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00188         print_file_and_cons(fodat,1)
00189         rss0 = rss1 ; j0 = j1
00190 
00191 rssEnd = mem_rss()
00192 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00193 print_file_and_cons(fodat,1)
00194 leak_check(rssStart, rssEnd)
00195 ## -----------------------------------------------------------------------------
00196 fodat = "set_organization_property_value()"
00197 print_file_and_cons(fodat)
00198 
00199 for i in range(loop_cnt):
00200     ## Organization::set_organization_property_value (in string name,in any value); 
00201     org.set_organization_property_value("Test2",any.to_any(200))
00202 
00203     if i == 0:
00204         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00205         fodat = "   %05d: %s KB start" % (1, rss0)
00206         print_file_and_cons(fodat,1)
00207     rss1 = mem_rss() ; j1 = i
00208     if rss0 != rss1:
00209         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00210         print_file_and_cons(fodat,1)
00211         rss0 = rss1 ; j0 = j1
00212 
00213 rssEnd = mem_rss()
00214 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00215 print_file_and_cons(fodat,1)
00216 leak_check(rssStart, rssEnd)
00217 ## -----------------------------------------------------------------------------
00218 fodat = "set_owner()"
00219 print_file_and_cons(fodat)
00220 
00221 for i in range(loop_cnt):
00222     ## Organization::set_owner (in SDOSystemElement sdo); 
00223     org.set_owner(a0.rtc_ref)
00224 
00225     if i == 0:
00226         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00227         fodat = "   %05d: %s KB start" % (1, rss0)
00228         print_file_and_cons(fodat,1)
00229     rss1 = mem_rss() ; j1 = i
00230     if rss0 != rss1:
00231         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00232         print_file_and_cons(fodat,1)
00233         rss0 = rss1 ; j0 = j1
00234 
00235 rssEnd = mem_rss()
00236 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00237 print_file_and_cons(fodat,1)
00238 leak_check(rssStart, rssEnd)
00239 ## -----------------------------------------------------------------------------
00240 
00241 fodat = "=== " + test_case + " end ==="
00242 print_file_and_cons(fodat)
00243 fout.close()


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