sys-cpu 0.6.4-universal-linux → 0.7.0-universal-linux
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +11 -1
- data/README +6 -2
- data/Rakefile +19 -50
- data/doc/sunos.txt +2 -2
- data/doc/windows.txt +2 -2
- data/examples/example_sys_cpu_windows.rb +5 -4
- data/lib/linux/sys/cpu.rb +1 -1
- data/lib/unix/sys/cpu.rb +347 -0
- data/lib/windows/sys/cpu.rb +4 -4
- data/sys-cpu.gemspec +4 -11
- data/test/test_sys_cpu.rb +12 -12
- data/test/test_sys_cpu_bsd.rb +84 -60
- data/test/test_sys_cpu_sunos.rb +62 -46
- data/test/test_sys_cpu_version.rb +2 -2
- data/test/test_sys_cpu_windows.rb +13 -13
- metadata +25 -13
- data/ext/bsd/bsd.c +0 -331
- data/ext/extconf.rb +0 -26
- data/ext/hpux/hpux.c +0 -219
- data/ext/sunos/sunos.c +0 -281
- data/ext/version.h +0 -2
data/lib/windows/sys/cpu.rb
CHANGED
@@ -9,7 +9,7 @@ module Sys
|
|
9
9
|
class Error < StandardError; end
|
10
10
|
|
11
11
|
# The version of the sys-cpu library
|
12
|
-
VERSION = '0.
|
12
|
+
VERSION = '0.7.0'
|
13
13
|
|
14
14
|
private
|
15
15
|
|
@@ -17,7 +17,7 @@ module Sys
|
|
17
17
|
BASE_CS = "winmgmts:{impersonationLevel=impersonate}" # :nodoc:
|
18
18
|
|
19
19
|
# Fields used in the CPUStruct
|
20
|
-
fields = %w
|
20
|
+
fields = %w[
|
21
21
|
address_width
|
22
22
|
architecture
|
23
23
|
availability
|
@@ -62,7 +62,7 @@ module Sys
|
|
62
62
|
upgrade_method
|
63
63
|
version
|
64
64
|
voltage_caps
|
65
|
-
|
65
|
+
]
|
66
66
|
|
67
67
|
# The struct returned by the CPU.processors method
|
68
68
|
CPUStruct = Struct.new("CPUStruct", *fields) # :nodoc:
|
@@ -255,7 +255,7 @@ module Sys
|
|
255
255
|
|
256
256
|
# Returns a string indicating the type of processor, e.g. GenuineIntel.
|
257
257
|
#
|
258
|
-
def self.
|
258
|
+
def self.cpu_type(host = Socket.gethostname)
|
259
259
|
cs = BASE_CS + "//#{host}/root/cimv2:Win32_Processor='cpu0'"
|
260
260
|
begin
|
261
261
|
wmi = WIN32OLE.connect(cs)
|
data/sys-cpu.gemspec
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'sys-cpu'
|
5
|
-
spec.version = '0.
|
5
|
+
spec.version = '0.7.0'
|
6
6
|
spec.author = 'Daniel J. Berger'
|
7
7
|
spec.email = 'djberg96 at nospam at gmail dot com'
|
8
8
|
spec.homepage = 'http://www.rubyforge.org/projects/sysutils'
|
@@ -14,6 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.rubyforge_project = 'sysutils'
|
15
15
|
spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
|
16
16
|
|
17
|
+
spec.add_dependency('ffi', '>= 1.0.0')
|
17
18
|
spec.add_development_dependency('test-unit', '>= 2.1.2')
|
18
19
|
|
19
20
|
spec.description = <<-EOF
|
@@ -22,15 +23,6 @@ Gem::Specification.new do |spec|
|
|
22
23
|
and load average.
|
23
24
|
EOF
|
24
25
|
|
25
|
-
case Config::CONFIG['host_os']
|
26
|
-
when /hpux/i
|
27
|
-
spec.extra_rdoc_files += ['ext/hpux/hpux.c']
|
28
|
-
when /sunos|solaris/i
|
29
|
-
spec.extra_rdoc_files += ['ext/sunos/sunos.c']
|
30
|
-
when /bsd|darwin|mach|osx/i
|
31
|
-
spec.extra_rdoc_files += ['ext/bsd/bsd.c']
|
32
|
-
end
|
33
|
-
|
34
26
|
case Config::CONFIG['host_os']
|
35
27
|
when /mswin|dos|windows|win32|mingw|cygwin/i
|
36
28
|
spec.require_paths = ['lib', 'lib/windows']
|
@@ -45,6 +37,7 @@ Gem::Specification.new do |spec|
|
|
45
37
|
spec.platform = Gem::Platform.new('universal-linux')
|
46
38
|
spec.original_platform = spec.platform
|
47
39
|
else
|
48
|
-
spec.
|
40
|
+
spec.require_paths = ['lib', 'lib/unix']
|
41
|
+
spec.extra_rdoc_files << 'lib/unix/sys/cpu.rb'
|
49
42
|
end
|
50
43
|
end
|
data/test/test_sys_cpu.rb
CHANGED
@@ -8,16 +8,16 @@ require 'rbconfig'
|
|
8
8
|
require 'test_sys_cpu_version'
|
9
9
|
|
10
10
|
case Config::CONFIG['host_os']
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
when /bsd|darwin|mach|osx/i
|
12
|
+
require 'test_sys_cpu_bsd'
|
13
|
+
when /hpux/i
|
14
|
+
require 'test_sys_cpu_hpux'
|
15
|
+
when /linux/i
|
16
|
+
require 'test_sys_cpu_linux'
|
17
|
+
when /sunos|solaris/i
|
18
|
+
require 'test_sys_cpu_sunos'
|
19
|
+
when /mswin|win32|dos|mingw|cygwin/i
|
20
|
+
require 'test_sys_cpu_windows'
|
21
|
+
else
|
22
|
+
raise "Platform not supported"
|
23
23
|
end
|
data/test/test_sys_cpu_bsd.rb
CHANGED
@@ -13,64 +13,88 @@ require 'test_sys_cpu_version'
|
|
13
13
|
include Sys
|
14
14
|
|
15
15
|
class TC_Sys_CPU_BSD < Test::Unit::TestCase
|
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
|
-
|
16
|
+
test "architecture method basic functionality" do
|
17
|
+
assert_respond_to(CPU, :architecture)
|
18
|
+
assert_nothing_raised{ CPU.architecture }
|
19
|
+
end
|
20
|
+
|
21
|
+
test "architecture method returns a sane value" do
|
22
|
+
assert_kind_of(String, CPU.architecture)
|
23
|
+
assert_true(CPU.architecture.size > 0)
|
24
|
+
end
|
25
|
+
|
26
|
+
test "architecture method does not accept any arguments" do
|
27
|
+
assert_raises(ArgumentError){ CPU.architecture(0) }
|
28
|
+
end
|
29
|
+
|
30
|
+
test "freq method basic functionality" do
|
31
|
+
assert_respond_to(CPU, :freq)
|
32
|
+
assert_nothing_raised{ CPU.freq }
|
33
|
+
end
|
34
|
+
|
35
|
+
test "freq method returns expected value" do
|
36
|
+
assert_kind_of(Integer, CPU.freq)
|
37
|
+
assert_true(CPU.freq > 0)
|
38
|
+
end
|
39
|
+
|
40
|
+
test "freq method does not accept any arguments" do
|
41
|
+
assert_raises(ArgumentError){ CPU.freq(0) }
|
42
|
+
end
|
43
|
+
|
44
|
+
test "load_avg method basic functionality" do
|
45
|
+
assert_respond_to(CPU, :load_avg)
|
46
|
+
assert_nothing_raised{ CPU.load_avg }
|
47
|
+
end
|
48
|
+
|
49
|
+
test "load_avg returns the expected results" do
|
50
|
+
assert_kind_of(Array, CPU.load_avg)
|
51
|
+
assert_equal(3, CPU.load_avg.length)
|
52
|
+
assert_kind_of(Float, CPU.load_avg[0])
|
53
|
+
end
|
54
|
+
|
55
|
+
test "load_avg does not accept any arguments" do
|
56
|
+
assert_raises(ArgumentError){ CPU.load_avg(0) }
|
57
|
+
end
|
58
|
+
|
59
|
+
test "machine method basic functionality" do
|
60
|
+
assert_respond_to(CPU, :machine)
|
61
|
+
assert_nothing_raised{ CPU.machine }
|
62
|
+
end
|
63
|
+
|
64
|
+
test "machine method returns sane value" do
|
65
|
+
assert_kind_of(String, CPU.machine)
|
66
|
+
assert_true(CPU.machine.size > 0)
|
67
|
+
end
|
68
|
+
|
69
|
+
test "machine method does not accept any arguments" do
|
70
|
+
assert_raises(ArgumentError){ CPU.machine(0) }
|
71
|
+
end
|
72
|
+
|
73
|
+
test "model method basic functionality" do
|
74
|
+
assert_respond_to(CPU, :model)
|
75
|
+
assert_nothing_raised{ CPU.model }
|
76
|
+
end
|
77
|
+
|
78
|
+
test "model method returns sane value" do
|
79
|
+
assert_kind_of(String, CPU.model)
|
80
|
+
assert_true(CPU.model.length > 0)
|
81
|
+
end
|
82
|
+
|
83
|
+
test "model method does not accept any arguments" do
|
84
|
+
assert_raises(ArgumentError){ CPU.model(0) }
|
85
|
+
end
|
86
|
+
|
87
|
+
test "num_cpu method basic functionality" do
|
88
|
+
assert_respond_to(CPU, :num_cpu)
|
89
|
+
assert_nothing_raised{ CPU.num_cpu }
|
90
|
+
end
|
91
|
+
|
92
|
+
test "num_cpu method returns expected value" do
|
93
|
+
assert_kind_of(Integer, CPU.num_cpu)
|
94
|
+
assert_true(CPU.num_cpu > 0)
|
95
|
+
end
|
96
|
+
|
97
|
+
test "num_cpu method does not accept any arguments" do
|
98
|
+
assert_raises(ArgumentError){ CPU.num_cpu(0) }
|
99
|
+
end
|
76
100
|
end
|
data/test/test_sys_cpu_sunos.rb
CHANGED
@@ -6,62 +6,78 @@
|
|
6
6
|
###########################################################
|
7
7
|
require 'rubygems'
|
8
8
|
gem 'test-unit'
|
9
|
-
|
10
9
|
require 'sys/cpu'
|
11
10
|
require 'test/unit'
|
12
11
|
include Sys
|
13
12
|
|
14
13
|
class TC_Sys_CPU_SunOS < Test::Unit::TestCase
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
test "freq method basic functionality" do
|
15
|
+
assert_respond_to(CPU, :freq)
|
16
|
+
assert_nothing_raised{ CPU.freq }
|
17
|
+
end
|
18
|
+
|
19
|
+
test "freq method does not accept any arguments" do
|
20
|
+
assert_raise(ArgumentError){ CPU.freq(0) }
|
21
|
+
end
|
22
|
+
|
23
|
+
test "freq method returns a sane value" do
|
24
|
+
assert_kind_of(Integer, CPU.freq)
|
25
|
+
assert_true(CPU.freq > 100)
|
26
|
+
end
|
27
|
+
|
28
|
+
test "fpu_type basic functionality" do
|
29
|
+
assert_respond_to(CPU, :fpu_type)
|
30
|
+
assert_nothing_raised{ CPU.fpu_type }
|
31
|
+
end
|
32
|
+
|
33
|
+
test "fpu_type returns a sane value" do
|
34
|
+
assert_kind_of(String, CPU.fpu_type)
|
35
|
+
assert_false(CPU.fpu_type.empty?)
|
36
|
+
end
|
37
|
+
|
38
|
+
test "load_avg basic functionality" do
|
39
|
+
assert_respond_to(CPU, :load_avg)
|
40
|
+
assert_nothing_raised{ CPU.load_avg }
|
41
|
+
end
|
42
|
+
|
43
|
+
test "load_avg method returns the expected values" do
|
44
|
+
assert_kind_of(Array, CPU.load_avg)
|
45
|
+
assert_equal(3, CPU.load_avg.length)
|
46
|
+
assert_kind_of(Float, CPU.load_avg.first)
|
47
|
+
end
|
21
48
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
49
|
+
test "model method basic functionality" do
|
50
|
+
assert_respond_to(CPU, :model)
|
51
|
+
assert_nothing_raised{ CPU.model }
|
52
|
+
end
|
27
53
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
54
|
+
test "model method returns a sane value" do
|
55
|
+
assert_kind_of(String, CPU.model)
|
56
|
+
assert_false(CPU.model.empty?)
|
57
|
+
end
|
33
58
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
assert_equal(3, CPU.load_avg.length)
|
39
|
-
assert_kind_of(Float, CPU.load_avg.first)
|
40
|
-
end
|
59
|
+
test "num_cpu method basic functionalty" do
|
60
|
+
assert_respond_to(CPU, :num_cpu)
|
61
|
+
assert_nothing_raised{ CPU.num_cpu }
|
62
|
+
end
|
41
63
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
64
|
+
test "num_cpu method returns a sane value" do
|
65
|
+
assert_kind_of(Integer, CPU.num_cpu)
|
66
|
+
assert_true(CPU.num_cpu > 0)
|
67
|
+
end
|
47
68
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
69
|
+
test "state basic functionality" do
|
70
|
+
assert_respond_to(CPU, :state)
|
71
|
+
assert_nothing_raised{ CPU.state }
|
72
|
+
end
|
53
73
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
assert_kind_of(String, CPU.state(0))
|
59
|
-
end
|
74
|
+
test "state method accepts one optional argument" do
|
75
|
+
assert_nothing_raised{ CPU.state(0) }
|
76
|
+
assert_raise(ArgumentError){ CPU.state(0,0) }
|
77
|
+
end
|
60
78
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
assert_raises(TypeError){ CPU.freq('yo') }
|
66
|
-
end
|
79
|
+
test "state method returns a sane value" do
|
80
|
+
assert_kind_of(String, CPU.state(0))
|
81
|
+
assert_false(CPU.state.empty?)
|
82
|
+
end
|
67
83
|
end
|
@@ -12,7 +12,7 @@ require 'sys/cpu'
|
|
12
12
|
require 'test/unit'
|
13
13
|
|
14
14
|
class TC_Sys_CPU_VERSION < Test::Unit::TestCase
|
15
|
-
|
16
|
-
assert_equal('0.
|
15
|
+
test "version number is set to the expected value" do
|
16
|
+
assert_equal('0.7.0', Sys::CPU::VERSION)
|
17
17
|
end
|
18
18
|
end
|
@@ -17,14 +17,14 @@ class TC_Sys_CPU_Windows < Test::Unit::TestCase
|
|
17
17
|
def self.startup
|
18
18
|
@@host = Socket.gethostname
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def test_architecture
|
22
22
|
assert_respond_to(CPU, :architecture)
|
23
23
|
assert_nothing_raised{ CPU.architecture }
|
24
24
|
assert_nothing_raised{ CPU.architecture(@@host) }
|
25
25
|
assert_kind_of(String, CPU.architecture, 'Invalid Type')
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def test_freq
|
29
29
|
assert_respond_to(CPU, :freq)
|
30
30
|
assert_nothing_raised{ CPU.freq }
|
@@ -32,35 +32,35 @@ class TC_Sys_CPU_Windows < Test::Unit::TestCase
|
|
32
32
|
assert_nothing_raised{ CPU.freq(0, @@host) }
|
33
33
|
assert_kind_of(Integer, CPU.freq, 'Invalid Type')
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def test_model
|
37
37
|
assert_respond_to(CPU, :model)
|
38
38
|
assert_nothing_raised{ CPU.model }
|
39
39
|
assert_nothing_raised{ CPU.model(@@host) }
|
40
40
|
assert_kind_of(String, CPU.model, 'Invalid Type')
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def test_num_cpu
|
44
44
|
assert_respond_to(CPU, :num_cpu)
|
45
45
|
assert_nothing_raised{ CPU.num_cpu }
|
46
46
|
assert_nothing_raised{ CPU.num_cpu(@@host) }
|
47
47
|
assert_kind_of(Integer, CPU.num_cpu, 'Invalid Type')
|
48
48
|
end
|
49
|
-
|
50
|
-
def
|
51
|
-
assert_respond_to(CPU, :
|
52
|
-
assert_nothing_raised{ CPU.
|
53
|
-
assert_nothing_raised{ CPU.
|
54
|
-
assert_kind_of(String, CPU.
|
49
|
+
|
50
|
+
def test_cpu_type
|
51
|
+
assert_respond_to(CPU, :cpu_type)
|
52
|
+
assert_nothing_raised{ CPU.cpu_type }
|
53
|
+
assert_nothing_raised{ CPU.cpu_type(@@host) }
|
54
|
+
assert_kind_of(String, CPU.cpu_type, 'Invalid Type')
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def test_load_avg
|
58
58
|
assert_respond_to(CPU, :load_avg)
|
59
59
|
assert_nothing_raised{ CPU.load_avg }
|
60
60
|
assert_nothing_raised{ CPU.load_avg(0, @@host) }
|
61
61
|
assert_kind_of(Integer, CPU.load_avg, 'Invalid Type')
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
def test_processors
|
65
65
|
assert_respond_to(CPU, :processors)
|
66
66
|
assert_nothing_raised{ CPU.processors{} }
|
@@ -68,5 +68,5 @@ class TC_Sys_CPU_Windows < Test::Unit::TestCase
|
|
68
68
|
|
69
69
|
def self.shutdown
|
70
70
|
@@host = nil
|
71
|
-
end
|
71
|
+
end
|
72
72
|
end
|