proc-wait3 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,14 @@
1
+ == 1.5.5 - 8-Aug-2009
2
+ * Now compatible with Ruby 1.9.x.
3
+ * License changed to Artistic 2.0.
4
+ * Added test-unit 2.x as a development dependency.
5
+ * Test suite refactored to take advantage of some of the features of
6
+ test-unit 2.x, as well as fixes (skips) for BSD platforms.
7
+ * Several gemspec updates, including the license and description.
8
+ * Renamed test file to test_proc_wait3.rb.
9
+ * Example files renamed to avoid any confusion with actual test files.
10
+ * Several Rake tasks added to run individual example programs.
11
+
1
12
  == 1.5.4 - 7-Feb-2008
2
13
  * ALERT! ALERT! Now auto-patches your mkmf.rb file to add the 'have_const'
3
14
  method if it's not already found. This is necessary to determine if certain
data/MANIFEST CHANGED
@@ -6,9 +6,9 @@ proc-wait3.gemspec
6
6
  doc/wait3.txt
7
7
  ext/extconf.rb
8
8
  ext/proc/wait3.c
9
- examples/test_getrusage.rb
10
- examples/test_pause.rb
11
- examples/test_wait3.rb
12
- examples/test_wait4.rb
13
- examples/test_waitid.rb
14
- test/tc_wait3.rb
9
+ examples/example_getrusage.rb
10
+ examples/example_pause.rb
11
+ examples/example_wait3.rb
12
+ examples/example_wait4.rb
13
+ examples/example_waitid.rb
14
+ test/test_proc_wait3.rb
data/README CHANGED
@@ -4,21 +4,19 @@
4
4
  and setrlimit methods.
5
5
 
6
6
  == Installation
7
- ruby extconf.rb
8
- make
9
- ruby test/tc_wait3.rb (optional)
10
- make site-install
7
+ === Remote Gem Installation
8
+ gem install proc-wait3
9
+ === Local Installation
10
+ rake install
11
11
 
12
12
  == Tested Platforms
13
- * Solaris 9
14
- * Solaris 10
15
- * Linux 2.4.7 (RedHat)
16
- * Linux 2.6.11 (Suse)
17
- * Linux 2.6.8.1 (Mandriva)
18
- * FreeBSD 4.9
13
+ * Solaris
14
+ * Linux
15
+ * FreeBSD
16
+ * OS X
19
17
 
20
18
  == Warnings
21
- Linux users who compile with gcc -Wall will notice a few warnings. These
19
+ Linux users who compile with gcc -Wall will notice a few warnings. These
22
20
  are harmless (and unavoidable atm).
23
21
 
24
22
  == Applying the mkmf.diff patch
data/Rakefile ADDED
@@ -0,0 +1,105 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'fileutils'
4
+
5
+ desc "Clean the generated build files"
6
+ task :clean do |t|
7
+ Dir.chdir('ext') do
8
+ sh 'make distclean' if File.exists?('wait3.o')
9
+ rm 'proc/wait3.' + Config::CONFIG['DLEXT'] rescue nil
10
+ end
11
+ end
12
+
13
+ desc "Build the source (but don't install it)"
14
+ task :build => [:patch, :clean] do |t|
15
+ Dir.chdir('ext') do
16
+ ruby 'extconf.rb'
17
+ sh 'make'
18
+ FileUtils.mv 'wait3.' + Config::CONFIG['DLEXT'], 'proc'
19
+ end
20
+ end
21
+
22
+ desc "Install the proc-wait3 library"
23
+ task :install => [:build] do |t|
24
+ sh 'make install'
25
+ end
26
+
27
+ desc 'Run the Process.getrusage example program'
28
+ task :example_getrusage => [:build] do
29
+ ruby '-Iext examples/example_getrusage.rb'
30
+ end
31
+
32
+ desc 'Run the Process.pause example program'
33
+ task :example_pause => [:build] do
34
+ ruby '-Iext examples/example_pause.rb'
35
+ end
36
+
37
+ desc 'Run the Process.wait3 example program'
38
+ task :example_wait3 => [:build] do
39
+ ruby '-Iext examples/example_wait3.rb'
40
+ end
41
+
42
+ desc 'Run the Process.wait4 example program'
43
+ task :example_wait4 => [:build] do
44
+ ruby '-Iext examples/example_wait4.rb'
45
+ end
46
+
47
+ desc 'Run the Process.waitid example program'
48
+ task :example_waitid => [:build] do
49
+ ruby '-Iext examples/example_waitid.rb'
50
+ end
51
+
52
+ Rake::TestTask.new do |t|
53
+ task :test => [:build]
54
+ t.libs << 'ext'
55
+ t.warning = true
56
+ t.verbose = true
57
+ end
58
+
59
+ desc "Patch your mkmf.rb file so that it supports have_const. Must be root."
60
+ task :patch do |t|
61
+ require 'mkmf'
62
+ unless defined? have_const
63
+ file = File.join(Config::CONFIG['rubylibdir'], 'mkmf.rb')
64
+ date = Time.now
65
+
66
+ FileUtils.cp(file, 'mkmf.orig') # Backup original
67
+
68
+ File.open(file, 'a+'){ |fh|
69
+ fh.puts %Q{
70
+ # Returns whether or not the constant +const+ can be found in the common
71
+ # header files, or within a +header+ that you provide. If found, a macro is
72
+ # passed as a preprocessor constant to the compiler using the constant name,
73
+ # in uppercase, prepended with 'HAVE_'. This method is also used to test
74
+ # for the presence of enum values.
75
+ #
76
+ # For example, if have_const('FOO') returned true, then the HAVE_CONST_FOO
77
+ # preprocessor macro would be passed to the compiler.
78
+ #
79
+ # This method was added automatically by the proc-wait3 library on
80
+ # #{date}.
81
+ #
82
+ def have_const(const, header = nil, opt = "", &b)
83
+ checking_for const do
84
+ header = cpp_include(header)
85
+ if try_compile(<<"SRC", opt, &b)
86
+ #\{COMMON_HEADERS\}
87
+ #\{header\}
88
+ /* top */
89
+ static int t = #\{const\};
90
+ SRC
91
+ $defs.push(
92
+ format(
93
+ "-DHAVE_CONST_%s",
94
+ const.strip.upcase.tr_s("^A-Z0-9_", "_")
95
+ )
96
+ )
97
+ true
98
+ else
99
+ false
100
+ end
101
+ end
102
+ end}
103
+ }
104
+ end
105
+ end
data/doc/wait3.txt CHANGED
@@ -183,10 +183,10 @@ Process::RLIM_SAVED_MAX
183
183
  page at http://www.rubyforge.org/projects/shards.
184
184
 
185
185
  == License
186
- Ruby's
186
+ Artistic 2.0
187
187
 
188
188
  == Copyright
189
- (C) 2003-2008 Daniel J. Berger
189
+ (C) 2003-2009 Daniel J. Berger
190
190
  All Rights Reserved.
191
191
 
192
192
  == Warranty
@@ -196,8 +196,6 @@ Process::RLIM_SAVED_MAX
196
196
 
197
197
  == Author
198
198
  Daniel J. Berger
199
- djberg96 at gmail dot com
200
- imperator on IRC (irc.freenode.net)
201
199
 
202
200
  == See also
203
201
  wait3, wait4, waitid, pause, sigsend
@@ -0,0 +1,17 @@
1
+ ########################################################################
2
+ # example_getrusage.rb
3
+ #
4
+ # Simple demonstration of the Process.getrusage method. You can run
5
+ # this code via the 'rake example_getrusage' task.
6
+ #
7
+ # Modify as you see fit.
8
+ ########################################################################
9
+ require 'proc/wait3'
10
+ require 'pp'
11
+
12
+ # Show resource stats for this process for 30 seconds
13
+ 10.times do
14
+ pp Process.getrusage
15
+ puts "=" * 50
16
+ sleep 3
17
+ end
@@ -0,0 +1,21 @@
1
+ #######################################################################
2
+ # example_pause.rb
3
+ #
4
+ # Simple demonstration of the Process.pause method. You can use
5
+ # the 'rake example_pause' task to run this program.
6
+ #
7
+ # Modify as you see fit.
8
+ #######################################################################
9
+ require 'rbconfig'
10
+ require 'proc/wait3'
11
+
12
+ puts "Pausing. Hit Ctrl-C to continue."
13
+
14
+ if Config::CONFIG['host_os'] =~ /linux/i
15
+ Process.pause(2)
16
+ else
17
+ Process.pause("INT")
18
+ end
19
+
20
+ puts "Hey, thanks for hitting Ctrl-C. Continuing..."
21
+ puts "Done"
@@ -0,0 +1,15 @@
1
+ #######################################################################
2
+ # example_wait3.rb
3
+ #
4
+ # Simple demo of the Process.wait3 method. You can use the
5
+ # 'rake example_wait3' rake task to run this program.
6
+ #
7
+ # Modify as you see fit.
8
+ #######################################################################
9
+ require 'proc/wait3'
10
+
11
+ pid = fork{ sleep 1; exit 2 }
12
+
13
+ p Time.now
14
+ Process.wait3
15
+ p $?
@@ -0,0 +1,14 @@
1
+ #######################################################################
2
+ # example_wait4.rb
3
+ #
4
+ # Simple demonstration of the Process.wait4 method. You can use the
5
+ # 'rake example_wait4' task to run this code.
6
+ #
7
+ # Modify as you see fit.
8
+ #######################################################################
9
+ require 'proc/wait3'
10
+
11
+ pid = fork{ sleep 2 }
12
+ p Time.now
13
+ Process.wait4(pid, Process::WUNTRACED)
14
+ p $?
@@ -0,0 +1,14 @@
1
+ #######################################################################
2
+ # example_waitid.rb
3
+ #
4
+ # Simple demonstration of the Process.waitid method. You can run this
5
+ # code via the 'rake example_waitid' task.
6
+ #
7
+ # Modify as you see fit.
8
+ #######################################################################
9
+ require 'proc/wait3'
10
+
11
+ pid = fork{ sleep 2 }
12
+ p Time.now
13
+ Process.waitid(Process::P_PID, pid, Process::WEXITED)
14
+ p $?
data/ext/extconf.rb CHANGED
@@ -64,6 +64,10 @@ begin
64
64
  have_const('P_SID', 'signal.h')
65
65
  have_const('P_UID', 'signal.h')
66
66
 
67
+ have_const('P_ALL', 'signal.h') || have_const('P_ALL', 'sys/wait.h')
68
+ have_const('P_PGID', 'signal.h') || have_const('P_PGID', 'sys/wait.h')
69
+ have_const('P_PID', 'signal.h') || have_const('P_PID', 'sys/wait.h')
70
+
67
71
  # These are only supported by Solaris 8 and later afaik
68
72
  have_const('P_PROJID', 'signal.h')
69
73
  have_const('P_TASKID', 'signal.h')
data/ext/proc/wait3.c CHANGED
@@ -17,6 +17,17 @@
17
17
  #define SIG2STR_MAX 32
18
18
  #endif
19
19
 
20
+ /* Ruby 1.9.x */
21
+ #ifndef RSTRING_PTR
22
+ #define RSTRING_PTR(v) (RSTRING(v)->ptr)
23
+ #define RSTRING_LEN(v) (RSTRING(v)->len)
24
+ #endif
25
+
26
+ #ifndef RARRAY_PTR
27
+ #define RARRAY_PTR(v) (RARRAY(v)->ptr)
28
+ #define RARRAY_LEN(v) (RARRAY(v)->len)
29
+ #endif
30
+
20
31
  /* Copied from process.c in Ruby 1.8.5 */
21
32
  #ifndef RUBY_HAS_RLIMIT
22
33
  #if SIZEOF_RLIM_T == SIZEOF_INT
@@ -197,7 +208,7 @@ static VALUE proc_wait3(int argc, VALUE *argv, VALUE mod){
197
208
  }
198
209
 
199
210
  #ifdef HAVE_WAIT4
200
- /*
211
+ /*
201
212
  * call-seq:
202
213
  * Proc.wait4(pid, flags=0)
203
214
  *
@@ -342,7 +353,7 @@ static VALUE proc_waitid(int argc, VALUE* argv, VALUE mod){
342
353
  *
343
354
  * See Rich Teer's "Solaris Systems Programming", p 755 ff.
344
355
  */
345
-
356
+
346
357
  #ifdef SI_NOINFO
347
358
  if(infop.si_code == SI_NOINFO){
348
359
  #else
@@ -554,7 +565,7 @@ static VALUE proc_pause(int argc, VALUE* argv, VALUE mod){
554
565
  rb_scan_args(argc, argv, "0*", &v_signals);
555
566
 
556
567
  /* Iterate over each signal, calling sigset for each one */
557
- len = RARRAY(v_signals)->len;
568
+ len = RARRAY_LEN(v_signals);
558
569
  if(len > 0){
559
570
  VALUE v_val;
560
571
  char signame[SIG2STR_MAX];
@@ -612,7 +623,7 @@ static void sigproc(int signum){ /* Do nothing */ }
612
623
  * The idtype * must be one of the following values:
613
624
  *
614
625
  * * Process::P_ALL
615
- * All non-system processes. The +id+ is ignored.
626
+ * All non-system processes. The +id+ is ignored.
616
627
  *
617
628
  * * Process::P_CID
618
629
  * Any process whose scheduler class ID is equal to +id+.
@@ -766,7 +777,7 @@ static VALUE proc_getrlimit(VALUE mod, VALUE v_resource){
766
777
  rb_ary_push(v_array, rb_str_new2("infinity"));
767
778
  else
768
779
  rb_ary_push(v_array, INT2FIX(limits.rlim_max));
769
-
780
+
770
781
  return v_array;
771
782
  }
772
783
 
@@ -924,14 +935,20 @@ void Init_wait3()
924
935
  * I am forced to keep the leading 'P_' for these constants.
925
936
  */
926
937
 
938
+ #ifdef HAVE_CONST_P_ALL
927
939
  /* Any child */
928
940
  rb_define_const(rb_mProcess, "P_ALL", INT2FIX(P_ALL));
941
+ #endif
929
942
 
943
+ #ifdef HAVE_CONST_P_PGID
930
944
  /* Process group ID */
931
945
  rb_define_const(rb_mProcess, "P_PGID", INT2FIX(P_PGID));
946
+ #endif
932
947
 
948
+ #ifdef HAVE_CONST_P_PID
933
949
  /* Process ID */
934
950
  rb_define_const(rb_mProcess, "P_PID", INT2FIX(P_PID));
951
+ #endif
935
952
 
936
953
  #ifdef HAVE_CONST_P_CID
937
954
  /* Process scheduler class ID */
@@ -1014,8 +1031,8 @@ void Init_wait3()
1014
1031
  #endif
1015
1032
  #endif
1016
1033
 
1017
- /* 1.5.4: The version of this library */
1018
- rb_define_const(rb_mProcess, "WAIT3_VERSION", rb_str_new2("1.5.4"));
1034
+ /* 1.5.5: The version of the proc-wait3 library */
1035
+ rb_define_const(rb_mProcess, "WAIT3_VERSION", rb_str_new2("1.5.5"));
1019
1036
 
1020
1037
  /* Define this last in our Init_wait3 function */
1021
1038
  rb_define_readonly_variable("$?", &v_last_status);
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
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') }
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']
20
+
21
+ gem.add_development_dependency('test-unit', '>= 2.0.3')
22
+
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
29
+
30
+ Gem::Builder.new(spec).build
@@ -0,0 +1,250 @@
1
+ ##################################################################
2
+ # test_proc_wait3.rb
3
+ #
4
+ # Test suite for the Ruby proc-wait3 package. You should run this
5
+ # via the 'test' rake task.
6
+ ##################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'proc/wait3'
11
+ require 'test/unit'
12
+ require 'rbconfig'
13
+
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
250
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proc-wait3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.4
4
+ version: 1.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,11 +9,20 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-08 00:00:00 -07:00
12
+ date: 2009-08-08 00:00:00 -06:00
13
13
  default_executable:
14
- dependencies: []
15
-
16
- description: Adds the wait3, wait4, waitid, pause, sigsend, and getrusage methods to the Process module. It also adds the getrlimit and setrlimit methods for Ruby 1.8.4 or earlier.
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: test-unit
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.3
24
+ version:
25
+ description: " The proc-wait3 library adds the wait3, wait4, waitid, pause, sigsend,\n and getrusage methods to the Process module. It also adds the getrlimit\n and setrlimit methods for Ruby 1.8.4 or earlier.\n"
17
26
  email: djberg96@gmail.com
18
27
  executables: []
19
28
 
@@ -25,14 +34,24 @@ extra_rdoc_files:
25
34
  - MANIFEST
26
35
  - ext/proc/wait3.c
27
36
  files:
37
+ - CHANGES
28
38
  - doc/wait3.txt
29
- - test/tc_wait3.rb
39
+ - examples/example_getrusage.rb
40
+ - examples/example_pause.rb
41
+ - examples/example_wait3.rb
42
+ - examples/example_wait4.rb
43
+ - examples/example_waitid.rb
44
+ - ext/extconf.rb
30
45
  - ext/proc/wait3.c
31
- - CHANGES
32
- - README
33
46
  - MANIFEST
47
+ - proc-wait3.gemspec
48
+ - Rakefile
49
+ - README
50
+ - test/test_proc_wait3.rb
34
51
  has_rdoc: true
35
52
  homepage: http://www.rubyforge.org/projects/shards
53
+ licenses:
54
+ - Artistic 2.0
36
55
  post_install_message:
37
56
  rdoc_options: []
38
57
 
@@ -42,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
42
61
  requirements:
43
62
  - - ">="
44
63
  - !ruby/object:Gem::Version
45
- version: 1.8.0
64
+ version: 1.8.2
46
65
  version:
47
66
  required_rubygems_version: !ruby/object:Gem::Requirement
48
67
  requirements:
@@ -53,9 +72,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
72
  requirements: []
54
73
 
55
74
  rubyforge_project: shards
56
- rubygems_version: 1.0.1
75
+ rubygems_version: 1.3.5
57
76
  signing_key:
58
- specification_version: 2
59
- summary: Adds the wait3, wait4, waitid, pause, sigsend, and getrusage methods to the Process module. It also adds the getrlimit and setrlimit methods for Ruby 1.8.4 or earlier.
77
+ specification_version: 3
78
+ summary: Adds wait3 and other methods to the Process module
60
79
  test_files:
61
- - test/tc_wait3.rb
80
+ - test/test_proc_wait3.rb
data/test/tc_wait3.rb DELETED
@@ -1,235 +0,0 @@
1
- ##################################################################
2
- # tc_wait3.rb
3
- #
4
- # Test suite for the Ruby proc-wait3 package. You should run this
5
- # via the 'test' rake task.
6
- ##################################################################
7
- require "proc/wait3"
8
- require "test/unit"
9
-
10
- class TC_Wait3 < Test::Unit::TestCase
11
- def setup
12
- @proc_stat = nil
13
- @proc_stat_members = ["pid", "status", "utime", "stime", "maxrss",
14
- "ixrss", "idrss", "isrss", "minflt", "majflt", "nswap", "inblock",
15
- "oublock", "msgsnd", "msgrcv", "nsignals", "nvcsw", "nivcsw",
16
- "stopped", "signaled","exited","success","coredump","exitstatus",
17
- "termsig", "stopsig"]
18
- end
19
-
20
- def test_wait3_version
21
- assert_equal('1.5.4', Process::WAIT3_VERSION)
22
- end
23
-
24
- def test_wait3_basic
25
- assert_respond_to(Process, :wait3)
26
- end
27
-
28
- def test_wait3_no_args
29
- pid = fork{ sleep 1 }
30
- assert_nothing_raised{ Process.wait3 }
31
- end
32
-
33
- def test_wait3_procstat_members
34
- pid = fork{ sleep 1 }
35
- assert_nothing_raised{ @proc_stat = Process.wait3 }
36
- assert_equal(@proc_stat_members, @proc_stat.members)
37
- end
38
-
39
- def test_wait3_nohang
40
- pid = fork{ sleep 1 }
41
- assert_nothing_raised{ Process.wait3(Process::WNOHANG) }
42
- end
43
-
44
- if RUBY_PLATFORM =~ /solaris|sunos/i
45
- def test_getdtablesize
46
- assert_respond_to(Process, :getdtablesize)
47
- assert_kind_of(Fixnum, Process.getdtablesize)
48
- assert(Process.getdtablesize > 0)
49
- end
50
- end
51
-
52
- unless RUBY_PLATFORM =~ /hpux/i
53
- def test_wait4_basic
54
- assert_respond_to(Process,:wait4)
55
- assert_raises(ArgumentError){ Process.wait4 } # Must have at least 1 arg
56
- end
57
-
58
- def test_wait4_in_action
59
- pid = fork{ sleep 1 }
60
- assert_nothing_raised{ @proc_stat = Process.wait4(pid) }
61
- assert_kind_of(Struct::ProcStat, @proc_stat)
62
- end
63
-
64
- def test_waitid_basic
65
- if RUBY_PLATFORM =~ /mach|darwin|osx/i
66
- STDOUT.puts "Skipping 'test_waitid_basic' on this platform"
67
- else
68
- assert_respond_to(Process, :waitid)
69
- end
70
- end
71
-
72
- def test_waitid_in_action
73
- if RUBY_PLATFORM =~ /mach|darwin|osx/i
74
- STDOUT.puts "Skipping 'test_waitid_in_action' on this platform"
75
- else
76
- pid = fork{ sleep 1 }
77
-
78
- assert_nothing_raised{
79
- Process.waitid(Process::P_PID, pid, Process::WEXITED)
80
- }
81
-
82
- assert_raises(TypeError){
83
- Process.waitid("foo", pid, Process::WEXITED)
84
- }
85
-
86
- assert_raises(TypeError){
87
- Process.waitid(Process::P_PID, pid, "foo")
88
- }
89
-
90
- assert_raises(TypeError){
91
- Process.waitid(Process::P_PID, "foo", Process::WEXITED)
92
- }
93
-
94
- if RUBY_PLATFORM.match("linux")
95
- assert_raises(Errno::ECHILD){
96
- Process.waitid(Process::P_PID, 99999999, Process::WEXITED)
97
- }
98
- else
99
- assert_raises(Errno::EINVAL){
100
- Process.waitid(Process::P_PID, 99999999, Process::WEXITED)
101
- }
102
- end
103
- end
104
- end
105
-
106
- def test_sigsend_basic
107
- if RUBY_PLATFORM.match("linux")
108
- puts "Skipping 'test_sigsend_basic' on this platform"
109
- else
110
- assert_respond_to(Process,:send)
111
- end
112
- end
113
-
114
- def test_sigsend_in_action
115
- if RUBY_PLATFORM =~ /linux|mach|darwin|osx/i
116
- puts "Skipping 'test_sigsend_in_action' on this platform"
117
- else
118
- pid = fork{ sleep 1 }
119
-
120
- assert_nothing_raised{
121
- Process.sigsend(Process::P_PID,pid,0)
122
- }
123
- end
124
- end
125
- end
126
-
127
- def test_getrusage_basic
128
- assert_respond_to(Process,:getrusage)
129
- end
130
-
131
- def test_getrusage_in_action
132
- pid = fork{ sleep 1 }
133
- assert_nothing_raised{ Process.getrusage }
134
- assert_nothing_raised{ Process.getrusage(true) }
135
- assert_kind_of(Struct::RUsage, Process.getrusage)
136
- assert_kind_of(Float, Process.getrusage.stime)
137
- assert_kind_of(Float, Process.getrusage.utime)
138
- end
139
-
140
- def test_pause
141
- assert_respond_to(Process, :pause)
142
- end
143
-
144
- def test_wait_constants
145
- msg = "Don't panic. It simply appears that this constant is not defined"
146
- msg += "on your particular platform. Ignore"
147
-
148
- unless RUBY_PLATFORM =~ /darwin/i
149
- assert_not_nil(Process::WCONTINUED, msg)
150
- assert_not_nil(Process::WEXITED, msg)
151
- assert_not_nil(Process::WNOWAIT, msg)
152
- assert_not_nil(Process::WSTOPPED, msg)
153
- unless RUBY_PLATFORM.match("linux")
154
- assert_not_nil(Process::WTRAPPED, msg)
155
- end
156
- end
157
- end
158
-
159
- # Skip these tests on Ruby 1.8.5 or later
160
- #
161
- if RUBY_VERSION.split('.').last.to_i <= 4
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_setrlimit
170
- assert_respond_to(Process, :setrlimit)
171
- assert_nothing_raised{
172
- Process.setrlimit(
173
- Process::RLIMIT_CPU,
174
- Process::RLIM_SAVED_CUR,
175
- Process::RLIM_SAVED_MAX
176
- )
177
- }
178
- assert_nothing_raised{
179
- Process.setrlimit(Process::RLIMIT_CPU, Process::RLIM_SAVED_CUR)
180
- }
181
- end
182
- else
183
- STDOUT.puts('Process.getrlimit test skipped for Ruby 1.8.5 or later')
184
- STDOUT.puts('Process.setrlimit test skipped for Ruby 1.8.5 or later')
185
- end
186
-
187
- # Test to ensure that the various rlimit constants are defined. Note that
188
- # as of Ruby 1.8.5 these are defined by Ruby itself, except for the
189
- # RLIMIT_VMEM constant, which is platform dependent.
190
- #
191
- def test_rlimit_constants
192
- assert_not_nil(Process::RLIMIT_AS)
193
- assert_not_nil(Process::RLIMIT_CORE)
194
- assert_not_nil(Process::RLIMIT_CPU)
195
- assert_not_nil(Process::RLIMIT_DATA)
196
- assert_not_nil(Process::RLIMIT_FSIZE)
197
- assert_not_nil(Process::RLIMIT_NOFILE)
198
- assert_not_nil(Process::RLIMIT_STACK)
199
- assert_not_nil(Process::RLIM_INFINITY)
200
- assert_not_nil(Process::RLIM_SAVED_MAX)
201
- assert_not_nil(Process::RLIM_SAVED_CUR)
202
- end
203
-
204
- # This test was added to ensure that these three constants are being
205
- # defined properly after an issue appeared on Linux with regards to
206
- # the value accidentally being assigned a negative value.
207
- #
208
- def test_rlimit_constants_valid
209
- assert(Process::RLIM_INFINITY > 0)
210
- assert(Process::RLIM_SAVED_MAX > 0)
211
- assert(Process::RLIM_SAVED_CUR > 0)
212
- end
213
-
214
- def test_process_type_flags
215
- unless RUBY_PLATFORM =~ /linux|mach|darwin|osx/i
216
- assert_not_nil(Process::P_ALL)
217
- assert_not_nil(Process::P_CID)
218
- assert_not_nil(Process::P_GID)
219
- assert_not_nil(Process::P_MYID)
220
- assert_not_nil(Process::P_PGID)
221
- assert_not_nil(Process::P_PID)
222
- assert_not_nil(Process::P_SID)
223
- assert_not_nil(Process::P_UID)
224
- end
225
- if RUBY_PLATFORM =~ /sunos|solaris/i
226
- assert_not_nil(Process::P_TASKID)
227
- assert_not_nil(Process::P_PROJID)
228
- end
229
- end
230
-
231
- def teardown
232
- @proc_stat = nil
233
- @proc_stat_members = nil
234
- end
235
- end