sys-proctable 1.0.0-universal-darwin → 1.1.0-universal-darwin

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,252 +7,99 @@
7
7
  require 'test-unit'
8
8
  require 'sys/proctable'
9
9
  require 'test/test_sys_proctable_all'
10
- include Sys
11
10
 
12
11
  class TC_ProcTable_Darwin < Test::Unit::TestCase
13
12
  def self.startup
14
- @@fields = %w/
15
- pid ppid pgid ruid rgid euid egid groups svuid svgid
16
- comm state pctcpu oncpu tnum
17
- tdev wmesg rtime priority usrpri nice cmdline exe environ starttime
18
- maxrss ixrss idrss isrss minflt majflt nswap inblock oublock
19
- msgsnd msgrcv nsignals nvcsw nivcsw utime stime
20
- /
13
+ @@fields = %w[
14
+ flags status xstatus pid ppid uid gid ruid rgid svuid svgid rfu1 comm
15
+ name nfiles pgid pjobc tdev tpgid nice start_tvsec start_tvusec
16
+ virtual_size resident_size total_user total_system threads_user
17
+ threads_system policy faults pageins cow_faults messages_sent
18
+ messages_received syscalls_mach syscalls_unix csw threadnum numrunning
19
+ priority cmdline exe environ
20
+ ]
21
21
 
22
22
  @@pid = fork do
23
23
  exec('env', '-i', 'A=B', 'Z=', 'sleep', '60')
24
24
  end
25
+
25
26
  sleep 1 # wait to make sure env is replaced by sleep
26
27
  end
27
28
 
28
29
  def setup
29
- @ptable = ProcTable.ps.find{ |ptable| ptable.pid == @@pid }
30
+ @ptable = Sys::ProcTable.ps(@@pid)
30
31
  end
31
32
 
32
- def test_fields
33
- assert_respond_to(ProcTable, :fields)
34
- assert_kind_of(Array, ProcTable.fields)
35
- assert_equal(@@fields, ProcTable.fields)
33
+ test "fields basic functionality" do
34
+ assert_respond_to(Sys::ProcTable, :fields)
35
+ assert_kind_of(Array, Sys::ProcTable.fields)
36
+ assert_equal(@@fields, Sys::ProcTable.fields)
36
37
  end
37
38
 
38
- def test_pid
39
+ test "pid struct member is defined and returns expected value" do
39
40
  assert_respond_to(@ptable, :pid)
40
41
  assert_kind_of(Fixnum, @ptable.pid)
41
42
  assert_equal(@ptable.pid, @@pid)
42
43
  end
43
44
 
44
- def test_ppid
45
+ test "ppid struct member is defined and returns expected value" do
45
46
  assert_respond_to(@ptable, :ppid)
46
47
  assert_kind_of(Fixnum, @ptable.ppid)
47
48
  assert_equal(Process.pid, @ptable.ppid)
48
49
  end
49
50
 
50
- def test_pgid
51
+ test "pgid struct member is defined and returns expected value" do
51
52
  assert_respond_to(@ptable, :pgid)
52
53
  assert_kind_of(Fixnum, @ptable.pgid)
53
54
  assert_equal(Process.getpgrp, @ptable.pgid)
54
55
  end
55
56
 
56
- def test_ruid
57
+ test "ruid struct member is defined and returns expected value" do
57
58
  assert_respond_to(@ptable, :ruid)
58
59
  assert_kind_of(Fixnum, @ptable.ruid)
59
60
  assert_equal(Process.uid, @ptable.ruid)
60
61
  end
61
62
 
62
- def test_rgid
63
+ test "rgid struct member is defined and returns expected value" do
63
64
  assert_respond_to(@ptable, :rgid)
64
65
  assert_kind_of(Fixnum, @ptable.rgid)
65
66
  assert_equal(Process.gid, @ptable.rgid)
66
67
  end
67
68
 
68
- def test_euid
69
- assert_respond_to(@ptable, :euid)
70
- assert_kind_of(Fixnum, @ptable.euid)
71
- assert_equal(Process.euid, @ptable.euid)
72
- end
73
-
74
- def test_egid
75
- assert_respond_to(@ptable, :egid)
76
- assert_kind_of(Fixnum, @ptable.egid)
77
- assert_equal(Process.egid, @ptable.egid)
78
- end
79
-
80
- def test_groups
81
- assert_respond_to(@ptable, :groups)
82
- assert_kind_of(Array, @ptable.groups)
83
- assert_equal(Process.groups, @ptable.groups)
84
- end
85
-
86
- def test_svuid
69
+ test "svuid struct member is defined and returns expected value" do
87
70
  assert_respond_to(@ptable, :svuid)
88
71
  assert_kind_of(Fixnum, @ptable.svuid)
89
72
  assert_equal(Process.uid, @ptable.svuid) # not valid for all processes
90
73
  end
91
74
 
92
- def test_svgid
75
+ test "svgid struct member is defined and returns expected value" do
93
76
  assert_respond_to(@ptable, :svgid)
94
77
  assert_kind_of(Fixnum, @ptable.svgid)
95
78
  assert_equal(Process.gid, @ptable.svgid) # not valid for all processes
96
79
  end
97
80
 
98
- def test_comm
81
+ test "comm struct member is defined and returns expected value" do
99
82
  assert_respond_to(@ptable, :comm)
100
83
  assert_kind_of(String, @ptable.comm)
101
84
  assert_equal('sleep', @ptable.comm)
102
85
  end
103
86
 
104
- def test_state
105
- assert_respond_to(@ptable, :state)
106
- assert_kind_of(String, @ptable.state)
107
- assert_true(%w/idle run sleep stop zombie unknown/.include?(@ptable.state))
108
- end
109
-
110
- def test_pctcpu
111
- assert_respond_to(@ptable, :pctcpu)
112
- assert_kind_of(Float, @ptable.pctcpu)
113
- end
114
-
115
- def test_oncpu
116
- assert_respond_to(@ptable, :oncpu)
117
- omit("oncpu always nil for now")
118
- end
119
-
120
- def test_tnum
121
- assert_respond_to(@ptable, :tnum)
122
- #assert_kind_of(Fixnum, @ptable.tnum)
123
- end
124
-
125
- def test_tdev
126
- assert_respond_to(@ptable, :tdev)
127
- #assert_kind_of(String, @ptable.tdev)
128
- end
129
-
130
- def test_wmesg
131
- assert_respond_to(@ptable, :wmesg)
132
- assert_kind_of(String, @ptable.wmesg)
133
- end
134
-
135
- def test_rtime
136
- assert_respond_to(@ptable, :rtime)
137
- assert_kind_of(Fixnum, @ptable.rtime)
138
- end
139
-
140
- def test_priority
141
- assert_respond_to(@ptable, :priority)
142
- assert_kind_of(Fixnum, @ptable.priority)
143
- end
144
-
145
- def test_usrpri
146
- assert_respond_to(@ptable, :usrpri)
147
- assert_kind_of(Fixnum, @ptable.usrpri)
148
- end
149
-
150
- def test_nice
151
- assert_respond_to(@ptable, :nice)
152
- assert_kind_of(Fixnum, @ptable.nice)
153
- end
154
-
155
- def test_cmdline
87
+ test "cmdline struct member is defined and returns expected value" do
156
88
  assert_respond_to(@ptable, :cmdline)
157
89
  assert_kind_of(String, @ptable.cmdline)
158
90
  assert_equal('sleep 60', @ptable.cmdline)
159
91
  end
160
92
 
161
- def test_exe
93
+ test "exe struct member is defined and returns expected value" do
162
94
  assert_respond_to(@ptable, :exe)
163
95
  assert_kind_of(String, @ptable.exe)
164
96
  assert_equal(`which sleep`.chomp, @ptable.exe)
165
97
  end
166
98
 
167
- def test_environ
99
+ test "environ struct member is defined and returns expected value" do
168
100
  assert_respond_to(@ptable, :environ)
169
101
  assert_kind_of(Hash, @ptable.environ)
170
- assert_equal({'A' => 'B', 'Z' => ''}, @ptable.environ)
171
- end
172
-
173
- def test_starttime
174
- assert_respond_to(@ptable, :starttime)
175
- assert_kind_of(Time, @ptable.starttime)
176
- end
177
-
178
- def test_maxrss
179
- assert_respond_to(@ptable, :maxrss)
180
- assert_true([NilClass, Fixnum].include?(@ptable.maxrss.class))
181
- end
182
-
183
- def test_ixrss
184
- assert_respond_to(@ptable, :ixrss)
185
- assert_true([NilClass, Fixnum].include?(@ptable.ixrss.class))
186
- end
187
-
188
- def test_idrss
189
- assert_respond_to(@ptable, :idrss)
190
- assert_true([NilClass, Fixnum].include?(@ptable.idrss.class))
191
- end
192
-
193
- def test_isrss
194
- assert_respond_to(@ptable, :isrss)
195
- assert_true([NilClass, Fixnum].include?(@ptable.isrss.class))
196
- end
197
-
198
- def test_minflt
199
- assert_respond_to(@ptable, :minflt)
200
- assert_true([NilClass, Fixnum].include?(@ptable.minflt.class))
201
- end
202
-
203
- def test_majflt
204
- assert_respond_to(@ptable, :majflt)
205
- assert_true([NilClass, Fixnum].include?(@ptable.majflt.class))
206
- end
207
-
208
- def test_nswap
209
- assert_respond_to(@ptable, :nswap)
210
- assert_true([NilClass, Fixnum].include?(@ptable.nswap.class))
211
- end
212
-
213
- def test_inblock
214
- assert_respond_to(@ptable, :inblock)
215
- assert_true([NilClass, Fixnum].include?(@ptable.inblock.class))
216
- end
217
-
218
- def test_oublock
219
- assert_respond_to(@ptable, :oublock)
220
- assert_true([NilClass, Fixnum].include?(@ptable.oublock.class))
221
- end
222
-
223
- def test_msgsnd
224
- assert_respond_to(@ptable, :msgsnd)
225
- assert_true([NilClass, Fixnum].include?(@ptable.msgsnd.class))
226
- end
227
-
228
- def test_msgrcv
229
- assert_respond_to(@ptable, :msgrcv)
230
- assert_true([NilClass, Fixnum].include?(@ptable.msgrcv.class))
231
- end
232
-
233
- def test_nsignals
234
- assert_respond_to(@ptable, :nsignals)
235
- assert_true([NilClass, Fixnum].include?(@ptable.nsignals.class))
236
- end
237
-
238
- def test_nvcsw
239
- assert_respond_to(@ptable, :nvcsw)
240
- assert_true([NilClass, Fixnum].include?(@ptable.nvcsw.class))
241
- end
242
-
243
- def test_nivcsw
244
- assert_respond_to(@ptable, :nivcsw)
245
- assert_true([NilClass, Fixnum].include?(@ptable.nivcsw.class))
246
- end
247
-
248
- def test_utime
249
- assert_respond_to(@ptable, :utime)
250
- assert_true([NilClass, Fixnum].include?(@ptable.utime.class))
251
- end
252
-
253
- def test_stime
254
- assert_respond_to(@ptable, :stime)
255
- assert_true([NilClass, Fixnum].include?(@ptable.stime.class))
102
+ assert_equal({'A' => 'B', 'Z' => nil}, @ptable.environ)
256
103
  end
257
104
 
258
105
  def teardown
@@ -261,7 +108,6 @@ class TC_ProcTable_Darwin < Test::Unit::TestCase
261
108
 
262
109
  def self.shutdown
263
110
  @@fields = nil
264
-
265
111
  Process.kill('TERM', @@pid)
266
112
  end
267
113
  end
@@ -2,45 +2,64 @@
2
2
  # test_sys_top.rb
3
3
  #
4
4
  # Test suite for the sys-top library that is included with this distribution.
5
+ #
6
+ # Tests omitted on OSX until I figure out how to get pctcpu information.
5
7
  ##############################################################################
6
- require 'rubygems'
7
- gem 'test-unit'
8
-
9
- require 'test/unit'
8
+ require 'test-unit'
10
9
  require 'sys/top'
11
10
 
12
11
  class TC_Top < Test::Unit::TestCase
13
12
  include Sys
14
13
 
15
- def test_version
14
+ def setup
15
+ @osx = RbConfig::CONFIG['host_os'] =~ /darwin/i
16
+ end
17
+
18
+ test "top version" do
16
19
  assert_equal('1.0.4', Top::VERSION)
17
20
  end
18
21
 
19
- def test_top_basic
22
+ test "top basic functionality" do
20
23
  assert_respond_to(Top, :top)
24
+ end
25
+
26
+ test "top works with no arguments" do
27
+ omit_if(@osx)
21
28
  assert_nothing_raised{ Top.top }
29
+ end
30
+
31
+ test "top accepts optional arguments" do
32
+ omit_if(@osx)
22
33
  assert_nothing_raised{ Top.top(5) }
23
34
  assert_nothing_raised{ Top.top(5, 'cmdline') }
24
35
  end
25
36
 
26
- def test_top
37
+ test "top with no arguments returns expected results" do
38
+ omit_if(@osx)
27
39
  assert_equal(10, Top.top.length)
28
40
  assert_kind_of(Struct::ProcTableStruct, Top.top.first)
29
41
  end
30
42
 
31
- def test_top_with_size
43
+ test "top with size argument returns expected result" do
44
+ omit_if(@osx)
32
45
  assert_equal(5, Top.top(5).length)
33
46
  end
34
47
 
35
- def test_top_with_size_and_sort_by_field
48
+ test "top with size and sort_by argument returns expected result" do
49
+ omit_if(@osx)
36
50
  assert_equal(5, Top.top(5, :cmdline).length)
37
51
  end
38
52
 
39
- def test_top_return_type
53
+ test "top returns an array" do
54
+ omit_if(@osx)
40
55
  assert_kind_of(Array, Top.top)
41
56
  end
42
57
 
43
- def test_top_expected_errors
58
+ test "top accepts a maximum of two arguments" do
44
59
  assert_raises(ArgumentError){ Top.top(1, 'foo', 2) }
45
60
  end
61
+
62
+ def teardown
63
+ @osx = nil
64
+ end
46
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sys-proctable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: universal-darwin
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -30,7 +30,7 @@ cert_chain:
30
30
  EJYzxdPOrx2n6NYR3Hk+vHP0U7UBSveI6+qx+ndQYaeyCn+GRX2PKS9h66YF/Q1V
31
31
  tGSHgAmcLlkdGgan182qsE/4kKM=
32
32
  -----END CERTIFICATE-----
33
- date: 2016-01-11 00:00:00.000000000 Z
33
+ date: 2016-06-27 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: test-unit
@@ -60,6 +60,20 @@ dependencies:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: ffi
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
63
77
  description: |2
64
78
  The sys-proctable library provides an interface for gathering information
65
79
  about processes on your system, i.e. the process table. Most major
@@ -68,14 +82,12 @@ description: |2
68
82
  platforms.
69
83
  email: djberg96@gmail.com
70
84
  executables: []
71
- extensions:
72
- - ext/darwin/extconf.rb
85
+ extensions: []
73
86
  extra_rdoc_files:
74
87
  - CHANGES
75
88
  - README
76
89
  - MANIFEST
77
90
  - doc/top.txt
78
- - ext/darwin/sys/proctable.c
79
91
  files:
80
92
  - CHANGES
81
93
  - MANIFEST
@@ -89,15 +101,16 @@ files:
89
101
  - lib/sys/top.rb
90
102
  - sys-proctable.gemspec
91
103
  - test/test_sys_proctable_all.rb
92
- - ext/darwin/sys/proctable.c
104
+ - lib/darwin/sys/proctable.rb
93
105
  homepage: http://github.com/djberg96/sys-proctable
94
106
  licenses:
95
- - Artistic 2.0
107
+ - Apache 2.0
96
108
  metadata: {}
97
109
  post_install_message:
98
110
  rdoc_options: []
99
111
  require_paths:
100
112
  - lib
113
+ - lib/darwin
101
114
  required_ruby_version: !ruby/object:Gem::Requirement
102
115
  requirements:
103
116
  - - ">="
@@ -110,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
123
  version: '0'
111
124
  requirements: []
112
125
  rubyforge_project:
113
- rubygems_version: 2.5.1
126
+ rubygems_version: 2.6.4
114
127
  signing_key:
115
128
  specification_version: 4
116
129
  summary: An interface for providing process table information
metadata.gz.sig CHANGED
Binary file
@@ -1,4 +0,0 @@
1
- require 'mkmf'
2
-
3
- have_type('rb_pid_t', 'ruby.h')
4
- create_makefile('sys/proctable', 'sys')