sys-proctable 0.9.9-universal-aix5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ require 'sys/proctable'
@@ -0,0 +1,6 @@
1
+ module Sys
2
+ class ProcTable
3
+ # The version of the sys-proctable library
4
+ VERSION = '0.9.9'
5
+ end
6
+ end
@@ -0,0 +1,31 @@
1
+ require 'sys/proctable'
2
+
3
+ # The Sys module serves as a namespace only
4
+ module Sys
5
+
6
+ # The Top class serves as a toplevel name for the 'top' method.
7
+ class Top
8
+
9
+ # The version of the sys-top library
10
+ VERSION = '1.0.4'
11
+
12
+ # Returns an array of Struct::ProcTableStruct elements containing up
13
+ # to +num+ elements, sorted by +field+. The default number of elements
14
+ # is 10, while the default field is 'pctcpu'.
15
+ #
16
+ # Exception: the default sort field is 'pid' on AIX and Windows.
17
+ #
18
+ def self.top(num=10, field='pctcpu')
19
+ field = field.to_s if field.is_a?(Symbol)
20
+
21
+ aix = RbConfig::CONFIG['host_os'] =~ /aix/i
22
+
23
+ # Sort by pid on Windows and AIX by default
24
+ if (File::ALT_SEPARATOR || aix) && field == 'pctcpu'
25
+ field = 'pid'
26
+ end
27
+
28
+ Sys::ProcTable.ps.sort_by{ |obj| obj.send(field) || '' }[0..num-1]
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'sys-proctable'
5
+ spec.version = '0.9.9'
6
+ spec.author = 'Daniel J. Berger'
7
+ spec.license = 'Artistic 2.0'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'http://github.com/djberg96/sys-proctable'
10
+ spec.platform = Gem::Platform::CURRENT # Probably altered by Rake task
11
+ spec.summary = 'An interface for providing process table information'
12
+ spec.test_files = ['test/test_sys_proctable_all.rb']
13
+ spec.cert_chain = ['certs/djberg96_pub.pem']
14
+
15
+ # Additional files for your platform are added by the 'rake gem' task.
16
+ spec.files = [
17
+ 'benchmarks/bench_ps.rb',
18
+ 'examples/example_ps.rb',
19
+ 'lib/sys/proctable/version.rb',
20
+ 'lib/sys/top.rb',
21
+ 'CHANGES',
22
+ 'MANIFEST',
23
+ 'Rakefile',
24
+ 'README',
25
+ 'sys-proctable.gemspec'
26
+ ]
27
+
28
+ spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'doc/top.txt']
29
+
30
+ spec.add_development_dependency('test-unit')
31
+ spec.add_development_dependency('rake')
32
+
33
+ spec.description = <<-EOF
34
+ The sys-proctable library provides an interface for gathering information
35
+ about processes on your system, i.e. the process table. Most major
36
+ platforms are supported and, while different platforms may return
37
+ different information, the external interface is identical across
38
+ platforms.
39
+ EOF
40
+ end
@@ -0,0 +1,324 @@
1
+ #######################################################################
2
+ # test_sys_proctable_aix.rb
3
+ #
4
+ # Test suite for the AIX version of the sys-proctable library. You
5
+ # should run these tests via the 'rake test' task.
6
+ #######################################################################
7
+ require 'test-unit'
8
+ require 'sys/proctable'
9
+ require 'test/test_sys_proctable_all'
10
+ include Sys
11
+
12
+ class TC_ProcTable_AIX < Test::Unit::TestCase
13
+ def self.startup
14
+ File.open('aix-child.rb', 'w') do |out|
15
+ out.puts 'trap("HUP") { exit }'
16
+ out.puts 'trap("TERM") { exit }'
17
+ out.puts 'sleep(60)'
18
+ end
19
+
20
+ @@myenv = ENV.to_hash
21
+ @@p1args = %w/aix-child.rb testing how well this works 1/
22
+ @@p2args = %w/aix-child.rb testing how well this works 2/
23
+
24
+ @@pid1 = fork do
25
+ exec('ruby', *@@p1args)
26
+ end
27
+
28
+ @@pid2 = fork do
29
+ exec('ruby', *@@p2args)
30
+ end
31
+
32
+ sleep(2) # wait to make sure the above execs have completed in children
33
+
34
+ @@fields = %w/
35
+ addr argc argv bindpro cid clname cmd_args cmdline cwd egid environ
36
+ envp euid fd flag flag2 fname gid lwpid map nice nlwp onpro pgid pid
37
+ policy ppid pri psargs ptid rssize sid size sname start state time
38
+ ttydev uid wchan wtype s_ttydev
39
+ /
40
+
41
+ @@map_fields = %w/
42
+ size vaddr mapname off mflags pathoff alias gp s_mflags path
43
+ /
44
+
45
+ @@p1info = ProcTable.ps(@@pid1)
46
+ @@p2info = ProcTable.ps.select { |e| e.pid == @@pid2 }
47
+
48
+ if @@p2info.size == 1
49
+ @@p2info = @@p2info[0]
50
+ else
51
+ $stderr.puts "expected a single process, have #{@@p2info.size}"
52
+ exit 1
53
+ end
54
+ end
55
+
56
+ def test_expected_fields
57
+ assert_respond_to(ProcTable, :fields)
58
+ assert_kind_of(Array, ProcTable.fields)
59
+ assert_equal(@@fields.sort, ProcTable.fields.sort)
60
+ end
61
+
62
+ def test_flag
63
+ assert_respond_to(@@p1info, :flag)
64
+ assert_kind_of(Fixnum, @@p1info.flag)
65
+ end
66
+
67
+ def test_flag2
68
+ assert_respond_to(@@p1info, :flag2)
69
+ assert_kind_of(Fixnum, @@p1info.flag2)
70
+ end
71
+
72
+ def test_nlwp
73
+ assert_respond_to(@@p1info, :nlwp)
74
+ assert_kind_of(Fixnum, @@p1info.nlwp)
75
+ end
76
+
77
+ def test_uid
78
+ assert_respond_to(@@p1info, :uid)
79
+ assert_kind_of(Integer, @@p1info.uid)
80
+ assert_equal(Process.uid, @@p1info.uid)
81
+ end
82
+
83
+ def test_euid
84
+ assert_respond_to(@@p1info, :euid)
85
+ assert_kind_of(Integer, @@p1info.euid)
86
+ assert_equal(Process.euid, @@p1info.euid)
87
+ end
88
+
89
+ def test_gid
90
+ assert_respond_to(@@p1info, :gid)
91
+ assert_kind_of(Integer, @@p1info.gid)
92
+ assert_equal(Process.gid, @@p1info.gid)
93
+ end
94
+
95
+ def test_egid
96
+ assert_respond_to(@@p1info, :egid)
97
+ assert_kind_of(Integer, @@p1info.egid)
98
+ assert_equal(Process.egid, @@p1info.egid)
99
+ end
100
+
101
+ def test_pid
102
+ assert_respond_to(@@p1info, :pid)
103
+ assert_kind_of(Integer, @@p1info.pid)
104
+ assert_equal(@@pid1, @@p1info.pid)
105
+ end
106
+
107
+ def test_ppid
108
+ assert_respond_to(@@p1info, :ppid)
109
+ assert_kind_of(Integer, @@p1info.ppid)
110
+ assert_equal(Process.pid, @@p1info.ppid)
111
+ end
112
+
113
+ def test_pgid
114
+ assert_respond_to(@@p1info, :pgid)
115
+ assert_kind_of(Integer, @@p1info.pgid)
116
+ assert_equal(Process.getpgrp, @@p1info.pgid)
117
+ end
118
+
119
+ def test_sid
120
+ assert_respond_to(@@p1info, :sid)
121
+ assert_kind_of(Integer, @@p1info.sid)
122
+ end
123
+
124
+ def test_ttydev
125
+ assert_respond_to(@@p1info, :ttydev)
126
+ assert_kind_of(Integer, @@p1info.ttydev)
127
+ end
128
+
129
+ def test_addr
130
+ assert_respond_to(@@p1info, :addr)
131
+ assert_kind_of(Integer, @@p1info.addr)
132
+ end
133
+
134
+ def test_size
135
+ assert_respond_to(@@p1info, :size)
136
+ assert_kind_of(Integer, @@p1info.size)
137
+ end
138
+
139
+ def test_rssize
140
+ assert_respond_to(@@p1info, :rssize)
141
+ assert_kind_of(Integer, @@p1info.rssize)
142
+ end
143
+
144
+ def test_start
145
+ assert_respond_to(@@p1info, :start)
146
+ assert_kind_of(Time, @@p1info.start)
147
+ end
148
+
149
+ def test_time
150
+ assert_respond_to(@@p1info, :time)
151
+ assert_kind_of(Integer, @@p1info.time)
152
+ end
153
+
154
+ def test_cid
155
+ assert_respond_to(@@p1info, :cid)
156
+ assert_kind_of(Fixnum, @@p1info.cid)
157
+ end
158
+
159
+ def test_argc
160
+ assert_respond_to(@@p1info, :argc)
161
+ assert_kind_of(Fixnum, @@p1info.argc)
162
+ assert_equal(@@p1args.size + 1, @@p1info.argc)
163
+ end
164
+
165
+ def test_argv
166
+ assert_respond_to(@@p1info, :argv)
167
+ assert_kind_of(Integer, @@p1info.argv)
168
+ end
169
+
170
+ def test_envp
171
+ assert_respond_to(@@p1info, :envp)
172
+ assert_kind_of(Integer, @@p1info.envp)
173
+ end
174
+
175
+ def test_fname
176
+ assert_respond_to(@@p1info, :fname)
177
+ assert_kind_of(String, @@p1info.fname)
178
+ end
179
+
180
+ def test_psargs
181
+ assert_respond_to(@@p1info, :psargs)
182
+ assert_kind_of(String, @@p1info.psargs)
183
+ end
184
+
185
+ def test_lwpid
186
+ assert_respond_to(@@p1info, :lwpid)
187
+ assert_kind_of(Integer, @@p1info.lwpid)
188
+ end
189
+
190
+ def test_wchan
191
+ assert_respond_to(@@p1info, :wchan)
192
+ assert_kind_of(Integer, @@p1info.wchan)
193
+ end
194
+
195
+ def test_wtype
196
+ assert_respond_to(@@p1info, :wtype)
197
+ assert_kind_of(Fixnum, @@p1info.wtype)
198
+ end
199
+
200
+ def test_state
201
+ assert_respond_to(@@p1info, :state)
202
+ assert_kind_of(Fixnum, @@p1info.state)
203
+ end
204
+
205
+ def test_sname
206
+ assert_respond_to(@@p1info, :sname)
207
+ assert_kind_of(String, @@p1info.sname)
208
+ end
209
+
210
+ def test_nice
211
+ assert_respond_to(@@p1info, :nice)
212
+ assert_kind_of(Fixnum, @@p1info.nice)
213
+ end
214
+
215
+ def test_pri
216
+ assert_respond_to(@@p1info, :pri)
217
+ assert_kind_of(Fixnum, @@p1info.pri)
218
+ end
219
+
220
+ def test_policy
221
+ assert_respond_to(@@p1info, :policy)
222
+ assert_kind_of(Fixnum, @@p1info.policy)
223
+ end
224
+
225
+ def test_clname
226
+ assert_respond_to(@@p1info, :clname)
227
+ assert_kind_of(String, @@p1info.clname)
228
+ end
229
+
230
+ def test_onpro
231
+ assert_respond_to(@@p1info, :onpro)
232
+ assert_kind_of(Fixnum, @@p1info.onpro)
233
+ end
234
+
235
+ def test_bindpro
236
+ assert_respond_to(@@p1info, :bindpro)
237
+ assert_kind_of(Fixnum, @@p1info.bindpro)
238
+ end
239
+
240
+ def test_ptid
241
+ assert_respond_to(@@p1info, :ptid)
242
+ assert_kind_of(Fixnum, @@p1info.ptid)
243
+ end
244
+
245
+ def test_comm
246
+ assert_respond_to(@@p1info, :comm)
247
+ assert_kind_of(String, @@p1info.comm)
248
+ end
249
+
250
+ def test_fd
251
+ assert_respond_to(@@p1info, :fd)
252
+ assert_kind_of(Array, @@p1info.fd)
253
+ end
254
+
255
+ def test_cmd_args
256
+ assert_respond_to(@@p1info, :cmd_args)
257
+ assert_kind_of(Array, @@p1info.cmd_args)
258
+ assert_equal([ 'ruby', @@p1args ].flatten, @@p1info.cmd_args)
259
+
260
+ assert_respond_to(@@p2info, :cmd_args)
261
+ assert_kind_of(Array, @@p2info.cmd_args)
262
+ assert_equal([ 'ruby', @@p2args ].flatten, @@p2info.cmd_args)
263
+ end
264
+
265
+ def test_environ
266
+ assert_respond_to(@@p1info, :environ)
267
+ assert_kind_of(Hash, @@p1info.environ)
268
+ assert_equal(@@myenv, @@p1info.environ)
269
+
270
+ assert_respond_to(@@p2info, :environ)
271
+ assert_kind_of(Hash, @@p2info.environ)
272
+ assert_equal(@@myenv, @@p2info.environ)
273
+ end
274
+
275
+ def test_cmdline
276
+ assert_respond_to(@@p1info, :cmdline)
277
+ assert_kind_of(String, @@p1info.cmdline)
278
+ end
279
+
280
+ def test_cwd
281
+ assert_respond_to(@@p1info, :cwd)
282
+ assert_kind_of([String, NilClass], @@p1info.cwd)
283
+ end
284
+
285
+ def test_map
286
+ assert_respond_to(@@p1info, :map)
287
+ assert_kind_of([Array, NilClass], @@p1info.map)
288
+ end
289
+
290
+ def test_map_struct
291
+ assert_not_nil(@@p1info.map)
292
+ assert_equal(@@map_fields.sort, @@p1info.map[0].members.sort)
293
+ end
294
+
295
+ def test_map_print
296
+ assert_not_nil(@@p1info.map)
297
+
298
+ @@p1info.map.each do |m|
299
+ assert_kind_of(Struct::ProcTableMapStruct, m)
300
+ assert_kind_of(Integer, m.size)
301
+ assert_kind_of(Integer, m.vaddr)
302
+ assert_kind_of(String, m.mapname)
303
+ assert_kind_of(Integer, m.size)
304
+ assert_kind_of(Integer, m.off)
305
+ assert_kind_of(Integer, m.mflags)
306
+ assert_kind_of(String, m.s_mflags)
307
+ assert_kind_of(Integer, m.pathoff)
308
+ assert_kind_of(Integer, m.alias)
309
+ assert_kind_of(Integer, m.gp)
310
+ assert_kind_of(String, m.path)
311
+ end
312
+ end
313
+
314
+ def self.shutdown
315
+ Process.kill('TERM', @@pid1)
316
+ Process.kill('TERM', @@pid2)
317
+ File.unlink('aix-child.rb') rescue nil
318
+ @@myenv = nil
319
+ @@pid1 = nil
320
+ @@pid2 = nil
321
+ @@p1info = nil
322
+ @@p2info = nil
323
+ end
324
+ end
@@ -0,0 +1,87 @@
1
+ #######################################################################
2
+ # test_sys_proctable_all.rb
3
+ #
4
+ # Test suite for methods common to all platforms. Generally speaking
5
+ # you should run this test case using the 'rake test' task.
6
+ #######################################################################
7
+ require 'test-unit'
8
+ require 'sys/proctable'
9
+ require 'test/test_sys_top'
10
+ include Sys
11
+
12
+ class TC_ProcTable_All < Test::Unit::TestCase
13
+ def self.startup
14
+ @@windows = File::ALT_SEPARATOR
15
+ end
16
+
17
+ def setup
18
+ @pid = @@windows ? 0 : 1
19
+ end
20
+
21
+ def test_version
22
+ assert_equal('0.9.9', ProcTable::VERSION)
23
+ end
24
+
25
+ def test_fields
26
+ assert_respond_to(ProcTable, :fields)
27
+ assert_nothing_raised{ ProcTable.fields }
28
+ assert_kind_of(Array, ProcTable.fields)
29
+ assert_kind_of(String, ProcTable.fields.first)
30
+ end
31
+
32
+ def test_ps
33
+ assert_respond_to(ProcTable, :ps)
34
+ assert_nothing_raised{ ProcTable.ps }
35
+ assert_nothing_raised{ ProcTable.ps{} }
36
+ end
37
+
38
+ def test_ps_with_pid
39
+ assert_nothing_raised{ ProcTable.ps(0) }
40
+ end
41
+
42
+ def test_ps_with_explicit_nil
43
+ assert_nothing_raised{ ProcTable.ps(nil) }
44
+ assert_kind_of(Array, ProcTable.ps(nil))
45
+ end
46
+
47
+ def test_ps_return_value
48
+ assert_kind_of(Array, ProcTable.ps)
49
+ assert_kind_of(Struct::ProcTableStruct, ProcTable.ps(@pid))
50
+ assert_equal(nil, ProcTable.ps(999999999))
51
+ assert_equal(nil, ProcTable.ps(999999999){})
52
+ assert_equal(nil, ProcTable.ps{})
53
+ end
54
+
55
+ def test_ps_returned_struct_is_frozen
56
+ assert_true(ProcTable.ps.first.frozen?)
57
+ end
58
+
59
+ def test_ps_expected_errors
60
+ assert_raises(TypeError){ ProcTable.ps('vim') }
61
+ omit_if(@@windows, 'ArgumentError check skipped on MS Windows')
62
+ assert_raises(ArgumentError){ ProcTable.ps(0, 'localhost') }
63
+ end
64
+
65
+ def test_new_not_allowed
66
+ assert_raise(NoMethodError){ Sys::ProcTable.new }
67
+ end
68
+
69
+ def test_error_class_defined
70
+ assert_not_nil(Sys::ProcTable::Error)
71
+ assert_kind_of(StandardError, Sys::ProcTable::Error.new)
72
+ end
73
+
74
+ def test_from_thread
75
+ Thread.new do
76
+ Sys::ProcTable.ps
77
+ end.value
78
+ end
79
+
80
+ def teardown
81
+ @pid = nil
82
+ end
83
+
84
+ def self.teardown
85
+ @@windows = nil
86
+ end
87
+ end