win32-process 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES +239 -231
- data/MANIFEST +9 -9
- data/README +76 -76
- data/Rakefile +63 -58
- data/lib/win32/process.rb +937 -894
- data/lib/win32/process/constants.rb +110 -105
- data/lib/win32/process/functions.rb +78 -77
- data/lib/win32/process/helper.rb +13 -13
- data/lib/win32/process/structs.rb +118 -118
- data/test/test_win32_process.rb +353 -319
- data/test/test_win32_process_kill.rb +159 -144
- data/win32-process.gemspec +27 -27
- metadata +16 -20
data/test/test_win32_process.rb
CHANGED
@@ -1,319 +1,353 @@
|
|
1
|
-
###############################################################################
|
2
|
-
# test_win32_process.rb
|
3
|
-
#
|
4
|
-
# Test suite for the win32-process library. This test suite will start
|
5
|
-
# at least two instances of Notepad on your system, which will then
|
6
|
-
# be killed. Requires the sys-proctable library.
|
7
|
-
#
|
8
|
-
# I haven't added a lot of test cases for fork/wait because it's difficult
|
9
|
-
# to run such tests without causing havoc with Test::Unit itself. Ideas
|
10
|
-
# welcome.
|
11
|
-
#
|
12
|
-
# You should run this test case via the 'rake test' task.
|
13
|
-
###############################################################################
|
14
|
-
require 'test-unit'
|
15
|
-
require 'win32/process'
|
16
|
-
|
17
|
-
class TC_Win32Process < Test::Unit::TestCase
|
18
|
-
def self.startup
|
19
|
-
@@pids = []
|
20
|
-
@@jruby = RUBY_PLATFORM == 'java'
|
21
|
-
end
|
22
|
-
|
23
|
-
def setup
|
24
|
-
@priority = Process::BELOW_NORMAL_PRIORITY_CLASS
|
25
|
-
end
|
26
|
-
|
27
|
-
test "win32-process version is set to the correct value" do
|
28
|
-
assert_equal('0.7.
|
29
|
-
end
|
30
|
-
|
31
|
-
test "create basic functionality" do
|
32
|
-
assert_respond_to(Process, :create)
|
33
|
-
end
|
34
|
-
|
35
|
-
test "create with common flags works as expected" do
|
36
|
-
assert_nothing_raised{
|
37
|
-
@@pids << Process.create(
|
38
|
-
:app_name => "notepad.exe",
|
39
|
-
:creation_flags => Process::DETACHED_PROCESS,
|
40
|
-
:process_inherit => false,
|
41
|
-
:thread_inherit => true,
|
42
|
-
:cwd => "C:\\"
|
43
|
-
).process_id
|
44
|
-
}
|
45
|
-
|
46
|
-
assert_nothing_raised{ Process.kill(9, @@pids.pop) }
|
47
|
-
end
|
48
|
-
|
49
|
-
test "create requires a hash argument" do
|
50
|
-
assert_raise(TypeError){ Process.create("bogusapp.exe") }
|
51
|
-
end
|
52
|
-
|
53
|
-
test "create does not accept invalid keys" do
|
54
|
-
assert_raise(ArgumentError){ Process.create(:bogus => 'test.exe') }
|
55
|
-
assert_raise_message("invalid key 'bogus'"){
|
56
|
-
Process.create(:bogus => 'test.exe')
|
57
|
-
}
|
58
|
-
end
|
59
|
-
|
60
|
-
test "create does not accept invalid startup_info keys" do
|
61
|
-
assert_raise(ArgumentError){
|
62
|
-
Process.create(:startup_info => {:foo => 'test'})
|
63
|
-
}
|
64
|
-
assert_raise_message("invalid startup_info key 'foo'"){
|
65
|
-
Process.create(:startup_info => {:foo => 'test'})
|
66
|
-
}
|
67
|
-
end
|
68
|
-
|
69
|
-
test "create raises an error if the executable cannot be found" do
|
70
|
-
assert_raise(Errno::ENOENT){ Process.create(:app_name => "bogusapp.exe") }
|
71
|
-
end
|
72
|
-
|
73
|
-
test "create passes local environment when environment is not specified" do
|
74
|
-
omit_if(@@jruby)
|
75
|
-
stdout_read, stdout_write = IO.pipe
|
76
|
-
|
77
|
-
ENV['AARDVARK'] = 'B'
|
78
|
-
assert_nothing_raised {
|
79
|
-
Process.create(
|
80
|
-
:app_name => 'cmd.exe /c echo %AARDVARK%',
|
81
|
-
:creation_flags => Process::DETACHED_PROCESS,
|
82
|
-
:startup_info => { :stdout => stdout_write }
|
83
|
-
)
|
84
|
-
}
|
85
|
-
|
86
|
-
stdout_write.close
|
87
|
-
assert_equal('B', stdout_read.read.chomp)
|
88
|
-
end
|
89
|
-
|
90
|
-
test "create does not pass local environment when environment is specified" do
|
91
|
-
omit_if(@@jruby)
|
92
|
-
stdout_read, stdout_write = IO.pipe
|
93
|
-
|
94
|
-
ENV['AARDVARK'] = 'B'
|
95
|
-
assert_nothing_raised {
|
96
|
-
Process.create(
|
97
|
-
:app_name => 'cmd.exe /c echo %AARDVARK%',
|
98
|
-
:creation_flags => Process::DETACHED_PROCESS,
|
99
|
-
:environment => "",
|
100
|
-
:startup_info => { :stdout => stdout_write }
|
101
|
-
)
|
102
|
-
}
|
103
|
-
|
104
|
-
stdout_write.close
|
105
|
-
assert_equal('%AARDVARK%', stdout_read.read.chomp)
|
106
|
-
end
|
107
|
-
|
108
|
-
test "create supports :environment as a string" do
|
109
|
-
omit_if(@@jruby)
|
110
|
-
stdout_read, stdout_write = IO.pipe
|
111
|
-
|
112
|
-
assert_nothing_raised {
|
113
|
-
Process.create(
|
114
|
-
:app_name => 'cmd.exe /c echo %A% %C%',
|
115
|
-
:creation_flags => Process::DETACHED_PROCESS,
|
116
|
-
:environment => "A=B;C=D",
|
117
|
-
:startup_info => { :stdout => stdout_write }
|
118
|
-
)
|
119
|
-
}
|
120
|
-
|
121
|
-
stdout_write.close
|
122
|
-
assert_equal("B D", stdout_read.read.chomp)
|
123
|
-
end
|
124
|
-
|
125
|
-
test "create supports :environment as an array" do
|
126
|
-
omit_if(@@jruby)
|
127
|
-
stdout_read, stdout_write = IO.pipe
|
128
|
-
|
129
|
-
assert_nothing_raised {
|
130
|
-
Process.create(
|
131
|
-
:app_name => 'cmd.exe /c echo %A% %C%',
|
132
|
-
:creation_flags => Process::DETACHED_PROCESS,
|
133
|
-
:environment => [ "A=B;X;", "C=;D;Y" ],
|
134
|
-
:startup_info => { :stdout => stdout_write }
|
135
|
-
)
|
136
|
-
}
|
137
|
-
|
138
|
-
stdout_write.close
|
139
|
-
assert_equal("B;X; ;D;Y", stdout_read.read.chomp)
|
140
|
-
end
|
141
|
-
|
142
|
-
test "create supports empty :environment string" do
|
143
|
-
assert_nothing_raised {
|
144
|
-
Process.create(
|
145
|
-
:creation_flags => Process::DETACHED_PROCESS,
|
146
|
-
:app_name => 'cmd.exe',
|
147
|
-
:environment => ''
|
148
|
-
)
|
149
|
-
}
|
150
|
-
end
|
151
|
-
|
152
|
-
test "create supports empty :environment array" do
|
153
|
-
assert_nothing_raised {
|
154
|
-
Process.create(
|
155
|
-
:creation_flags => Process::DETACHED_PROCESS,
|
156
|
-
:app_name => 'cmd.exe',
|
157
|
-
:environment => []
|
158
|
-
)
|
159
|
-
}
|
160
|
-
end
|
161
|
-
|
162
|
-
test "uid basic functionality" do
|
163
|
-
assert_respond_to(Process, :uid)
|
164
|
-
assert_kind_of(Fixnum, Process.uid)
|
165
|
-
end
|
166
|
-
|
167
|
-
test "uid accepts a boolean argument" do
|
168
|
-
assert_nothing_raised{ Process.uid(true) }
|
169
|
-
assert_nothing_raised{ Process.uid(true) }
|
170
|
-
end
|
171
|
-
|
172
|
-
test "uid returns a string if its argument is true" do
|
173
|
-
assert_kind_of(String, Process.uid(true))
|
174
|
-
end
|
175
|
-
|
176
|
-
test "uid accepts a maximum of one argument" do
|
177
|
-
assert_raise(ArgumentError){ Process.uid(true, true) }
|
178
|
-
end
|
179
|
-
|
180
|
-
test "argument to uid must be a boolean" do
|
181
|
-
assert_raise(TypeError){ Process.uid('test') }
|
182
|
-
end
|
183
|
-
|
184
|
-
test "getpriority basic functionality" do
|
185
|
-
assert_respond_to(Process, :getpriority)
|
186
|
-
assert_nothing_raised{ Process.getpriority(Process::PRIO_PROCESS, Process.pid) }
|
187
|
-
assert_kind_of(Fixnum, Process.getpriority(Process::PRIO_PROCESS, Process.pid))
|
188
|
-
end
|
189
|
-
|
190
|
-
test "getpriority treats an int argument of zero as the current process" do
|
191
|
-
assert_nothing_raised{ Process.getpriority(0, 0) }
|
192
|
-
end
|
193
|
-
|
194
|
-
test "getpriority requires both a kind and an int" do
|
195
|
-
assert_raise(ArgumentError){ Process.getpriority }
|
196
|
-
assert_raise(ArgumentError){ Process.getpriority(Process::PRIO_PROCESS) }
|
197
|
-
end
|
198
|
-
|
199
|
-
test "getpriority requires integer arguments" do
|
200
|
-
assert_raise(TypeError){ Process.getpriority('test', 0) }
|
201
|
-
assert_raise(TypeError){ Process.getpriority(Process::PRIO_PROCESS, 'test') }
|
202
|
-
end
|
203
|
-
|
204
|
-
test "setpriority basic functionality" do
|
205
|
-
assert_respond_to(Process, :setpriority)
|
206
|
-
assert_nothing_raised{ Process.setpriority(0, Process.pid, @priority) }
|
207
|
-
assert_equal(@priority, Process.getpriority(0, Process.pid))
|
208
|
-
end
|
209
|
-
|
210
|
-
test "setpriority returns zero on success" do
|
211
|
-
assert_equal(0, Process.setpriority(0, Process.pid, @priority))
|
212
|
-
end
|
213
|
-
|
214
|
-
test "setpriority treats an int argument of zero as the current process" do
|
215
|
-
assert_equal(0, Process.setpriority(0, 0, @priority))
|
216
|
-
end
|
217
|
-
|
218
|
-
test "setpriority requires at least three arguments" do
|
219
|
-
assert_raise(ArgumentError){ Process.setpriority }
|
220
|
-
assert_raise(ArgumentError){ Process.setpriority(0) }
|
221
|
-
assert_raise(ArgumentError){ Process.setpriority(0, 0) }
|
222
|
-
end
|
223
|
-
|
224
|
-
test "arguments to setpriority must be numeric" do
|
225
|
-
assert_raise(TypeError){ Process.setpriority('test', 0, @priority) }
|
226
|
-
assert_raise(TypeError){ Process.setpriority(0, 'test', @priority) }
|
227
|
-
assert_raise(TypeError){ Process.setpriority(0, 0, 'test') }
|
228
|
-
end
|
229
|
-
|
230
|
-
test "custom creation constants are defined" do
|
231
|
-
assert_not_nil(Process::CREATE_DEFAULT_ERROR_MODE)
|
232
|
-
assert_not_nil(Process::CREATE_NEW_CONSOLE)
|
233
|
-
assert_not_nil(Process::CREATE_NEW_PROCESS_GROUP)
|
234
|
-
assert_not_nil(Process::CREATE_NO_WINDOW)
|
235
|
-
assert_not_nil(Process::CREATE_SEPARATE_WOW_VDM)
|
236
|
-
assert_not_nil(Process::CREATE_SHARED_WOW_VDM)
|
237
|
-
assert_not_nil(Process::CREATE_SUSPENDED)
|
238
|
-
assert_not_nil(Process::CREATE_UNICODE_ENVIRONMENT)
|
239
|
-
assert_not_nil(Process::DEBUG_ONLY_THIS_PROCESS)
|
240
|
-
assert_not_nil(Process::DEBUG_PROCESS)
|
241
|
-
assert_not_nil(Process::DETACHED_PROCESS)
|
242
|
-
end
|
243
|
-
|
244
|
-
test "getrlimit basic functionality" do
|
245
|
-
assert_respond_to(Process, :getrlimit)
|
246
|
-
assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
|
247
|
-
assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_FSIZE) }
|
248
|
-
end
|
249
|
-
|
250
|
-
test "getrlimit returns an array of two numeric elements" do
|
251
|
-
assert_kind_of(Array, Process.getrlimit(Process::RLIMIT_CPU))
|
252
|
-
assert_equal(2, Process.getrlimit(Process::RLIMIT_CPU).length)
|
253
|
-
assert_kind_of(Integer, Process.getrlimit(Process::RLIMIT_CPU).first)
|
254
|
-
end
|
255
|
-
|
256
|
-
test "getrlimit can be called multiple times without issue" do
|
257
|
-
assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
|
258
|
-
assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
|
259
|
-
assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
|
260
|
-
end
|
261
|
-
|
262
|
-
test "getrlimit requires a valid resource value" do
|
263
|
-
assert_raise(ArgumentError){ Process.getrlimit(9999) }
|
264
|
-
end
|
265
|
-
|
266
|
-
test "setrlimit basic functionality" do
|
267
|
-
assert_respond_to(Process, :setrlimit)
|
268
|
-
assert_nothing_raised{ Process.setrlimit(Process::RLIMIT_CPU, 1000000) }
|
269
|
-
end
|
270
|
-
|
271
|
-
test "setrlimit returns nil on success" do
|
272
|
-
assert_nil(Process.setrlimit(Process::RLIMIT_CPU, 1000000))
|
273
|
-
end
|
274
|
-
|
275
|
-
test "setrlimit sets the resource limit as expected" do
|
276
|
-
assert_nothing_raised{ Process.setrlimit(Process::RLIMIT_CPU, 1000000) }
|
277
|
-
assert_equal([1000000, 1000000], Process.getrlimit(Process::RLIMIT_CPU))
|
278
|
-
end
|
279
|
-
|
280
|
-
test "setrlimit raises an error if the resource value is invalid" do
|
281
|
-
assert_raise(ArgumentError){ Process.setrlimit(9999, 100) }
|
282
|
-
end
|
283
|
-
|
284
|
-
test "is_job basic functionality" do
|
285
|
-
assert_respond_to(Process, :job?)
|
286
|
-
assert_nothing_raised{ Process.job? }
|
287
|
-
end
|
288
|
-
|
289
|
-
test "is_job returns a boolean value" do
|
290
|
-
assert_boolean(Process.job?)
|
291
|
-
end
|
292
|
-
|
293
|
-
test "is_job does not accept any arguments" do
|
294
|
-
assert_raise(ArgumentError){ Process.job?(Process.pid) }
|
295
|
-
end
|
296
|
-
|
297
|
-
test "volume_type is a private method" do
|
298
|
-
assert_not_respond_to(Process, :volume_type)
|
299
|
-
end
|
300
|
-
|
301
|
-
test "ffi functions are private" do
|
302
|
-
assert_not_respond_to(Process, :CloseHandle)
|
303
|
-
assert_not_respond_to(Process, :GetCurrentProcess)
|
304
|
-
assert_not_respond_to(Process, :GetProcessAffinityMask)
|
305
|
-
assert_not_respond_to(Process, :GetPriorityClass)
|
306
|
-
assert_not_respond_to(Process, :IsProcessInJob)
|
307
|
-
assert_not_respond_to(Process, :OpenProcess)
|
308
|
-
assert_not_respond_to(Process, :SetHandleInformation)
|
309
|
-
assert_not_respond_to(Process, :SetPriorityClass)
|
310
|
-
end
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
end
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
1
|
+
###############################################################################
|
2
|
+
# test_win32_process.rb
|
3
|
+
#
|
4
|
+
# Test suite for the win32-process library. This test suite will start
|
5
|
+
# at least two instances of Notepad on your system, which will then
|
6
|
+
# be killed. Requires the sys-proctable library.
|
7
|
+
#
|
8
|
+
# I haven't added a lot of test cases for fork/wait because it's difficult
|
9
|
+
# to run such tests without causing havoc with Test::Unit itself. Ideas
|
10
|
+
# welcome.
|
11
|
+
#
|
12
|
+
# You should run this test case via the 'rake test' task.
|
13
|
+
###############################################################################
|
14
|
+
require 'test-unit'
|
15
|
+
require 'win32/process'
|
16
|
+
|
17
|
+
class TC_Win32Process < Test::Unit::TestCase
|
18
|
+
def self.startup
|
19
|
+
@@pids = []
|
20
|
+
@@jruby = RUBY_PLATFORM == 'java'
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup
|
24
|
+
@priority = Process::BELOW_NORMAL_PRIORITY_CLASS
|
25
|
+
end
|
26
|
+
|
27
|
+
test "win32-process version is set to the correct value" do
|
28
|
+
assert_equal('0.7.3', Process::WIN32_PROCESS_VERSION)
|
29
|
+
end
|
30
|
+
|
31
|
+
test "create basic functionality" do
|
32
|
+
assert_respond_to(Process, :create)
|
33
|
+
end
|
34
|
+
|
35
|
+
test "create with common flags works as expected" do
|
36
|
+
assert_nothing_raised{
|
37
|
+
@@pids << Process.create(
|
38
|
+
:app_name => "notepad.exe",
|
39
|
+
:creation_flags => Process::DETACHED_PROCESS,
|
40
|
+
:process_inherit => false,
|
41
|
+
:thread_inherit => true,
|
42
|
+
:cwd => "C:\\"
|
43
|
+
).process_id
|
44
|
+
}
|
45
|
+
|
46
|
+
assert_nothing_raised{ Process.kill(9, @@pids.pop) }
|
47
|
+
end
|
48
|
+
|
49
|
+
test "create requires a hash argument" do
|
50
|
+
assert_raise(TypeError){ Process.create("bogusapp.exe") }
|
51
|
+
end
|
52
|
+
|
53
|
+
test "create does not accept invalid keys" do
|
54
|
+
assert_raise(ArgumentError){ Process.create(:bogus => 'test.exe') }
|
55
|
+
assert_raise_message("invalid key 'bogus'"){
|
56
|
+
Process.create(:bogus => 'test.exe')
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
test "create does not accept invalid startup_info keys" do
|
61
|
+
assert_raise(ArgumentError){
|
62
|
+
Process.create(:startup_info => {:foo => 'test'})
|
63
|
+
}
|
64
|
+
assert_raise_message("invalid startup_info key 'foo'"){
|
65
|
+
Process.create(:startup_info => {:foo => 'test'})
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
test "create raises an error if the executable cannot be found" do
|
70
|
+
assert_raise(Errno::ENOENT){ Process.create(:app_name => "bogusapp.exe") }
|
71
|
+
end
|
72
|
+
|
73
|
+
test "create passes local environment when environment is not specified" do
|
74
|
+
omit_if(@@jruby)
|
75
|
+
stdout_read, stdout_write = IO.pipe
|
76
|
+
|
77
|
+
ENV['AARDVARK'] = 'B'
|
78
|
+
assert_nothing_raised {
|
79
|
+
Process.create(
|
80
|
+
:app_name => 'cmd.exe /c echo %AARDVARK%',
|
81
|
+
:creation_flags => Process::DETACHED_PROCESS,
|
82
|
+
:startup_info => { :stdout => stdout_write }
|
83
|
+
)
|
84
|
+
}
|
85
|
+
|
86
|
+
stdout_write.close
|
87
|
+
assert_equal('B', stdout_read.read.chomp)
|
88
|
+
end
|
89
|
+
|
90
|
+
test "create does not pass local environment when environment is specified" do
|
91
|
+
omit_if(@@jruby)
|
92
|
+
stdout_read, stdout_write = IO.pipe
|
93
|
+
|
94
|
+
ENV['AARDVARK'] = 'B'
|
95
|
+
assert_nothing_raised {
|
96
|
+
Process.create(
|
97
|
+
:app_name => 'cmd.exe /c echo %AARDVARK%',
|
98
|
+
:creation_flags => Process::DETACHED_PROCESS,
|
99
|
+
:environment => "",
|
100
|
+
:startup_info => { :stdout => stdout_write }
|
101
|
+
)
|
102
|
+
}
|
103
|
+
|
104
|
+
stdout_write.close
|
105
|
+
assert_equal('%AARDVARK%', stdout_read.read.chomp)
|
106
|
+
end
|
107
|
+
|
108
|
+
test "create supports :environment as a string" do
|
109
|
+
omit_if(@@jruby)
|
110
|
+
stdout_read, stdout_write = IO.pipe
|
111
|
+
|
112
|
+
assert_nothing_raised {
|
113
|
+
Process.create(
|
114
|
+
:app_name => 'cmd.exe /c echo %A% %C%',
|
115
|
+
:creation_flags => Process::DETACHED_PROCESS,
|
116
|
+
:environment => "A=B;C=D",
|
117
|
+
:startup_info => { :stdout => stdout_write }
|
118
|
+
)
|
119
|
+
}
|
120
|
+
|
121
|
+
stdout_write.close
|
122
|
+
assert_equal("B D", stdout_read.read.chomp)
|
123
|
+
end
|
124
|
+
|
125
|
+
test "create supports :environment as an array" do
|
126
|
+
omit_if(@@jruby)
|
127
|
+
stdout_read, stdout_write = IO.pipe
|
128
|
+
|
129
|
+
assert_nothing_raised {
|
130
|
+
Process.create(
|
131
|
+
:app_name => 'cmd.exe /c echo %A% %C%',
|
132
|
+
:creation_flags => Process::DETACHED_PROCESS,
|
133
|
+
:environment => [ "A=B;X;", "C=;D;Y" ],
|
134
|
+
:startup_info => { :stdout => stdout_write }
|
135
|
+
)
|
136
|
+
}
|
137
|
+
|
138
|
+
stdout_write.close
|
139
|
+
assert_equal("B;X; ;D;Y", stdout_read.read.chomp)
|
140
|
+
end
|
141
|
+
|
142
|
+
test "create supports empty :environment string" do
|
143
|
+
assert_nothing_raised {
|
144
|
+
Process.create(
|
145
|
+
:creation_flags => Process::DETACHED_PROCESS,
|
146
|
+
:app_name => 'cmd.exe',
|
147
|
+
:environment => ''
|
148
|
+
)
|
149
|
+
}
|
150
|
+
end
|
151
|
+
|
152
|
+
test "create supports empty :environment array" do
|
153
|
+
assert_nothing_raised {
|
154
|
+
Process.create(
|
155
|
+
:creation_flags => Process::DETACHED_PROCESS,
|
156
|
+
:app_name => 'cmd.exe',
|
157
|
+
:environment => []
|
158
|
+
)
|
159
|
+
}
|
160
|
+
end
|
161
|
+
|
162
|
+
test "uid basic functionality" do
|
163
|
+
assert_respond_to(Process, :uid)
|
164
|
+
assert_kind_of(Fixnum, Process.uid)
|
165
|
+
end
|
166
|
+
|
167
|
+
test "uid accepts a boolean argument" do
|
168
|
+
assert_nothing_raised{ Process.uid(true) }
|
169
|
+
assert_nothing_raised{ Process.uid(true) }
|
170
|
+
end
|
171
|
+
|
172
|
+
test "uid returns a string if its argument is true" do
|
173
|
+
assert_kind_of(String, Process.uid(true))
|
174
|
+
end
|
175
|
+
|
176
|
+
test "uid accepts a maximum of one argument" do
|
177
|
+
assert_raise(ArgumentError){ Process.uid(true, true) }
|
178
|
+
end
|
179
|
+
|
180
|
+
test "argument to uid must be a boolean" do
|
181
|
+
assert_raise(TypeError){ Process.uid('test') }
|
182
|
+
end
|
183
|
+
|
184
|
+
test "getpriority basic functionality" do
|
185
|
+
assert_respond_to(Process, :getpriority)
|
186
|
+
assert_nothing_raised{ Process.getpriority(Process::PRIO_PROCESS, Process.pid) }
|
187
|
+
assert_kind_of(Fixnum, Process.getpriority(Process::PRIO_PROCESS, Process.pid))
|
188
|
+
end
|
189
|
+
|
190
|
+
test "getpriority treats an int argument of zero as the current process" do
|
191
|
+
assert_nothing_raised{ Process.getpriority(0, 0) }
|
192
|
+
end
|
193
|
+
|
194
|
+
test "getpriority requires both a kind and an int" do
|
195
|
+
assert_raise(ArgumentError){ Process.getpriority }
|
196
|
+
assert_raise(ArgumentError){ Process.getpriority(Process::PRIO_PROCESS) }
|
197
|
+
end
|
198
|
+
|
199
|
+
test "getpriority requires integer arguments" do
|
200
|
+
assert_raise(TypeError){ Process.getpriority('test', 0) }
|
201
|
+
assert_raise(TypeError){ Process.getpriority(Process::PRIO_PROCESS, 'test') }
|
202
|
+
end
|
203
|
+
|
204
|
+
test "setpriority basic functionality" do
|
205
|
+
assert_respond_to(Process, :setpriority)
|
206
|
+
assert_nothing_raised{ Process.setpriority(0, Process.pid, @priority) }
|
207
|
+
assert_equal(@priority, Process.getpriority(0, Process.pid))
|
208
|
+
end
|
209
|
+
|
210
|
+
test "setpriority returns zero on success" do
|
211
|
+
assert_equal(0, Process.setpriority(0, Process.pid, @priority))
|
212
|
+
end
|
213
|
+
|
214
|
+
test "setpriority treats an int argument of zero as the current process" do
|
215
|
+
assert_equal(0, Process.setpriority(0, 0, @priority))
|
216
|
+
end
|
217
|
+
|
218
|
+
test "setpriority requires at least three arguments" do
|
219
|
+
assert_raise(ArgumentError){ Process.setpriority }
|
220
|
+
assert_raise(ArgumentError){ Process.setpriority(0) }
|
221
|
+
assert_raise(ArgumentError){ Process.setpriority(0, 0) }
|
222
|
+
end
|
223
|
+
|
224
|
+
test "arguments to setpriority must be numeric" do
|
225
|
+
assert_raise(TypeError){ Process.setpriority('test', 0, @priority) }
|
226
|
+
assert_raise(TypeError){ Process.setpriority(0, 'test', @priority) }
|
227
|
+
assert_raise(TypeError){ Process.setpriority(0, 0, 'test') }
|
228
|
+
end
|
229
|
+
|
230
|
+
test "custom creation constants are defined" do
|
231
|
+
assert_not_nil(Process::CREATE_DEFAULT_ERROR_MODE)
|
232
|
+
assert_not_nil(Process::CREATE_NEW_CONSOLE)
|
233
|
+
assert_not_nil(Process::CREATE_NEW_PROCESS_GROUP)
|
234
|
+
assert_not_nil(Process::CREATE_NO_WINDOW)
|
235
|
+
assert_not_nil(Process::CREATE_SEPARATE_WOW_VDM)
|
236
|
+
assert_not_nil(Process::CREATE_SHARED_WOW_VDM)
|
237
|
+
assert_not_nil(Process::CREATE_SUSPENDED)
|
238
|
+
assert_not_nil(Process::CREATE_UNICODE_ENVIRONMENT)
|
239
|
+
assert_not_nil(Process::DEBUG_ONLY_THIS_PROCESS)
|
240
|
+
assert_not_nil(Process::DEBUG_PROCESS)
|
241
|
+
assert_not_nil(Process::DETACHED_PROCESS)
|
242
|
+
end
|
243
|
+
|
244
|
+
test "getrlimit basic functionality" do
|
245
|
+
assert_respond_to(Process, :getrlimit)
|
246
|
+
assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
|
247
|
+
assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_FSIZE) }
|
248
|
+
end
|
249
|
+
|
250
|
+
test "getrlimit returns an array of two numeric elements" do
|
251
|
+
assert_kind_of(Array, Process.getrlimit(Process::RLIMIT_CPU))
|
252
|
+
assert_equal(2, Process.getrlimit(Process::RLIMIT_CPU).length)
|
253
|
+
assert_kind_of(Integer, Process.getrlimit(Process::RLIMIT_CPU).first)
|
254
|
+
end
|
255
|
+
|
256
|
+
test "getrlimit can be called multiple times without issue" do
|
257
|
+
assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
|
258
|
+
assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
|
259
|
+
assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
|
260
|
+
end
|
261
|
+
|
262
|
+
test "getrlimit requires a valid resource value" do
|
263
|
+
assert_raise(ArgumentError){ Process.getrlimit(9999) }
|
264
|
+
end
|
265
|
+
|
266
|
+
test "setrlimit basic functionality" do
|
267
|
+
assert_respond_to(Process, :setrlimit)
|
268
|
+
assert_nothing_raised{ Process.setrlimit(Process::RLIMIT_CPU, 1000000) }
|
269
|
+
end
|
270
|
+
|
271
|
+
test "setrlimit returns nil on success" do
|
272
|
+
assert_nil(Process.setrlimit(Process::RLIMIT_CPU, 1000000))
|
273
|
+
end
|
274
|
+
|
275
|
+
test "setrlimit sets the resource limit as expected" do
|
276
|
+
assert_nothing_raised{ Process.setrlimit(Process::RLIMIT_CPU, 1000000) }
|
277
|
+
assert_equal([1000000, 1000000], Process.getrlimit(Process::RLIMIT_CPU))
|
278
|
+
end
|
279
|
+
|
280
|
+
test "setrlimit raises an error if the resource value is invalid" do
|
281
|
+
assert_raise(ArgumentError){ Process.setrlimit(9999, 100) }
|
282
|
+
end
|
283
|
+
|
284
|
+
test "is_job basic functionality" do
|
285
|
+
assert_respond_to(Process, :job?)
|
286
|
+
assert_nothing_raised{ Process.job? }
|
287
|
+
end
|
288
|
+
|
289
|
+
test "is_job returns a boolean value" do
|
290
|
+
assert_boolean(Process.job?)
|
291
|
+
end
|
292
|
+
|
293
|
+
test "is_job does not accept any arguments" do
|
294
|
+
assert_raise(ArgumentError){ Process.job?(Process.pid) }
|
295
|
+
end
|
296
|
+
|
297
|
+
test "volume_type is a private method" do
|
298
|
+
assert_not_respond_to(Process, :volume_type)
|
299
|
+
end
|
300
|
+
|
301
|
+
test "ffi functions are private" do
|
302
|
+
assert_not_respond_to(Process, :CloseHandle)
|
303
|
+
assert_not_respond_to(Process, :GetCurrentProcess)
|
304
|
+
assert_not_respond_to(Process, :GetProcessAffinityMask)
|
305
|
+
assert_not_respond_to(Process, :GetPriorityClass)
|
306
|
+
assert_not_respond_to(Process, :IsProcessInJob)
|
307
|
+
assert_not_respond_to(Process, :OpenProcess)
|
308
|
+
assert_not_respond_to(Process, :SetHandleInformation)
|
309
|
+
assert_not_respond_to(Process, :SetPriorityClass)
|
310
|
+
end
|
311
|
+
|
312
|
+
test "get_exitcode basic functionality" do
|
313
|
+
assert_respond_to(Process, :get_exitcode)
|
314
|
+
end
|
315
|
+
|
316
|
+
=begin
|
317
|
+
test "get_exitcode returns the process exit code" do
|
318
|
+
pid = Process.create(
|
319
|
+
:app_name => 'cmd /c exit 7',
|
320
|
+
:creation_flags => Process::DETACHED_PROCESS
|
321
|
+
).process_id
|
322
|
+
10.times do
|
323
|
+
sleep(0.1)
|
324
|
+
break if Process.get_exitcode(pid)
|
325
|
+
end
|
326
|
+
assert_equal 7, Process.get_exitcode(pid)
|
327
|
+
end
|
328
|
+
|
329
|
+
test "get_exitcode returns nil while the process is running" do
|
330
|
+
stdin_read, stdin_write = IO.pipe
|
331
|
+
pid = Process.create(
|
332
|
+
:app_name => 'cmd /c pause',
|
333
|
+
:creation_flags => Process::DETACHED_PROCESS,
|
334
|
+
:startup_info => { :stdin => stdin_read }
|
335
|
+
).process_id
|
336
|
+
assert_equal nil, Process.get_exitcode(pid)
|
337
|
+
stdin_write.write("\n")
|
338
|
+
10.times do
|
339
|
+
sleep(0.1)
|
340
|
+
break if Process.get_exitcode(pid)
|
341
|
+
end
|
342
|
+
assert_equal 1, Process.get_exitcode(pid)
|
343
|
+
end
|
344
|
+
=end
|
345
|
+
|
346
|
+
def teardown
|
347
|
+
@priority = nil
|
348
|
+
end
|
349
|
+
|
350
|
+
def self.shutdown
|
351
|
+
@@pids = nil
|
352
|
+
end
|
353
|
+
end
|