CreateDeleteRTCTest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 #
4 ## CreateDeleteRTCTest.py
5 
12 
13 from rtc_handle import *
14 from BasicDataType_idl import *
15 from CorbaNaming import *
16 import time
17 import commands
18 import socket
19 import RTM
20 
21 env = RtmEnv(sys.argv, ["localhost:9898"])
22 
23 mgr_name=socket.gethostname()+".host_cxt/manager.mgr"
24 naming = CorbaNaming(env.orb,"localhost:9898")
25 manager = naming.resolve(mgr_name)._narrow(RTM.Manager)
26 
27 time.sleep(2)
28 
29 def mem_rss():
30  (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
31  return output.split()[7]
32 
33 ## file and console out
34 def print_file_and_cons(out_data, out_flag=0):
35  ## out_flag:1 is file out only
36  if out_flag == 1:
37  fout.write(out_data + '\n')
38  fout.flush()
39  ## out_flag:2 is console out only
40  elif out_flag == 2:
41  print out_data
42  ## out_flag:0 is console and file out (default)
43  else:
44  print out_data
45  fout.write(out_data + '\n')
46  fout.flush()
47  return
48 
49 ## memory leak check
50 def leak_check(rss_start, rss_end):
51  if rss_start != rss_end:
52  fodat = " result: memory leak was found !!!"
53  else:
54  fodat = " result: memory leak was not found."
55  print_file_and_cons(fodat)
56  return
57 
58 ## file out setting
59 test_case = "CreateDeleteRTCTest"
60 fout = open(test_case + ".log", 'w')
61 
62 fodat = "=== " + test_case + " start ==="
64 
65 loop_cnt = 1000
66 ## -----------------------------------------------------------------------------
67 fodat = "load_module() and unload_module()"
69 
70 for i in range(loop_cnt):
71  ## Manager::unload_module(in string pathname);
72  try:
73  #retcode = manager.unload_module(".//ConsoleIn.so")
74  retcode = manager.unload_module(".//ConsoleOut.so")
75  except:
76  pass
77  #print "unload_module() ret=",retcode
78 
79  ## Manager::load_module(in string pathname, in string initfunc);
80  #retcode = manager.load_module("ConsoleIn.so", "ConsoleInInit")
81  retcode = manager.load_module("ConsoleOut.so", "ConsoleOutInit")
82  #print "load_module() ret=",retcode
83 
84  if i == 0:
85  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
86  fodat = " %05d: %s KB start" % (1, rss0)
87  print_file_and_cons(fodat,1)
88  rss1 = mem_rss() ; j1 = i
89  if rss0 != rss1:
90  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
91  print_file_and_cons(fodat,1)
92  rss0 = rss1 ; j0 = j1
93 
94 rssEnd = mem_rss()
95 fodat = " %05d: %s KB end" % (i+1, rssEnd)
96 print_file_and_cons(fodat,1)
97 leak_check(rssStart, rssEnd)
98 ## -----------------------------------------------------------------------------
99 fodat = "create_component() and delete_component()"
100 print_file_and_cons(fodat)
101 
102 for i in range(loop_cnt):
103  ## Manager::delete_component(in string instance_name);
104  ret0 = manager.delete_component("ConsoleOut0")
105  #ret0 = manager.delete_component("ConsoleIn0")
106  #print " delete_comp() ret=",ret0
107 
108  ## Manager::create_component(in string module_name);
109  obj0 = manager.create_component("ConsoleOut")
110  #obj0 = manager.create_component("ConsoleIn")
111  #print " create_comp() ret_Ref=",obj0
112 
113  if i == 0:
114  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
115  fodat = " %05d: %s KB start" % (1, rss0)
116  print_file_and_cons(fodat,1)
117  rss1 = mem_rss() ; j1 = i
118  if rss0 != rss1:
119  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
120  print_file_and_cons(fodat,1)
121  rss0 = rss1 ; j0 = j1
122 
123 rssEnd = mem_rss()
124 fodat = " %05d: %s KB end" % (i+1, rssEnd)
125 print_file_and_cons(fodat,1)
126 leak_check(rssStart, rssEnd)
127 ## -----------------------------------------------------------------------------
128 
129 fodat = "=== " + test_case + " end ==="
130 print_file_and_cons(fodat)
131 fout.close()
132 
133 manager.delete_component("ConsoleOut0")
134 #manager.delete_component("ConsoleIn0")
135 #retcode = manager.unload_module(".//ConsoleOut.so")
def print_file_and_cons(out_data, out_flag=0)
file and console out
def leak_check(rss_start, rss_end)
memory leak check


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:25:58