proc-wait3 1.5.5 → 1.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/proc-wait3.gemspec CHANGED
@@ -1,30 +1,29 @@
1
1
  require 'rubygems'
2
2
 
3
- spec = Gem::Specification.new do |gem|
4
- gem.name = 'proc-wait3'
5
- gem.version = '1.5.5'
6
- gem.author = 'Daniel J. Berger'
7
- gem.license = 'Artistic 2.0'
8
- gem.email = 'djberg96@gmail.com'
9
- gem.homepage = 'http://www.rubyforge.org/projects/shards'
10
- gem.platform = Gem::Platform::RUBY
11
- gem.summary = 'Adds wait3 and other methods to the Process module'
12
- gem.test_file = 'test/test_proc_wait3.rb'
13
- gem.has_rdoc = true
14
- gem.extensions = ['ext/extconf.rb']
15
- gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
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
- gem.rubyforge_project = 'shards'
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
- gem.add_development_dependency('test-unit', '>= 2.0.3')
19
+ spec.rubyforge_project = 'shards'
20
+ spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'ext/proc/wait3.c']
22
21
 
23
- gem.description = <<-EOF
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
- Gem::Builder.new(spec).build
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
@@ -12,239 +12,230 @@ require 'test/unit'
12
12
  require 'rbconfig'
13
13
 
14
14
  class TC_Proc_Wait3 < Test::Unit::TestCase
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.5', 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_in_action
93
- omit_if(@@hpux || @@darwin || @@freebsd, 'waitid test skipped on this platform')
94
- pid = fork{ sleep 1 }
95
-
96
- assert_nothing_raised{
97
- Process.waitid(Process::P_PID, pid, Process::WEXITED)
98
- }
99
-
100
- assert_raises(TypeError){
101
- Process.waitid("foo", pid, Process::WEXITED)
102
- }
103
-
104
- assert_raises(TypeError){
105
- Process.waitid(Process::P_PID, pid, "foo")
106
- }
107
-
108
- assert_raises(TypeError){
109
- Process.waitid(Process::P_PID, "foo", Process::WEXITED)
110
- }
111
-
112
- assert_raises(Errno::ECHILD, Errno::EINVAL){
113
- Process.waitid(Process::P_PID, 99999999, Process::WEXITED)
114
- }
115
- end
116
-
117
- def test_sigsend_basic
118
- omit_unless(@@solaris, 'sigsend test skipped on this platform')
119
- assert_respond_to(Process, :sigsend)
120
- end
121
-
122
- def test_sigsend_in_action
123
- omit_unless(@@solaris, 'sigsend test skipped on this platform')
124
- pid = fork{ sleep 1 }
125
-
126
- assert_nothing_raised{
127
- Process.sigsend(Process::P_PID,pid,0)
128
- }
129
- end
130
-
131
- def test_getrusage_basic
132
- assert_respond_to(Process, :getrusage)
133
- end
134
-
135
- def test_getrusage_in_action
136
- pid = fork{ sleep 1 }
137
- assert_nothing_raised{ Process.getrusage }
138
- assert_nothing_raised{ Process.getrusage(true) }
139
- assert_kind_of(Struct::RUsage, Process.getrusage)
140
- assert_kind_of(Float, Process.getrusage.stime)
141
- assert_kind_of(Float, Process.getrusage.utime)
142
- end
143
-
144
- def test_pause
145
- assert_respond_to(Process, :pause)
146
- end
147
-
148
- def test_wait_constants
149
- omit_if(@@darwin || @@freebsd, 'wait constant check skipped on this platform')
150
-
151
- assert_not_nil(Process::WCONTINUED)
152
- assert_not_nil(Process::WEXITED)
153
- assert_not_nil(Process::WNOWAIT)
154
- assert_not_nil(Process::WSTOPPED)
155
-
156
- omit_if(@@linux, 'WTRAPPED constant check skipped on this platform')
157
- assert_not_nil(Process::WTRAPPED)
158
- end
159
-
160
- def test_getrlimit
161
- omit_unless(@@old_ruby, 'getrlimit test skipped on recent versions of Ruby')
162
-
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_setrlimit
170
- omit_unless(@@old_ruby, 'setrlimit test skipped on recent versions of Ruby')
171
-
172
- assert_respond_to(Process, :setrlimit)
173
- assert_nothing_raised{
174
- Process.setrlimit(
175
- Process::RLIMIT_CPU,
176
- Process::RLIM_SAVED_CUR,
177
- Process::RLIM_SAVED_MAX
178
- )
179
- }
180
- assert_nothing_raised{
181
- Process.setrlimit(Process::RLIMIT_CPU, Process::RLIM_SAVED_CUR)
182
- }
183
- end
184
-
185
- # Test to ensure that the various rlimit constants are defined. Note that
186
- # as of Ruby 1.8.5 these are defined by Ruby itself, except for the
187
- # RLIMIT_VMEM constant, which is platform dependent.
188
- #
189
- def test_rlimit_constants
190
- assert_not_nil(Process::RLIMIT_AS)
191
- assert_not_nil(Process::RLIMIT_CORE)
192
- assert_not_nil(Process::RLIMIT_CPU)
193
- assert_not_nil(Process::RLIMIT_DATA)
194
- assert_not_nil(Process::RLIMIT_FSIZE)
195
- assert_not_nil(Process::RLIMIT_NOFILE)
196
- assert_not_nil(Process::RLIMIT_STACK)
197
- assert_not_nil(Process::RLIM_INFINITY)
198
- end
199
-
200
- def test_nonstandard_rlimit_constants
201
- omit_unless(@@old_ruby, 'nonstandard rlimit constant tests skipped on recent versions of Ruby')
202
- assert_not_nil(Process::RLIM_SAVED_MAX)
203
- assert_not_nil(Process::RLIM_SAVED_CUR)
204
- end
205
-
206
- # This test was added to ensure that these three constants are being
207
- # defined properly after an issue appeared on Linux with regards to
208
- # the value accidentally being assigned a negative value.
209
- #
210
- def test_rlimit_constants_valid
211
- omit_unless(@@old_ruby, 'valid rlimit constant tests skipped on recent versions of Ruby')
212
- assert(Process::RLIM_INFINITY > 0)
213
- assert(Process::RLIM_SAVED_MAX > 0)
214
- assert(Process::RLIM_SAVED_CUR > 0)
215
- end
216
-
217
- def test_process_type_flags
218
- omit_if(@@linux || @@darwin || @@freebsd, 'process type flag check skipped on this platform')
219
-
220
- assert_not_nil(Process::P_ALL)
221
- assert_not_nil(Process::P_CID)
222
- assert_not_nil(Process::P_GID)
223
- assert_not_nil(Process::P_MYID)
224
- assert_not_nil(Process::P_PGID)
225
- assert_not_nil(Process::P_PID)
226
- assert_not_nil(Process::P_SID)
227
- assert_not_nil(Process::P_UID)
228
- end
229
-
230
- def test_solaris_process_type_flags
231
- omit_unless(@@solaris, 'P_TASKID and P_PROJID constant check skipped on this platform')
232
-
233
- assert_not_nil(Process::P_TASKID)
234
- assert_not_nil(Process::P_PROJID)
235
- end
236
-
237
- def teardown
238
- @proc_stat = nil
239
- @proc_stat_members = nil
240
- end
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