r2corba 1.4.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +159 -0
  3. data/LICENSE +59 -0
  4. data/README +62 -0
  5. data/THANKS +52 -0
  6. data/bin/r2corba +8 -0
  7. data/bin/r2corba.bat +20 -0
  8. data/bin/ridlc +11 -0
  9. data/bin/ridlc.bat +23 -0
  10. data/bin/rins +7 -0
  11. data/bin/rins.bat +19 -0
  12. data/ext/.keep +0 -0
  13. data/lib/corba/cbase/IORMap.rb +33 -0
  14. data/lib/corba/cbase/ORB.rb +231 -0
  15. data/lib/corba/cbase/Request.rb +134 -0
  16. data/lib/corba/cbase/Streams.rb +129 -0
  17. data/lib/corba/cbase/Stub.rb +19 -0
  18. data/lib/corba/cbase/Typecode.rb +441 -0
  19. data/lib/corba/cbase/Values.rb +129 -0
  20. data/lib/corba/cbase/exception.rb +66 -0
  21. data/lib/corba/cbase/poa.rb +23 -0
  22. data/lib/corba/cbase/policies.rb +78 -0
  23. data/lib/corba/cbase/post_require.rb +14 -0
  24. data/lib/corba/cbase/require.rb +28 -0
  25. data/lib/corba/cmds/base.rb +85 -0
  26. data/lib/corba/cmds/test.rb +30 -0
  27. data/lib/corba/common/Any.rb +91 -0
  28. data/lib/corba/common/IDL.rb +104 -0
  29. data/lib/corba/common/ORB.rb +368 -0
  30. data/lib/corba/common/Object.rb +208 -0
  31. data/lib/corba/common/Request.rb +20 -0
  32. data/lib/corba/common/Servant.rb +108 -0
  33. data/lib/corba/common/Struct.rb +22 -0
  34. data/lib/corba/common/Stub.rb +79 -0
  35. data/lib/corba/common/Typecode.rb +1121 -0
  36. data/lib/corba/common/Union.rb +56 -0
  37. data/lib/corba/common/Values.rb +92 -0
  38. data/lib/corba/common/const.rb +22 -0
  39. data/lib/corba/common/exception.rb +68 -0
  40. data/lib/corba/common/require.rb +27 -0
  41. data/lib/corba/common/version.rb +22 -0
  42. data/lib/corba/idl/BiDirPolicyC.rb +63 -0
  43. data/lib/corba/idl/CosNamingC.rb +461 -0
  44. data/lib/corba/idl/CosNamingS.rb +309 -0
  45. data/lib/corba/idl/IDL.rb +21 -0
  46. data/lib/corba/idl/IORTable.pidl +62 -0
  47. data/lib/corba/idl/IORTableC.rb +117 -0
  48. data/lib/corba/idl/MessagingC.rb +904 -0
  49. data/lib/corba/idl/POAC.rb +930 -0
  50. data/lib/corba/idl/TAO_Ext.pidl +46 -0
  51. data/lib/corba/idl/TAO_ExtC.rb +179 -0
  52. data/lib/corba/idl/r2c_orb.rb +572 -0
  53. data/lib/corba/idl/require.rb +20 -0
  54. data/lib/corba/jbase/Any.rb +273 -0
  55. data/lib/corba/jbase/IORMap.rb +36 -0
  56. data/lib/corba/jbase/ORB.rb +99 -0
  57. data/lib/corba/jbase/Object.rb +98 -0
  58. data/lib/corba/jbase/Request.rb +226 -0
  59. data/lib/corba/jbase/Servant.rb +247 -0
  60. data/lib/corba/jbase/ServerRequest.rb +128 -0
  61. data/lib/corba/jbase/Streams.rb +671 -0
  62. data/lib/corba/jbase/Stub.rb +38 -0
  63. data/lib/corba/jbase/Typecode.rb +520 -0
  64. data/lib/corba/jbase/Values.rb +173 -0
  65. data/lib/corba/jbase/exception.rb +106 -0
  66. data/lib/corba/jbase/poa.rb +229 -0
  67. data/lib/corba/jbase/policies.rb +300 -0
  68. data/lib/corba/jbase/post_require.rb +14 -0
  69. data/lib/corba/jbase/require.rb +86 -0
  70. data/lib/corba/naming.rb +14 -0
  71. data/lib/corba/naming_service.rb +15 -0
  72. data/lib/corba/poa.rb +15 -0
  73. data/lib/corba/policies.rb +18 -0
  74. data/lib/corba/require.rb +17 -0
  75. data/lib/corba/svcs/ins/cos_naming.rb +426 -0
  76. data/lib/corba/svcs/ins/ins.rb +526 -0
  77. data/lib/corba/svcs/ins/naming_service.rb +119 -0
  78. data/lib/corba.rb +16 -0
  79. data/lib/ridlbe/ruby/config.rb +336 -0
  80. data/lib/ridlbe/ruby/orb.pidlc +0 -0
  81. data/lib/ridlbe/ruby/require.rb +16 -0
  82. data/lib/ridlbe/ruby/walker.rb +1582 -0
  83. data/mkrf_conf_bingem.rb +101 -0
  84. data/rakelib/bin.rake +80 -0
  85. data/rakelib/bin.rb +146 -0
  86. data/rakelib/build.rake +87 -0
  87. data/rakelib/config.rake +52 -0
  88. data/rakelib/config.rb +450 -0
  89. data/rakelib/ext.rake +242 -0
  90. data/rakelib/ext.rb +308 -0
  91. data/rakelib/ext_r2tao.rb +232 -0
  92. data/rakelib/gem.rake +212 -0
  93. data/rakelib/gem.rb +146 -0
  94. data/rakelib/package.rake +26 -0
  95. data/rakelib/test.rake +23 -0
  96. data/test/BiDirectional/Test.idl +34 -0
  97. data/test/BiDirectional/client.rb +132 -0
  98. data/test/BiDirectional/run_test.rb +68 -0
  99. data/test/BiDirectional/server.ior +1 -0
  100. data/test/BiDirectional/server.rb +169 -0
  101. data/test/CORBA_Services/Naming/BindingIterator/Test.idl +27 -0
  102. data/test/CORBA_Services/Naming/BindingIterator/client.rb +121 -0
  103. data/test/CORBA_Services/Naming/BindingIterator/ins.ior +1 -0
  104. data/test/CORBA_Services/Naming/BindingIterator/run_test.rb +82 -0
  105. data/test/CORBA_Services/Naming/BindingIterator/server.rb +109 -0
  106. data/test/CORBA_Services/Naming/Corbaname/Test.idl +27 -0
  107. data/test/CORBA_Services/Naming/Corbaname/client.rb +85 -0
  108. data/test/CORBA_Services/Naming/Corbaname/corbaname.ior +1 -0
  109. data/test/CORBA_Services/Naming/Corbaname/ins.ior +1 -0
  110. data/test/CORBA_Services/Naming/Corbaname/run_test.rb +88 -0
  111. data/test/CORBA_Services/Naming/Corbaname/server.rb +135 -0
  112. data/test/CORBA_Services/Naming/Simple/Test.idl +27 -0
  113. data/test/CORBA_Services/Naming/Simple/client.rb +84 -0
  114. data/test/CORBA_Services/Naming/Simple/ins.ior +1 -0
  115. data/test/CORBA_Services/Naming/Simple/run_test.rb +82 -0
  116. data/test/CORBA_Services/Naming/Simple/server.rb +109 -0
  117. data/test/Collocation/Diamond.idl +39 -0
  118. data/test/Collocation/run_test.rb +52 -0
  119. data/test/Collocation/test.rb +195 -0
  120. data/test/Connect_Timeout/Test.idl +27 -0
  121. data/test/Connect_Timeout/client.rb +111 -0
  122. data/test/Connect_Timeout/run_test.rb +52 -0
  123. data/test/DII/Test.idl +27 -0
  124. data/test/DII/client.rb +115 -0
  125. data/test/DII/run_test.rb +69 -0
  126. data/test/DII/server.ior +1 -0
  127. data/test/DII/server.rb +95 -0
  128. data/test/DSI/Test.idl +27 -0
  129. data/test/DSI/client.rb +66 -0
  130. data/test/DSI/run_test.rb +69 -0
  131. data/test/DSI/server.ior +1 -0
  132. data/test/DSI/server.rb +106 -0
  133. data/test/Exceptions/Test.idl +48 -0
  134. data/test/Exceptions/client.rb +118 -0
  135. data/test/Exceptions/run_test.rb +69 -0
  136. data/test/Exceptions/server.ior +1 -0
  137. data/test/Exceptions/server.rb +131 -0
  138. data/test/Hello/Test.idl +27 -0
  139. data/test/Hello/client.rb +78 -0
  140. data/test/Hello/run_test.rb +71 -0
  141. data/test/Hello/server.rb +95 -0
  142. data/test/IDL_Test/Test.idl +113 -0
  143. data/test/IDL_Test/Test_inc.idl +17 -0
  144. data/test/IDL_Test/client.rb +102 -0
  145. data/test/IDL_Test/run_test.rb +69 -0
  146. data/test/IDL_Test/server.ior +1 -0
  147. data/test/IDL_Test/server.rb +99 -0
  148. data/test/IORMap/Test.idl +27 -0
  149. data/test/IORMap/client.rb +73 -0
  150. data/test/IORMap/run_test.rb +69 -0
  151. data/test/IORMap/server.ior +1 -0
  152. data/test/IORMap/server.rb +114 -0
  153. data/test/IORTable/Test.idl +27 -0
  154. data/test/IORTable/client.rb +75 -0
  155. data/test/IORTable/run_test.rb +69 -0
  156. data/test/IORTable/server.ior +1 -0
  157. data/test/IORTable/server.rb +130 -0
  158. data/test/Implicit_Conversion/Test.idl +31 -0
  159. data/test/Implicit_Conversion/client.rb +110 -0
  160. data/test/Implicit_Conversion/run_test.rb +69 -0
  161. data/test/Implicit_Conversion/server.ior +1 -0
  162. data/test/Implicit_Conversion/server.rb +99 -0
  163. data/test/Multi_Threading/Multiple_ORB/Test.idl +27 -0
  164. data/test/Multi_Threading/Multiple_ORB/client.rb +82 -0
  165. data/test/Multi_Threading/Multiple_ORB/run_test.rb +71 -0
  166. data/test/Multi_Threading/Multiple_ORB/server.rb +108 -0
  167. data/test/Multi_Threading/Multiple_ORB/server0.ior +1 -0
  168. data/test/Multi_Threading/Multiple_ORB/server1.ior +1 -0
  169. data/test/Multi_Threading/Simple/Test.idl +27 -0
  170. data/test/Multi_Threading/Simple/client.rb +88 -0
  171. data/test/Multi_Threading/Simple/run_test.rb +69 -0
  172. data/test/Multi_Threading/Simple/server.ior +1 -0
  173. data/test/Multi_Threading/Simple/server.rb +118 -0
  174. data/test/Multi_Threading/Threads/Test.idl +31 -0
  175. data/test/Multi_Threading/Threads/client.rb +80 -0
  176. data/test/Multi_Threading/Threads/run_test.rb +76 -0
  177. data/test/Multi_Threading/Threads/server.ior +1 -0
  178. data/test/Multi_Threading/Threads/server.rb +119 -0
  179. data/test/Multi_Threading/Threads/watchdog.ior +1 -0
  180. data/test/Multi_Threading/Threads/watchdog.rb +87 -0
  181. data/test/Multiple_Servant_Interfaces/Test.idl +34 -0
  182. data/test/Multiple_Servant_Interfaces/client.rb +70 -0
  183. data/test/Multiple_Servant_Interfaces/run_test.rb +69 -0
  184. data/test/Multiple_Servant_Interfaces/server.ior +1 -0
  185. data/test/Multiple_Servant_Interfaces/server.rb +102 -0
  186. data/test/Nil/Test.idl +27 -0
  187. data/test/Nil/run_test.rb +52 -0
  188. data/test/Nil/test.rb +78 -0
  189. data/test/OBV/AbstractInterface/client.rb +179 -0
  190. data/test/OBV/AbstractInterface/run_test.rb +69 -0
  191. data/test/OBV/AbstractInterface/server.ior +1 -0
  192. data/test/OBV/AbstractInterface/server.rb +149 -0
  193. data/test/OBV/AbstractInterface/test.idl +53 -0
  194. data/test/OBV/Custom/OBV.idl +18 -0
  195. data/test/OBV/Custom/OBV_impl.rb +40 -0
  196. data/test/OBV/Custom/client.rb +86 -0
  197. data/test/OBV/Custom/run_test.rb +69 -0
  198. data/test/OBV/Custom/server.ior +1 -0
  199. data/test/OBV/Custom/server.rb +100 -0
  200. data/test/OBV/Simple/OBV.idl +15 -0
  201. data/test/OBV/Simple/OBV_impl.rb +26 -0
  202. data/test/OBV/Simple/client.rb +86 -0
  203. data/test/OBV/Simple/run_test.rb +69 -0
  204. data/test/OBV/Simple/server.ior +1 -0
  205. data/test/OBV/Simple/server.rb +100 -0
  206. data/test/OBV/Simple_Event/Event.idl +15 -0
  207. data/test/OBV/Simple_Event/Event_impl.rb +26 -0
  208. data/test/OBV/Simple_Event/client.rb +86 -0
  209. data/test/OBV/Simple_Event/run_test.rb +69 -0
  210. data/test/OBV/Simple_Event/server.ior +1 -0
  211. data/test/OBV/Simple_Event/server.rb +100 -0
  212. data/test/OBV/Supports/client.rb +116 -0
  213. data/test/OBV/Supports/run_test.rb +69 -0
  214. data/test/OBV/Supports/server.ior +1 -0
  215. data/test/OBV/Supports/server.rb +103 -0
  216. data/test/OBV/Supports/supports.idl +33 -0
  217. data/test/OBV/Supports/supports_impl.rb +57 -0
  218. data/test/OBV/Tree/client.rb +116 -0
  219. data/test/OBV/Tree/run_test.rb +69 -0
  220. data/test/OBV/Tree/server.ior +1 -0
  221. data/test/OBV/Tree/server.rb +117 -0
  222. data/test/OBV/Tree/test.idl +32 -0
  223. data/test/OBV/Truncatable/Extra.idl +27 -0
  224. data/test/OBV/Truncatable/Truncatable.idl +105 -0
  225. data/test/OBV/Truncatable/Truncatable_impl.rb +86 -0
  226. data/test/OBV/Truncatable/client.rb +279 -0
  227. data/test/OBV/Truncatable/run_test.rb +69 -0
  228. data/test/OBV/Truncatable/server.ior +1 -0
  229. data/test/OBV/Truncatable/server.rb +89 -0
  230. data/test/OBV/ValueBox/client.rb +497 -0
  231. data/test/OBV/ValueBox/run_test.rb +69 -0
  232. data/test/OBV/ValueBox/server.ior +1 -0
  233. data/test/OBV/ValueBox/server.rb +271 -0
  234. data/test/OBV/ValueBox/valuebox.idl +101 -0
  235. data/test/OBV/ValueBox/vb_basic.idl +75 -0
  236. data/test/OBV/ValueBox/vb_struct.idl +68 -0
  237. data/test/OBV/ValueBox/vb_union.idl +21 -0
  238. data/test/Object/Test.idl +27 -0
  239. data/test/Object/client.rb +103 -0
  240. data/test/Object/run_test.rb +69 -0
  241. data/test/Object/server.ior +1 -0
  242. data/test/Object/server.rb +126 -0
  243. data/test/POA/Test.idl +27 -0
  244. data/test/POA/run_test.rb +52 -0
  245. data/test/POA/test.rb +112 -0
  246. data/test/Param_Test/Test.idl +182 -0
  247. data/test/Param_Test/client.rb +277 -0
  248. data/test/Param_Test/run_test.rb +69 -0
  249. data/test/Param_Test/server.ior +1 -0
  250. data/test/Param_Test/server.rb +296 -0
  251. data/test/Performance/Simple/Test.idl +27 -0
  252. data/test/Performance/Simple/client.rb +90 -0
  253. data/test/Performance/Simple/run_test.rb +69 -0
  254. data/test/Performance/Simple/server.ior +1 -0
  255. data/test/Performance/Simple/server.rb +95 -0
  256. data/test/Policies/Test.idl +27 -0
  257. data/test/Policies/run_test.rb +52 -0
  258. data/test/Policies/test.rb +144 -0
  259. data/test/Timeout/client.rb +207 -0
  260. data/test/Timeout/run_test.rb +69 -0
  261. data/test/Timeout/server.ior +1 -0
  262. data/test/Timeout/server.rb +109 -0
  263. data/test/Timeout/test.idl +19 -0
  264. data/test/lib/assert.rb +43 -0
  265. data/test/lib/test.rb +542 -0
  266. data/test/test_runner.rb +193 -0
  267. metadata +342 -0
data/test/lib/test.rb ADDED
@@ -0,0 +1,542 @@
1
+ #--------------------------------------------------------------------
2
+ # test.rb - Test running utils
3
+ #
4
+ # Author: Martin Corino
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the R2CORBA LICENSE which is
8
+ # included with this program.
9
+ #
10
+ # Copyright (c) Remedy IT Expertise BV
11
+ # Chamber of commerce Rotterdam nr.276339, The Netherlands
12
+ #--------------------------------------------------------------------
13
+
14
+ require 'rbconfig'
15
+
16
+ module TestUtil
17
+
18
+ if defined? RbConfig
19
+ RB_CONFIG = RbConfig::CONFIG
20
+ else
21
+ RB_CONFIG = Config::CONFIG
22
+ end
23
+
24
+ def self.is_win32?
25
+ (RB_CONFIG['target_os'] =~ /win32/ || RB_CONFIG['target_os'] =~ /mingw32/) ? true : false
26
+ end
27
+
28
+ RBVersion = RUBY_VERSION.split('.').collect {|x| x.to_i}
29
+ end
30
+
31
+
32
+ if defined?(JRUBY_VERSION)
33
+ require 'ffi'
34
+ elsif TestUtil::is_win32?
35
+ unless TestUtil::RBVersion[0] >= 2 || TestUtil::RBVersion[1] > 8
36
+ # get Win32 Process support
37
+ require 'rubygems'
38
+ gem 'windows-pr', '>= 1.2.2'
39
+ require 'windows/api'
40
+ require 'windows/process'
41
+ require 'windows/error'
42
+ require 'windows/library'
43
+ require 'windows/console'
44
+ require 'windows/handle'
45
+ require 'windows/synchronize'
46
+ require 'windows/thread'
47
+ end
48
+ end
49
+
50
+ module TestUtil
51
+
52
+ class ProcessError < RuntimeError; end
53
+
54
+ if defined?(JRUBY_VERSION)
55
+ class Process
56
+ JRUBY_CMD = File.join(RB_CONFIG['bindir'], RB_CONFIG['RUBY_INSTALL_NAME']).sub(/.*\s.*/m, '"\&"')
57
+ protected
58
+ module Exec
59
+ extend FFI::Library
60
+ ffi_lib 'c'
61
+
62
+ if TestUtil::is_win32?
63
+
64
+ # intptr_t _spawnvpe(int mode,
65
+ # const char *cmdname,
66
+ # const char *const *argv,
67
+ # const char *const *envp);
68
+
69
+ attach_function :_spawnvpe,:_spawnvpe, [:int, :string, :pointer, :pointer], :pointer
70
+
71
+ P_NOWAIT = 1
72
+
73
+ # intptr_t _cwait(int *termstat,
74
+ # intptr_t procHandle,
75
+ # int action);
76
+
77
+ attach_function :_wait, :_cwait, [:pointer, :pointer, :int], :pointer
78
+
79
+ module Kernel32
80
+ extend FFI::Library
81
+ ffi_lib 'kernel32'
82
+ ffi_convention :stdcall
83
+
84
+ attach_function :terminate_process, :TerminateProcess, [:pointer, :uint], :int
85
+ end
86
+
87
+ def self.run(cmd, args)
88
+ argv = ['cmd', '/c']
89
+ argv << "cd #{Dir.getwd.gsub('/', '\\')} && #{Process::JRUBY_CMD} #{$VERBOSE ? '-v' : ''} #{cmd} #{args}"
90
+ spawnp(*argv)
91
+ end
92
+
93
+ def self.spawnp(*args)
94
+ spawn_args = _prepare_spawn_args(args)
95
+ _spawnvpe(*spawn_args)
96
+ end
97
+
98
+ def self.stop(pid)
99
+ kill(pid)
100
+ end
101
+
102
+ def self.kill(pid)
103
+ Kernel32.terminate_process(pid, 0) if pid
104
+ end
105
+
106
+ def self.wait(pid)
107
+ stat_ptr = FFI::MemoryPointer.new(:int, 1)
108
+ tmp_pid = _wait(stat_ptr, pid, 0)
109
+ if tmp_pid==pid
110
+ return [pid, stat_ptr.get_int()]
111
+ else
112
+ return [pid, 0]
113
+ end
114
+ end
115
+
116
+ private
117
+
118
+ def self._prepare_spawn_args(args)
119
+ args_ary = FFI::MemoryPointer.new(:pointer, args.length + 1)
120
+ str_ptrs = args.map {|str| FFI::MemoryPointer.from_string(str)}
121
+ args_ary.put_array_of_pointer(0, str_ptrs)
122
+
123
+ env_ary = FFI::MemoryPointer.new(:pointer, ENV.length + 1)
124
+ env_ptrs = ENV.map {|key,value| FFI::MemoryPointer.from_string("#{key}=#{value}")}
125
+ env_ary.put_array_of_pointer(0, env_ptrs)
126
+
127
+ [P_NOWAIT, args[0], args_ary, env_ary]
128
+ end
129
+ else
130
+ # Extracted from the Spoon gem by Charles Oliver Nutter
131
+
132
+ # int
133
+ # posix_spawnp(pid_t *restrict pid, const char *restrict path,
134
+ # const posix_spawn_file_actions_t *file_actions,
135
+ # const posix_spawnattr_t *restrict attrp, char *const argv[restrict],
136
+ # char *const envp[restrict]);
137
+
138
+ attach_function :_posix_spawnp, :posix_spawnp, [:pointer, :string, :pointer, :pointer, :pointer, :pointer], :int
139
+
140
+ def self.run(cmd, args)
141
+ argv = ['sh', '-c']
142
+ argv << "cd #{Dir.getwd} && #{Process::JRUBY_CMD} #{$VERBOSE ? '-v' : ''} #{cmd} #{args}"
143
+ spawnp(*argv)
144
+ end
145
+
146
+ def self.spawnp(*args)
147
+ spawn_args = _prepare_spawn_args(args)
148
+ _posix_spawnp(*spawn_args)
149
+ spawn_args[0].read_int
150
+ end
151
+
152
+ def self.stop(pid)
153
+ ::Process.kill('TERM', pid) if pid
154
+ end
155
+
156
+ def self.kill(pid)
157
+ ::Process.kill('KILL', pid) if pid
158
+ end
159
+
160
+ def self.wait(pid)
161
+ begin
162
+ tmp, status = ::Process.waitpid2(pid, ::Process::WNOHANG)
163
+ if tmp==pid and status.success? != nil
164
+ return [pid, status.success?() ? 0 : status.exitstatus ]
165
+ end
166
+ return [nil, 0]
167
+ rescue Errno::ECHILD
168
+ return [pid, 0]
169
+ end
170
+ end
171
+
172
+ private
173
+
174
+ def self._prepare_spawn_args(args)
175
+ pid_ptr = FFI::MemoryPointer.new(:pid_t, 1)
176
+
177
+ args_ary = FFI::MemoryPointer.new(:pointer, args.length + 1)
178
+ str_ptrs = args.map {|str| FFI::MemoryPointer.from_string(str)}
179
+ args_ary.put_array_of_pointer(0, str_ptrs)
180
+
181
+ env_ary = FFI::MemoryPointer.new(:pointer, ENV.length + 1)
182
+ env_ptrs = ENV.map {|key,value| FFI::MemoryPointer.from_string("#{key}=#{value}")}
183
+ env_ary.put_array_of_pointer(0, env_ptrs)
184
+
185
+ [pid_ptr, args[0], nil, nil, args_ary, env_ary]
186
+ end
187
+ end
188
+ end
189
+ def initialize(cmd_, arg_)
190
+ @pid = nil
191
+ @exitstatus = nil
192
+ @trd = Thread.start() do
193
+ exit_status = 0
194
+ @pid = Exec.run(cmd_, arg_)
195
+ if @pid
196
+ is_running = true
197
+ while is_running
198
+ sleep 0.01
199
+
200
+ tmp_pid, tmp_status = Exec.wait(@pid)
201
+ if tmp_pid==@pid
202
+ exit_status = tmp_status
203
+ is_running = false
204
+ end
205
+ end
206
+ end
207
+ exit_status
208
+ end
209
+ end
210
+ public
211
+ private_class_method :new
212
+
213
+ def Process.run(cmd_, arg_)
214
+ proc = new(cmd_, arg_)
215
+ sleep(0.1)
216
+ proc.check_status
217
+ return proc
218
+ end
219
+
220
+ def pid
221
+ @pid
222
+ end
223
+
224
+ def check_status
225
+ begin
226
+ unless @trd.alive?
227
+ @exitstatus = @trd.value
228
+ end
229
+ return @trd.alive?
230
+ rescue
231
+ @exitstatus = 0
232
+ return false
233
+ end
234
+ end
235
+
236
+ def exitstatus
237
+ @exitstatus
238
+ end
239
+
240
+ def is_running?; @exitstatus.nil?; end
241
+ def has_error? ; @trd.status.nil? or (!self.is_running? and self.exitstatus!=0) ;end
242
+
243
+ def stop
244
+ Exec.stop(@pid)
245
+ end
246
+
247
+ def kill
248
+ Exec.kill(@pid)
249
+ end
250
+ end # Process
251
+ elsif is_win32? && TestUtil::RBVersion[0] < 2 && TestUtil::RBVersion[1] < 9
252
+ class Process
253
+ include Windows::Error
254
+ include Windows::Library
255
+ include Windows::Console
256
+ include Windows::Handle
257
+ include Windows::Synchronize
258
+ include Windows::Thread
259
+ extend Windows::Error
260
+ extend Windows::Library
261
+ extend Windows::Console
262
+ extend Windows::Handle
263
+ extend Windows::Synchronize
264
+ extend Windows::Thread
265
+
266
+ protected
267
+ # Used by Process.create
268
+ ProcessInfo = Struct.new("ProcessInfo",
269
+ :process_handle,
270
+ :thread_handle,
271
+ :process_id,
272
+ :thread_id
273
+ )
274
+
275
+ module WinAPI
276
+ Windows::API.auto_namespace = 'TestUtil::Process::WinAPI'
277
+ Windows::API.auto_constant = true
278
+ Windows::API.auto_method = true
279
+ Windows::API.auto_unicode = true
280
+
281
+ STILL_ACTIVE = 259
282
+
283
+ Windows::API.new('CreateProcess', 'PPPPLLLPPP', 'B')
284
+ Windows::API.new('GetExitCodeProcess', 'LP', 'B')
285
+ end
286
+
287
+ include WinAPI
288
+ extend WinAPI
289
+
290
+ def Process.create(cmd_)
291
+ startinfo = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
292
+ startinfo = startinfo.pack('LLLLLLLLLLLLSSLLLL')
293
+ procinfo = [0,0,0,0].pack('LLLL')
294
+
295
+ bool = CreateProcess(
296
+ 0, # App name
297
+ cmd_, # Command line
298
+ 0, # Process attributes
299
+ 0, # Thread attributes
300
+ 1, # Inherit handles?
301
+ 0, # Creation flags
302
+ 0, # Environment
303
+ 0, # Working directory
304
+ startinfo, # Startup Info
305
+ procinfo # Process Info
306
+ )
307
+
308
+ unless bool
309
+ raise ProcessError, "CreateProcess() failed: ", get_last_error
310
+ end
311
+
312
+ ProcessInfo.new(
313
+ procinfo[0,4].unpack('L').first, # hProcess
314
+ procinfo[4,4].unpack('L').first, # hThread
315
+ procinfo[8,4].unpack('L').first, # hProcessId
316
+ procinfo[12,4].unpack('L').first # hThreadId
317
+ )
318
+ end
319
+
320
+ def Process.waitpi(pi_)
321
+ exit_code = [0].pack('L')
322
+ if GetExitCodeProcess(pi_.process_handle, exit_code)
323
+ exit_code = exit_code.unpack('L').first
324
+ return exit_code == STILL_ACTIVE ? nil : exit_code
325
+ else
326
+ CloseHandle(pi_.process_handle) unless pi_.process_handle == INVALID_HANDLE_VALUE
327
+ pi_.process_handle = INVALID_HANDLE_VALUE
328
+ raise ProcessError, "GetExitCodeProcess failed: ", get_last_error
329
+ end
330
+ end
331
+
332
+ def Process.stop(pi_)
333
+ if pi_.process_handle != INVALID_HANDLE_VALUE
334
+ thread_id = [0].pack('L')
335
+ dll = 'kernel32'
336
+ proc = 'ExitProcess'
337
+
338
+ mh = GetModuleHandle(dll)
339
+ pa = GetProcAddress(mh, proc)
340
+ thread = CreateRemoteThread(
341
+ pi_.process_handle,
342
+ 0,
343
+ 0,
344
+ pa,
345
+ 0,
346
+ 0,
347
+ thread_id
348
+ )
349
+
350
+ if thread
351
+ WaitForSingleObject(thread, 5)
352
+ CloseHandle(pi_.process_handle)
353
+ pi_.process_handle = INVALID_HANDLE_VALUE
354
+ else
355
+ CloseHandle(pi_.process_handle)
356
+ pi_.process_handle = INVALID_HANDLE_VALUE
357
+ raise ProcessError, get_last_error
358
+ end
359
+ end
360
+ end
361
+
362
+ def Process.kill(pi_)
363
+ if pi_.process_handle != INVALID_HANDLE_VALUE
364
+ if TerminateProcess(pi_.process_handle, pi_.process_id)
365
+ CloseHandle(pi_.process_handle)
366
+ pi_.process_handle = INVALID_HANDLE_VALUE
367
+ else
368
+ CloseHandle(pi_.process_handle)
369
+ pi_.process_handle = INVALID_HANDLE_VALUE
370
+ raise ProcessError, get_last_error
371
+ end
372
+ end
373
+ end
374
+
375
+ def initialize(pi_)
376
+ @pi = pi_
377
+ @exitstatus = nil
378
+ end
379
+ public
380
+ private_class_method :new
381
+ def Process.run(cmd_, arg_)
382
+ pi = self.create("#{RB_CONFIG['RUBY_INSTALL_NAME']} #{$VERBOSE ? '-v' : ''} #{cmd_} #{arg_}")
383
+ proc = new(pi)
384
+ sleep(0.1)
385
+ proc.check_status
386
+ return proc
387
+ end
388
+
389
+ def pid; @pi.process_id; end
390
+
391
+ def check_status
392
+ @exitstatus ||= self.class.waitpi(@pi)
393
+ return @exitstatus.nil?
394
+ end
395
+
396
+ def exitstatus; @exitstatus; end
397
+
398
+ def is_running?; @exitstatus.nil?; end
399
+ def has_error?; !@exitstatus.nil? and (@exitstatus != 0); end
400
+
401
+ def stop
402
+ self.class.stop(@pi)
403
+ @exitstatus = 0
404
+ end
405
+
406
+ def kill
407
+ self.class.kill(@pi)
408
+ end
409
+ end # Process
410
+ else # !win32
411
+ class Process
412
+ protected
413
+ def initialize(pid_)
414
+ @pid = pid_
415
+ @status = nil
416
+ @exitstatus = nil
417
+ end
418
+ public
419
+ private_class_method :new
420
+ unless TestUtil::RBVersion[0] >= 2 || TestUtil::RBVersion[1] > 8
421
+ def Process.run(cmd_, arg_)
422
+ pid = ::Process.fork do
423
+ ::Kernel.exec("#{RB_CONFIG['RUBY_INSTALL_NAME']} #{$VERBOSE ? '-v' : ''} #{cmd_} #{arg_}")
424
+ end
425
+ proc = new(pid)
426
+ sleep(0.1)
427
+ proc.check_status
428
+ return proc
429
+ end
430
+ else
431
+ def Process.run(cmd_, arg_)
432
+ pid = ::Kernel.spawn("#{RB_CONFIG['RUBY_INSTALL_NAME']} #{$VERBOSE ? '-v' : ''} #{cmd_} #{arg_}")
433
+ proc = new(pid)
434
+ sleep(0.1)
435
+ proc.check_status
436
+ return proc
437
+ end
438
+ end
439
+
440
+ attr_reader :pid
441
+
442
+ def check_status
443
+ begin
444
+ tmp, @status = ::Process.waitpid2(@pid, ::Process::WNOHANG)
445
+ if tmp==@pid and @status.success? == false
446
+ @exitstatus = @status.exitstatus
447
+ return false
448
+ end
449
+ return true
450
+ rescue Errno::ECHILD
451
+ @exitstatus = 0
452
+ return false
453
+ end
454
+ end
455
+
456
+ def exitstatus
457
+ @exitstatus
458
+ end
459
+
460
+ def is_running?; @exitstatus.nil?; end
461
+ def has_error?; !@status.nil? and (@status.success? == false); end
462
+
463
+ def stop
464
+ ::Process.kill('SIGTERM', @pid)
465
+ end
466
+
467
+ def kill
468
+ ::Process.kill('SIGKILL', @pid)
469
+ end
470
+ end # Process
471
+ end
472
+
473
+ class Test
474
+ def initialize
475
+ @proc = nil
476
+ @cmd = ""
477
+ end
478
+
479
+ def run(cmd_, arg_)
480
+ @cmd = cmd_
481
+ begin
482
+ @proc = Process.run(cmd_, arg_)
483
+ rescue ProcessError
484
+ STDERR.puts "ERROR: failed to run <#{@cmd}>"
485
+ return false
486
+ end
487
+ true
488
+ end
489
+
490
+ def pid; @proc.pid; end
491
+ def is_running?; @proc.is_running?; end
492
+ def exit_status; @proc.exitstatus; end
493
+
494
+ def wait(timeout, check_exit=true)
495
+ t = Time.now
496
+ begin
497
+ if @proc.check_status
498
+ if (Time.now() - t) >= timeout.to_f
499
+ STDERR.puts "ERROR: KILLING #{@cmd}"
500
+ @proc.kill
501
+ return 255
502
+ end
503
+ sleep(0.1)
504
+ end
505
+ end until !@proc.is_running?
506
+ if check_exit && @proc.has_error?
507
+ STDERR.puts "ERROR: #{@cmd} returned: #{@proc.exitstatus}"
508
+ return @proc.exitstatus != 0 ? @proc.exitstatus : 255
509
+ end
510
+ return 0
511
+ end
512
+
513
+ def wait_term(timeout)
514
+ @proc.stop
515
+ self.wait(timeout, false)
516
+ end
517
+
518
+ def kill(timeout)
519
+ @proc.kill
520
+ self.wait(timeout, false)
521
+ end
522
+
523
+ end
524
+
525
+ def TestUtil.wait_for_file(filename, timeout)
526
+ t = Time.now
527
+ while !File.readable?(filename) do
528
+ sleep(0.1)
529
+ if (Time.now() - t) >= timeout.to_f
530
+ STDERR.puts "ERROR: could not find file '#{filename}'"
531
+ return false
532
+ end
533
+ end
534
+ true
535
+ end
536
+
537
+ def TestUtil.remove_file(filename)
538
+ File.delete(filename) if File.exists?(filename)
539
+ end
540
+
541
+ end
542
+