AddRemoveMemberSDOPackageTest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 #
00004 ## AddRemoveMemberSDOPackageTest.py
00005 ##
00006 ## メモリーリークチェック
00007 ## SDOPackage.idlで定義されているオペレーション
00008 ## OrganizationのMemberの追加と削除に関するオペレーション
00009 #
00010 # $Id: AddRemoveMemberSDOPackageTest.py 1541 2009-08-31 07:21:12Z hakuta $
00011 #
00012 
00013 
00014 from rtc_handle import *
00015 from BasicDataType_idl import *
00016 from omniORB import any
00017 import time
00018 import commands
00019 import SDOPackage
00020 import socket
00021 import RTM
00022 
00023 env = RtmEnv(sys.argv, ["localhost:9898"])
00024 
00025 ## Get Manager object reference
00026 mgr_name = socket.gethostname()+".host_cxt/manager.mgr"
00027 naming = CorbaNaming(env.orb, "localhost:9898")
00028 manager = naming.resolve(mgr_name)._narrow(RTM.Manager)
00029 ## Create Composite RTC.
00030 manager.create_component("PeriodicECSharedComposite?instance_name=a&exported_ports=ConsoleIn0.out,ConsoleOut0.in")
00031 
00032 time.sleep(2)
00033 
00034 listo = env.name_space["localhost:9898"].list_obj()
00035 env.name_space['localhost:9898'].rtc_handles.keys()
00036 
00037 ns = env.name_space['localhost:9898']
00038 
00039 seqin0 = ns.rtc_handles["SequenceInComponent0.rtc"]
00040 a0 = ns.rtc_handles["a.rtc"]
00041 org = a0.rtc_ref.get_owned_organizations()[0]
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 = "AddRemoveMemberSDOPackageTest"
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_members() and remove_member()"
00082 print_file_and_cons(fodat)
00083 
00084 for i in range(loop_cnt):
00085     ## Organization::add_members ( in SDOList sdo_list); 
00086     org.add_members ([seqin0.rtc_ref])               ### [add/remove]_member set
00087 
00088     ## Organization::remove_member (in UniqueIdentifier id);
00089     org.remove_member (seqin0.rtc_ref.get_sdo_id())  ### Segmentation fault.
00090 
00091     if i == 0:
00092         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00093         fodat = "   %05d: %s KB start" % (1, rss0)
00094         print_file_and_cons(fodat,1)
00095     rss1 = mem_rss() ; j1 = i
00096     if rss0 != rss1:
00097         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00098         print_file_and_cons(fodat,1)
00099         rss0 = rss1 ; j0 = j1
00100 
00101 rssEnd = mem_rss()
00102 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00103 print_file_and_cons(fodat,1)
00104 leak_check(rssStart, rssEnd)
00105 ## -----------------------------------------------------------------------------
00106 
00107 fodat = "=== " + test_case + " end ==="
00108 print_file_and_cons(fodat)
00109 fout.close()


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