ConfigurationSDOPackageTest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 #
4 
12 
13 from rtc_handle import *
14 from BasicDataType_idl import *
15 from omniORB import any
16 import time
17 import commands
18 import SDOPackage
19 import socket
20 import RTM
21 
22 env = RtmEnv(sys.argv, ["localhost:9898"])
23 
24 
25 mgr_name = socket.gethostname()+".host_cxt/manager.mgr"
26 naming = CorbaNaming(env.orb, "localhost:9898")
27 manager = naming.resolve(mgr_name)._narrow(RTM.Manager)
28 
29 manager.create_component("PeriodicECSharedComposite?instance_name=a&exported_ports=ConsoleIn0.out,ConsoleOut0.in")
30 
31 time.sleep(2)
32 
33 listo = env.name_space["localhost:9898"].list_obj()
34 env.name_space['localhost:9898'].rtc_handles.keys()
35 
36 ns = env.name_space['localhost:9898']
37 
38 consin0 = ns.rtc_handles["ConsoleIn0.rtc"]
39 consout0 = ns.rtc_handles["ConsoleOut0.rtc"]
40 
41 a0 = ns.rtc_handles["a.rtc"]
42 org = a0.rtc_ref.get_owned_organizations()[0]
43 config = a0.rtc_ref.get_configuration()
44 configset = config.get_configuration_sets()
45 id = configset[0].id
46 
47 config.add_configuration_set(configset[0])
48 
49 def mem_rss():
50  (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
51  return output.split()[7]
52 
53 
54 def print_file_and_cons(out_data, out_flag=0):
55 
56  if out_flag == 1:
57  fout.write(out_data + '\n')
58  fout.flush()
59 
60  elif out_flag == 2:
61  print out_data
62 
63  else:
64  print out_data
65  fout.write(out_data + '\n')
66  fout.flush()
67  return
68 
69 
70 def leak_check(rss_start, rss_end):
71  if rss_start != rss_end:
72  fodat = " result: memory leak was found !!!"
73  else:
74  fodat = " result: memory leak was not found."
75  print_file_and_cons(fodat)
76  return
77 
78 
79 test_case = "ConfigurationSDOPackageTest"
80 fout = open(test_case + ".log", 'w')
81 
82 fodat = "=== " + test_case + " start ==="
84 
85 loop_cnt = 1000
86 
87 fodat = "add_configuration_set() and remove_configuration_set()"
89 
90 for i in range(loop_cnt):
91 
92  config.add_configuration_set(configset[0])
93 
94 
95  config.remove_configuration_set(id)
96 
97  if i == 0:
98  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
99  fodat = " %05d: %s KB start" % (1, rss0)
100  print_file_and_cons(fodat,1)
101  rss1 = mem_rss() ; j1 = i
102  if rss0 != rss1:
103  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
104  print_file_and_cons(fodat,1)
105  rss0 = rss1 ; j0 = j1
106 
107 rssEnd = mem_rss()
108 fodat = " %05d: %s KB end" % (i+1, rssEnd)
109 print_file_and_cons(fodat,1)
110 leak_check(rssStart, rssEnd)
111 
112 fodat = "activate_configuration_set() and get_active_configuration_set()"
113 
114 print_file_and_cons(fodat)
115 
116 for i in range(loop_cnt):
117 
118  config.activate_configuration_set(id)
119 
120 
121  config.get_active_configuration_set()
122 
123  if i == 0:
124  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
125  fodat = " %05d: %s KB start" % (1, rss0)
126  print_file_and_cons(fodat,1)
127  rss1 = mem_rss() ; j1 = i
128  if rss0 != rss1:
129  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
130  print_file_and_cons(fodat,1)
131  rss0 = rss1 ; j0 = j1
132 
133 rssEnd = mem_rss()
134 fodat = " %05d: %s KB end" % (i+1, rssEnd)
135 print_file_and_cons(fodat,1)
136 leak_check(rssStart, rssEnd)
137 
138 fodat = "get_configuration_set()"
139 print_file_and_cons(fodat)
140 
141 for i in range(loop_cnt):
142 
143  config.get_configuration_set(id)
144 
145  if i == 0:
146  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
147  fodat = " %05d: %s KB start" % (1, rss0)
148  print_file_and_cons(fodat,1)
149  rss1 = mem_rss() ; j1 = i
150  if rss0 != rss1:
151  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
152  print_file_and_cons(fodat,1)
153  rss0 = rss1 ; j0 = j1
154 
155 rssEnd = mem_rss()
156 fodat = " %05d: %s KB end" % (i+1, rssEnd)
157 print_file_and_cons(fodat,1)
158 leak_check(rssStart, rssEnd)
159 
160 fodat = "set_configuration_set_values()"
161 print_file_and_cons(fodat)
162 
163 for i in range(loop_cnt):
164 
165  config.set_configuration_set_values (configset[0])
166 
167  if i == 0:
168  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
169  fodat = " %05d: %s KB start" % (1, rss0)
170  print_file_and_cons(fodat,1)
171  rss1 = mem_rss() ; j1 = i
172  if rss0 != rss1:
173  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
174  print_file_and_cons(fodat,1)
175  rss0 = rss1 ; j0 = j1
176 
177 rssEnd = mem_rss()
178 fodat = " %05d: %s KB end" % (i+1, rssEnd)
179 print_file_and_cons(fodat,1)
180 leak_check(rssStart, rssEnd)
181 
182 
183 fodat = "=== " + test_case + " end ==="
184 print_file_and_cons(fodat)
185 fout.close()
186 
187 config.remove_configuration_set(id)
def leak_check(rss_start, rss_end)
memory leak check
def print_file_and_cons(out_data, out_flag=0)
file and console out


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:42