proc-wait3 1.5.5 → 1.5.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +10 -0
- data/README +33 -51
- data/Rakefile +42 -81
- data/ext/extconf.rb +52 -73
- data/ext/proc/wait3.c +130 -109
- data/proc-wait3.gemspec +23 -24
- data/test/test_proc_wait3.rb +226 -235
- metadata +4 -4
data/proc-wait3.gemspec
CHANGED
@@ -1,30 +1,29 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'proc-wait3'
|
5
|
+
spec.version = '1.5.6'
|
6
|
+
spec.author = 'Daniel J. Berger'
|
7
|
+
spec.license = 'Artistic 2.0'
|
8
|
+
spec.email = 'djberg96@gmail.com'
|
9
|
+
spec.homepage = 'http://www.rubyforge.org/projects/shards'
|
10
|
+
spec.platform = Gem::Platform::RUBY
|
11
|
+
spec.summary = 'Adds wait3, wait4 and other methods to the Process module'
|
12
|
+
spec.test_file = 'test/test_proc_wait3.rb'
|
13
|
+
spec.has_rdoc = true
|
14
|
+
spec.extensions = ['ext/extconf.rb']
|
15
|
+
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
16
16
|
|
17
|
-
|
18
|
-
gem.required_ruby_version = '>= 1.8.2'
|
19
|
-
gem.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'ext/proc/wait3.c']
|
17
|
+
spec.required_ruby_version = '>= 1.8.2'
|
20
18
|
|
21
|
-
|
19
|
+
spec.rubyforge_project = 'shards'
|
20
|
+
spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'ext/proc/wait3.c']
|
22
21
|
|
23
|
-
|
24
|
-
The proc-wait3 library adds the wait3, wait4, waitid, pause, sigsend,
|
25
|
-
and getrusage methods to the Process module. It also adds the getrlimit
|
26
|
-
and setrlimit methods for Ruby 1.8.4 or earlier.
|
27
|
-
EOF
|
28
|
-
end
|
22
|
+
spec.add_development_dependency('test-unit', '>= 2.0.3')
|
29
23
|
|
30
|
-
|
24
|
+
spec.description = <<-EOF
|
25
|
+
The proc-wait3 library adds the wait3, wait4, waitid, pause, sigsend,
|
26
|
+
and getrusage methods to the Process module. It also adds the getrlimit
|
27
|
+
and setrlimit methods for Ruby 1.8.4 or earlier.
|
28
|
+
EOF
|
29
|
+
end
|
data/test/test_proc_wait3.rb
CHANGED
@@ -12,239 +12,230 @@ require 'test/unit'
|
|
12
12
|
require 'rbconfig'
|
13
13
|
|
14
14
|
class TC_Proc_Wait3 < Test::Unit::TestCase
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
def self.shutdown
|
243
|
-
@@solaris = nil
|
244
|
-
@@darwin = nil
|
245
|
-
@@hpux = nil
|
246
|
-
@@linux = nil
|
247
|
-
@@freebsd = nil
|
248
|
-
@@old_ruby = nil
|
249
|
-
end
|
15
|
+
def self.startup
|
16
|
+
@@solaris = Config::CONFIG['host_os'] =~ /sunos|solaris/i
|
17
|
+
@@darwin = Config::CONFIG['host_os'] =~ /darwin|osx/i
|
18
|
+
@@hpux = Config::CONFIG['host_os'] =~ /hpux/i
|
19
|
+
@@linux = Config::CONFIG['host_os'] =~ /linux/i
|
20
|
+
@@freebsd = Config::CONFIG['host_os'] =~ /bsd/i
|
21
|
+
@@old_ruby = RUBY_VERSION.split('.').last.to_i < 5
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@proc_stat = nil
|
26
|
+
@proc_stat_members = [
|
27
|
+
"pid", "status", "utime", "stime", "maxrss",
|
28
|
+
"ixrss", "idrss", "isrss", "minflt", "majflt", "nswap", "inblock",
|
29
|
+
"oublock", "msgsnd", "msgrcv", "nsignals", "nvcsw", "nivcsw",
|
30
|
+
"stopped", "signaled","exited","success","coredump","exitstatus",
|
31
|
+
"termsig", "stopsig"
|
32
|
+
]
|
33
|
+
|
34
|
+
if RUBY_VERSION.to_f >= 1.9
|
35
|
+
@proc_stat_members = @proc_stat_members.map{ |e| e.to_sym }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_wait3_version
|
40
|
+
assert_equal('1.5.6', Process::WAIT3_VERSION)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_wait3_basic
|
44
|
+
assert_respond_to(Process, :wait3)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_wait3_no_args
|
48
|
+
pid = fork{ sleep 1 }
|
49
|
+
assert_nothing_raised{ Process.wait3 }
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_wait3_procstat_members
|
53
|
+
pid = fork{ sleep 1 }
|
54
|
+
assert_nothing_raised{ @proc_stat = Process.wait3 }
|
55
|
+
assert_equal(@proc_stat_members, @proc_stat.members)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_wait3_nohang
|
59
|
+
pid = fork{ sleep 1 }
|
60
|
+
assert_nothing_raised{ Process.wait3(Process::WNOHANG) }
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_getdtablesize
|
64
|
+
omit_unless(@@solaris, 'getdtablesize skipped on this platform')
|
65
|
+
|
66
|
+
assert_respond_to(Process, :getdtablesize)
|
67
|
+
assert_kind_of(Fixnum, Process.getdtablesize)
|
68
|
+
assert(Process.getdtablesize > 0)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_wait4_basic
|
72
|
+
omit_if(@@hpux, 'wait4 test skipped on this platform')
|
73
|
+
|
74
|
+
assert_respond_to(Process,:wait4)
|
75
|
+
assert_raises(ArgumentError){ Process.wait4 } # Must have at least 1 arg
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_wait4_in_action
|
79
|
+
omit_if(@@hpux, 'wait4 test skipped on this platform')
|
80
|
+
|
81
|
+
pid = fork{ sleep 1 }
|
82
|
+
assert_nothing_raised{ @proc_stat = Process.wait4(pid) }
|
83
|
+
assert_kind_of(Struct::ProcStat, @proc_stat)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_waitid_basic
|
87
|
+
omit_if(@@hpux || @@darwin || @@freebsd, 'waitid test skipped on this platform')
|
88
|
+
|
89
|
+
assert_respond_to(Process, :waitid)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_waitid
|
93
|
+
omit_if(@@hpux || @@darwin || @@freebsd, 'waitid test skipped on this platform')
|
94
|
+
pid = fork{ sleep 1 }
|
95
|
+
|
96
|
+
assert_nothing_raised{ Process.waitid(Process::P_PID, pid, Process::WEXITED) }
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_waitid_expected_errors
|
100
|
+
omit_if(@@hpux || @@darwin || @@freebsd, 'waitid test skipped on this platform')
|
101
|
+
pid = fork{ sleep 1 }
|
102
|
+
|
103
|
+
assert_raises(TypeError){ Process.waitid("foo", pid, Process::WEXITED) }
|
104
|
+
assert_raises(TypeError){ Process.waitid(Process::P_PID, pid, "foo") }
|
105
|
+
assert_raises(TypeError){ Process.waitid(Process::P_PID, "foo", Process::WEXITED) }
|
106
|
+
assert_raises(Errno::ECHILD, Errno::EINVAL){ Process.waitid(Process::P_PID, 99999999, Process::WEXITED) }
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_sigsend_basic
|
110
|
+
omit_unless(@@solaris, 'sigsend test skipped on this platform')
|
111
|
+
assert_respond_to(Process, :sigsend)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_sigsend_in_action
|
115
|
+
omit_unless(@@solaris, 'sigsend test skipped on this platform')
|
116
|
+
pid = fork{ sleep 1 }
|
117
|
+
|
118
|
+
assert_nothing_raised{ Process.sigsend(Process::P_PID, pid, 0) }
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_getrusage_basic
|
122
|
+
assert_respond_to(Process, :getrusage)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_getrusage_in_action
|
126
|
+
pid = fork{ sleep 1 }
|
127
|
+
assert_nothing_raised{ Process.getrusage }
|
128
|
+
assert_nothing_raised{ Process.getrusage(true) }
|
129
|
+
assert_kind_of(Struct::RUsage, Process.getrusage)
|
130
|
+
assert_kind_of(Float, Process.getrusage.stime)
|
131
|
+
assert_kind_of(Float, Process.getrusage.utime)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_pause
|
135
|
+
assert_respond_to(Process, :pause)
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_wait_constants
|
139
|
+
omit_if(@@darwin || @@freebsd, 'wait constant check skipped on this platform')
|
140
|
+
|
141
|
+
assert_not_nil(Process::WCONTINUED)
|
142
|
+
assert_not_nil(Process::WEXITED)
|
143
|
+
assert_not_nil(Process::WNOWAIT)
|
144
|
+
assert_not_nil(Process::WSTOPPED)
|
145
|
+
|
146
|
+
omit_if(@@linux, 'WTRAPPED constant check skipped on this platform')
|
147
|
+
assert_not_nil(Process::WTRAPPED)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_getrlimit
|
151
|
+
omit_unless(@@old_ruby, 'getrlimit test skipped on recent versions of Ruby')
|
152
|
+
|
153
|
+
assert_respond_to(Process, :getrlimit)
|
154
|
+
assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
|
155
|
+
assert_kind_of(Array, Process.getrlimit(Process::RLIMIT_CPU))
|
156
|
+
assert_equal(2, Process.getrlimit(Process::RLIMIT_CPU).length)
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_setrlimit
|
160
|
+
omit_unless(@@old_ruby, 'setrlimit test skipped on recent versions of Ruby')
|
161
|
+
|
162
|
+
assert_respond_to(Process, :setrlimit)
|
163
|
+
assert_nothing_raised{
|
164
|
+
Process.setrlimit(
|
165
|
+
Process::RLIMIT_CPU,
|
166
|
+
Process::RLIM_SAVED_CUR,
|
167
|
+
Process::RLIM_SAVED_MAX
|
168
|
+
)
|
169
|
+
}
|
170
|
+
|
171
|
+
assert_nothing_raised{
|
172
|
+
Process.setrlimit(Process::RLIMIT_CPU, Process::RLIM_SAVED_CUR)
|
173
|
+
}
|
174
|
+
end
|
175
|
+
|
176
|
+
# Test to ensure that the various rlimit constants are defined. Note that
|
177
|
+
# as of Ruby 1.8.5 these are defined by Ruby itself, except for the
|
178
|
+
# RLIMIT_VMEM constant, which is platform dependent.
|
179
|
+
#
|
180
|
+
def test_rlimit_constants
|
181
|
+
assert_not_nil(Process::RLIMIT_AS)
|
182
|
+
assert_not_nil(Process::RLIMIT_CORE)
|
183
|
+
assert_not_nil(Process::RLIMIT_CPU)
|
184
|
+
assert_not_nil(Process::RLIMIT_DATA)
|
185
|
+
assert_not_nil(Process::RLIMIT_FSIZE)
|
186
|
+
assert_not_nil(Process::RLIMIT_NOFILE)
|
187
|
+
assert_not_nil(Process::RLIMIT_STACK)
|
188
|
+
assert_not_nil(Process::RLIM_INFINITY)
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_nonstandard_rlimit_constants
|
192
|
+
omit_unless(@@old_ruby, 'nonstandard rlimit constant tests skipped on recent versions of Ruby')
|
193
|
+
assert_not_nil(Process::RLIM_SAVED_MAX)
|
194
|
+
assert_not_nil(Process::RLIM_SAVED_CUR)
|
195
|
+
end
|
196
|
+
|
197
|
+
# This test was added to ensure that these three constants are being
|
198
|
+
# defined properly after an issue appeared on Linux with regards to
|
199
|
+
# the value accidentally being assigned a negative value.
|
200
|
+
#
|
201
|
+
def test_rlimit_constants_valid
|
202
|
+
omit_unless(@@old_ruby, 'valid rlimit constant tests skipped on recent versions of Ruby')
|
203
|
+
assert(Process::RLIM_INFINITY > 0)
|
204
|
+
assert(Process::RLIM_SAVED_MAX > 0)
|
205
|
+
assert(Process::RLIM_SAVED_CUR > 0)
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_process_type_flags
|
209
|
+
omit_if(@@linux || @@darwin || @@freebsd, 'process type flag check skipped on this platform')
|
210
|
+
|
211
|
+
assert_not_nil(Process::P_ALL)
|
212
|
+
assert_not_nil(Process::P_CID)
|
213
|
+
assert_not_nil(Process::P_GID)
|
214
|
+
assert_not_nil(Process::P_MYID)
|
215
|
+
assert_not_nil(Process::P_PGID)
|
216
|
+
assert_not_nil(Process::P_PID)
|
217
|
+
assert_not_nil(Process::P_SID)
|
218
|
+
assert_not_nil(Process::P_UID)
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_solaris_process_type_flags
|
222
|
+
omit_unless(@@solaris, 'P_TASKID and P_PROJID constant check skipped on this platform')
|
223
|
+
|
224
|
+
assert_not_nil(Process::P_TASKID)
|
225
|
+
assert_not_nil(Process::P_PROJID)
|
226
|
+
end
|
227
|
+
|
228
|
+
def teardown
|
229
|
+
@proc_stat = nil
|
230
|
+
@proc_stat_members = nil
|
231
|
+
end
|
232
|
+
|
233
|
+
def self.shutdown
|
234
|
+
@@solaris = nil
|
235
|
+
@@darwin = nil
|
236
|
+
@@hpux = nil
|
237
|
+
@@linux = nil
|
238
|
+
@@freebsd = nil
|
239
|
+
@@old_ruby = nil
|
240
|
+
end
|
250
241
|
end
|