win32-process 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +189 -180
- data/MANIFEST +10 -10
- data/README +117 -118
- data/Rakefile +28 -35
- data/examples/test_create.rb +39 -39
- data/examples/test_fork_wait.rb +33 -33
- data/examples/test_fork_waitpid.rb +50 -50
- data/examples/test_kill.rb +34 -34
- data/lib/win32/process.rb +1098 -1004
- data/test/test_win32_process.rb +207 -179
- data/win32-process.gemspec +29 -29
- metadata +47 -19
data/test/test_win32_process.rb
CHANGED
@@ -1,179 +1,207 @@
|
|
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 'rubygems'
|
15
|
-
gem 'test-unit'
|
16
|
-
|
17
|
-
require 'test/unit'
|
18
|
-
require 'win32/process'
|
19
|
-
require 'sys/proctable'
|
20
|
-
include Sys
|
21
|
-
|
22
|
-
class TC_Win32Process < Test::Unit::TestCase
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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 'rubygems'
|
15
|
+
gem 'test-unit'
|
16
|
+
|
17
|
+
require 'test/unit'
|
18
|
+
require 'win32/process'
|
19
|
+
require 'sys/proctable'
|
20
|
+
include Sys
|
21
|
+
|
22
|
+
class TC_Win32Process < Test::Unit::TestCase
|
23
|
+
|
24
|
+
# Start two instances of notepad and give them a chance to fire up
|
25
|
+
def self.startup
|
26
|
+
IO.popen('notepad')
|
27
|
+
IO.popen('notepad')
|
28
|
+
sleep 1 # Give the notepad instances a second to startup
|
29
|
+
|
30
|
+
@@pids = []
|
31
|
+
|
32
|
+
ProcTable.ps{ |struct|
|
33
|
+
next unless struct.comm =~ /notepad/i
|
34
|
+
@@pids << struct.pid
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@pid = nil
|
40
|
+
@pri_class = Process::NORMAL_PRIORITY_CLASS
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_version
|
44
|
+
assert_equal('0.6.3', Process::WIN32_PROCESS_VERSION)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_kill
|
48
|
+
assert_respond_to(Process, :kill)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_kill_expected_errors
|
52
|
+
assert_raises(ArgumentError){ Process.kill }
|
53
|
+
assert_raises(Process::Error){ Process.kill('SIGBOGUS') }
|
54
|
+
assert_raises(Process::Error){ Process.kill(0, 9999999) }
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_kill_signal_0
|
58
|
+
pid = @@pids.first
|
59
|
+
assert_nothing_raised{ Process.kill(0, pid) }
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_kill_signal_1
|
63
|
+
pid = @@pids.shift
|
64
|
+
assert_nothing_raised{ Process.kill(1, pid) }
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_kill_signal_9
|
68
|
+
pid = @@pids.pop
|
69
|
+
msg = "Could not find pid #{pid}"
|
70
|
+
assert_nothing_raised(msg){ Process.kill(9, pid) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_fork
|
74
|
+
assert_respond_to(Process, :fork)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_create
|
78
|
+
assert_respond_to(Process, :create)
|
79
|
+
assert_nothing_raised{
|
80
|
+
@pid = Process.create(
|
81
|
+
:app_name => "notepad.exe",
|
82
|
+
:creation_flags => Process::DETACHED_PROCESS,
|
83
|
+
:process_inherit => false,
|
84
|
+
:thread_inherit => true,
|
85
|
+
:cwd => "C:\\"
|
86
|
+
).process_id
|
87
|
+
}
|
88
|
+
|
89
|
+
assert_nothing_raised{ Process.kill(1, @pid) }
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_create_expected_errors
|
93
|
+
assert_raises(TypeError){ Process.create("bogusapp.exe") }
|
94
|
+
assert_raises(Process::Error){ Process.create(:app_name => "bogusapp.exe") }
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_wait
|
98
|
+
assert_respond_to(Process, :wait)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_wait2
|
102
|
+
assert_respond_to(Process, :wait2)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_waitpid
|
106
|
+
assert_respond_to(Process, :waitpid)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_waitpid2
|
110
|
+
assert_respond_to(Process, :waitpid2)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_ppid
|
114
|
+
assert_respond_to(Process, :ppid)
|
115
|
+
assert_equal(true, Process.ppid > 0)
|
116
|
+
assert_equal(false, Process.pid == Process.ppid)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_uid
|
120
|
+
assert_respond_to(Process, :uid)
|
121
|
+
assert_kind_of(Fixnum, Process.uid)
|
122
|
+
assert_kind_of(String, Process.uid(true))
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_getpriority
|
126
|
+
assert_respond_to(Process, :getpriority)
|
127
|
+
assert_nothing_raised{ Process.getpriority(nil, Process.pid) }
|
128
|
+
assert_kind_of(Fixnum, Process.getpriority(nil, Process.pid))
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_getpriority_expected_errors
|
132
|
+
assert_raise{ Process.getpriority }
|
133
|
+
assert_raise{ Process.getpriority(nil) }
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_setpriority
|
137
|
+
assert_respond_to(Process, :setpriority)
|
138
|
+
assert_nothing_raised{ Process.setpriority(nil, Process.pid, @pri_class) }
|
139
|
+
assert_equal(0, Process.setpriority(nil, Process.pid, @pri_class))
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_setpriority_expected_errors
|
143
|
+
assert_raise{ Process.setpriority }
|
144
|
+
assert_raise{ Process.setpriority(nil) }
|
145
|
+
assert_raise{ Process.setpriority(nil, Process.pid) }
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_creation_constants
|
149
|
+
assert_not_nil(Process::CREATE_DEFAULT_ERROR_MODE)
|
150
|
+
assert_not_nil(Process::CREATE_NEW_CONSOLE)
|
151
|
+
assert_not_nil(Process::CREATE_NEW_PROCESS_GROUP)
|
152
|
+
assert_not_nil(Process::CREATE_NO_WINDOW)
|
153
|
+
assert_not_nil(Process::CREATE_SEPARATE_WOW_VDM)
|
154
|
+
assert_not_nil(Process::CREATE_SHARED_WOW_VDM)
|
155
|
+
assert_not_nil(Process::CREATE_SUSPENDED)
|
156
|
+
assert_not_nil(Process::CREATE_UNICODE_ENVIRONMENT)
|
157
|
+
assert_not_nil(Process::DEBUG_ONLY_THIS_PROCESS)
|
158
|
+
assert_not_nil(Process::DEBUG_PROCESS)
|
159
|
+
assert_not_nil(Process::DETACHED_PROCESS)
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_getrlimit
|
163
|
+
assert_respond_to(Process, :getrlimit)
|
164
|
+
assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
|
165
|
+
assert_kind_of(Array, Process.getrlimit(Process::RLIMIT_CPU))
|
166
|
+
assert_equal(2, Process.getrlimit(Process::RLIMIT_CPU).length)
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_getrlimit_can_be_called_multiple_times
|
170
|
+
assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
|
171
|
+
assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
|
172
|
+
assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_getrlimit_raises_an_error_if_the_resource_is_invalid
|
176
|
+
assert_raise(Process::Error){ Process.getrlimit(9999) }
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_setrlimit_basic
|
180
|
+
assert_respond_to(Process, :getrlimit)
|
181
|
+
assert_nothing_raised{ Process.setrlimit(Process::RLIMIT_VMEM, 1024 * 4) }
|
182
|
+
assert_nil(Process.setrlimit(Process::RLIMIT_VMEM, 1024 * 4))
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_setrlimit_sets_the_resource_as_expected
|
186
|
+
assert_nothing_raised{ Process.setrlimit(Process::RLIMIT_VMEM, 1024 * 4) }
|
187
|
+
assert_equal([4096, 4096], Process.getrlimit(Process::RLIMIT_VMEM))
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_setrlimit_raises_an_error_if_the_resource_is_invalid
|
191
|
+
assert_raise(Process::Error){ Process.setrlimit(9999, 100) }
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_is_job
|
195
|
+
assert_respond_to(Process, :job?)
|
196
|
+
assert_nothing_raised{ Process.job? }
|
197
|
+
assert_boolean(Process.job?)
|
198
|
+
end
|
199
|
+
|
200
|
+
def teardown
|
201
|
+
@pid = nil
|
202
|
+
end
|
203
|
+
|
204
|
+
def self.shutdown
|
205
|
+
@@pids = []
|
206
|
+
end
|
207
|
+
end
|
data/win32-process.gemspec
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
The win32-process library implements several Process methods that are
|
25
|
-
either unimplemented or dysfunctional in some way in the default Ruby
|
26
|
-
implementation. Examples include Process.kill, Process.waitpid,
|
27
|
-
Process.create and an experimental Process.fork method.
|
28
|
-
EOF
|
29
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'win32-process'
|
5
|
+
spec.version = '0.6.3'
|
6
|
+
spec.license = 'Artistic 2.0'
|
7
|
+
spec.authors = ['Daniel Berger', 'Park Heesob']
|
8
|
+
spec.email = 'djberg96@gmail.com'
|
9
|
+
spec.homepage = 'http://www.rubyforge.org/projects/win32utils'
|
10
|
+
spec.platform = Gem::Platform::RUBY
|
11
|
+
spec.summary = 'Adds and redefines several Process methods for MS Windows'
|
12
|
+
spec.test_files = Dir['test/*.rb']
|
13
|
+
spec.has_rdoc = true
|
14
|
+
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
15
|
+
|
16
|
+
spec.rubyforge_project = 'win32utils'
|
17
|
+
spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
|
18
|
+
|
19
|
+
spec.add_dependency('windows-pr', '>= 1.1.0')
|
20
|
+
spec.add_development_dependency('test-unit', '>= 2.1.1')
|
21
|
+
spec.add_development_dependency('sys-proctable')
|
22
|
+
|
23
|
+
spec.description = <<-EOF
|
24
|
+
The win32-process library implements several Process methods that are
|
25
|
+
either unimplemented or dysfunctional in some way in the default Ruby
|
26
|
+
implementation. Examples include Process.kill, Process.waitpid,
|
27
|
+
Process.create and an experimental Process.fork method.
|
28
|
+
EOF
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: win32-process
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 1
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 6
|
9
|
+
- 3
|
10
|
+
version: 0.6.3
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Daniel Berger
|
@@ -10,39 +16,55 @@ autorequire:
|
|
10
16
|
bindir: bin
|
11
17
|
cert_chain: []
|
12
18
|
|
13
|
-
date:
|
19
|
+
date: 2010-11-09 00:00:00 -07:00
|
14
20
|
default_executable:
|
15
21
|
dependencies:
|
16
22
|
- !ruby/object:Gem::Dependency
|
17
23
|
name: windows-pr
|
18
|
-
|
19
|
-
|
20
|
-
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
21
27
|
requirements:
|
22
28
|
- - ">="
|
23
29
|
- !ruby/object:Gem::Version
|
24
|
-
|
25
|
-
|
30
|
+
hash: 19
|
31
|
+
segments:
|
32
|
+
- 1
|
33
|
+
- 1
|
34
|
+
- 0
|
35
|
+
version: 1.1.0
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
26
38
|
- !ruby/object:Gem::Dependency
|
27
39
|
name: test-unit
|
28
|
-
|
29
|
-
|
30
|
-
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
31
43
|
requirements:
|
32
44
|
- - ">="
|
33
45
|
- !ruby/object:Gem::Version
|
34
|
-
|
35
|
-
|
46
|
+
hash: 9
|
47
|
+
segments:
|
48
|
+
- 2
|
49
|
+
- 1
|
50
|
+
- 1
|
51
|
+
version: 2.1.1
|
52
|
+
type: :development
|
53
|
+
version_requirements: *id002
|
36
54
|
- !ruby/object:Gem::Dependency
|
37
55
|
name: sys-proctable
|
38
|
-
|
39
|
-
|
40
|
-
|
56
|
+
prerelease: false
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
41
59
|
requirements:
|
42
60
|
- - ">="
|
43
61
|
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
44
65
|
version: "0"
|
45
|
-
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id003
|
46
68
|
description: " The win32-process library implements several Process methods that are\n either unimplemented or dysfunctional in some way in the default Ruby\n implementation. Examples include Process.kill, Process.waitpid,\n Process.create and an experimental Process.fork method.\n"
|
47
69
|
email: djberg96@gmail.com
|
48
70
|
executables: []
|
@@ -75,21 +97,27 @@ rdoc_options: []
|
|
75
97
|
require_paths:
|
76
98
|
- lib
|
77
99
|
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
78
101
|
requirements:
|
79
102
|
- - ">="
|
80
103
|
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
81
107
|
version: "0"
|
82
|
-
version:
|
83
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
84
110
|
requirements:
|
85
111
|
- - ">="
|
86
112
|
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
87
116
|
version: "0"
|
88
|
-
version:
|
89
117
|
requirements: []
|
90
118
|
|
91
119
|
rubyforge_project: win32utils
|
92
|
-
rubygems_version: 1.3.
|
120
|
+
rubygems_version: 1.3.7
|
93
121
|
signing_key:
|
94
122
|
specification_version: 3
|
95
123
|
summary: Adds and redefines several Process methods for MS Windows
|