AddRemoveOrganizationSDOPackageTest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 #
00004 ## AddRemoveOrganizationSDOPackageTest.py
00005 ##
00006 ## メモリーリークチェック
00007 ## SDOPackage.idlで定義されているオペレーション
00008 ## Organizationの追加と削除に関するオペレーション
00009 #
00010 # $Id: AddRemoveOrganizationSDOPackageTest.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 config = a0.rtc_ref.get_configuration()
00041 
00042 
00043 def mem_rss():
00044     (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
00045     return output.split()[7]
00046 
00047 ## file and console out
00048 def print_file_and_cons(out_data, out_flag=0):
00049     ## out_flag:1 is file out only
00050     if out_flag == 1:
00051       fout.write(out_data + '\n')
00052       fout.flush()
00053     ## out_flag:2 is console out only
00054     elif out_flag == 2:
00055       print out_data
00056     ## out_flag:0 is console and file out (default)
00057     else:
00058       print out_data
00059       fout.write(out_data + '\n')
00060       fout.flush()
00061     return
00062 
00063 ## memory leak check
00064 def leak_check(rss_start, rss_end):
00065     if rss_start != rss_end:
00066         fodat = "  result: memory leak was found !!!"
00067     else:
00068         fodat = "  result: memory leak was not found."
00069     print_file_and_cons(fodat)
00070     return
00071 
00072 ## file out setting
00073 test_case = "AddRemoveOrganizationSDOPackageTest"
00074 fout = open(test_case + ".log", 'w')
00075 
00076 fodat = "=== " + test_case + " start ==="
00077 print_file_and_cons(fodat)
00078 
00079 loop_cnt = 1000
00080 ## -----------------------------------------------------------------------------
00081 fodat = "add_organization() and remove_organization()"
00082 print_file_and_cons(fodat)
00083 
00084 for i in range(loop_cnt):
00085     id = org.get_organization_id() 
00086 
00087     ## Configuration::add_organization (in Organization organization_object); 
00088     config.add_organization (org)   ### [add/remove]_organization set
00089 
00090     ## Configuration::remove_organization (in UniqueIdentifier organization_id);
00091     config.remove_organization (id) ###
00092 
00093     if i == 0:
00094         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00095         fodat = "   %05d: %s KB start" % (1, rss0)
00096         print_file_and_cons(fodat,1)
00097     rss1 = mem_rss() ; j1 = i
00098     if rss0 != rss1:
00099         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00100         print_file_and_cons(fodat,1)
00101         rss0 = rss1 ; j0 = j1
00102 
00103 rssEnd = mem_rss()
00104 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00105 print_file_and_cons(fodat,1)
00106 leak_check(rssStart, rssEnd)
00107 ## -----------------------------------------------------------------------------
00108 
00109 fodat = "=== " + test_case + " end ==="
00110 print_file_and_cons(fodat)
00111 fout.close()


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