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.
@@ -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.6.4'
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.type(host = Socket.gethostname)
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.6.4'
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.extensions = ['ext/extconf.rb']
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
- 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"
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
@@ -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
- def test_architecture
17
- assert_respond_to(CPU, :architecture)
18
- assert_nothing_raised{ CPU.architecture }
19
- assert_kind_of(String, CPU.architecture)
20
- end
21
-
22
- def test_architecture_expected_errors
23
- assert_raises(ArgumentError){ CPU.architecture(0) }
24
- end
25
-
26
- def test_cpu_freq
27
- assert_respond_to(CPU, :freq)
28
- assert_nothing_raised{ CPU.freq }
29
- assert_kind_of(Integer, CPU.freq)
30
- end
31
-
32
- def test_cpu_freq_expected_errors
33
- assert_raises(ArgumentError){ CPU.freq(0) }
34
- end
35
-
36
- def test_load_avg
37
- assert_respond_to(CPU, :load_avg)
38
- assert_nothing_raised{ CPU.load_avg }
39
- assert_kind_of(Array, CPU.load_avg)
40
- assert_equal(3,CPU.load_avg.length)
41
- end
42
-
43
- def test_load_avg_expected_errors
44
- assert_raises(ArgumentError){ CPU.load_avg(0) }
45
- end
46
-
47
- def test_machine
48
- assert_respond_to(CPU, :machine)
49
- assert_nothing_raised{ CPU.machine }
50
- assert_kind_of(String, CPU.machine)
51
- end
52
-
53
- def test_machine_expected_errors
54
- assert_raises(ArgumentError){ CPU.machine(0) }
55
- end
56
-
57
- def test_model
58
- assert_respond_to(CPU, :model)
59
- assert_nothing_raised{ CPU.model }
60
- assert_kind_of(String, CPU.model)
61
- end
62
-
63
- def test_model_expected_errors
64
- assert_raises(ArgumentError){ CPU.model(0) }
65
- end
66
-
67
- def test_num_cpu
68
- assert_respond_to(CPU, :num_cpu)
69
- assert_nothing_raised{ CPU.num_cpu }
70
- assert_kind_of(Integer, CPU.num_cpu)
71
- end
72
-
73
- def test_num_cpu_expected_errors
74
- assert_raises(ArgumentError){ CPU.num_cpu(0) }
75
- end
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
@@ -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
- def test_cpu_freq
16
- assert_respond_to(CPU, :freq)
17
- assert_nothing_raised{ CPU.freq }
18
- assert_nothing_raised{ CPU.freq(0) }
19
- assert_kind_of(Integer, CPU.freq(0))
20
- end
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
- def test_cpu_type
23
- assert_respond_to(CPU, :cpu_type)
24
- assert_nothing_raised{ CPU.cpu_type }
25
- assert_kind_of(String, CPU.cpu_type)
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
- def test_fpu_type
29
- assert_respond_to(CPU, :fpu_type)
30
- assert_nothing_raised{ CPU.fpu_type }
31
- assert_kind_of(String, CPU.fpu_type)
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
- def test_load_avg
35
- assert_respond_to(CPU, :load_avg)
36
- assert_nothing_raised{ CPU.load_avg }
37
- assert_kind_of(Array, CPU.load_avg)
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
- def test_cpu_model
43
- assert_respond_to(CPU, :model)
44
- assert_nothing_raised{ CPU.model }
45
- assert_kind_of(String, CPU.model)
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
- def test_num_cpu
49
- assert_respond_to(CPU, :num_cpu)
50
- assert_nothing_raised{ CPU.num_cpu }
51
- assert_kind_of(Integer, CPU.num_cpu)
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
- def test_state
55
- assert_respond_to(CPU, :state)
56
- assert_nothing_raised{ CPU.state }
57
- assert_nothing_raised{ CPU.state(0) }
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
- def test_expected_errors
62
- assert_raises(Sys::CPU::Error){ CPU.state(55) }
63
- assert_raises(TypeError){ CPU.state('yo') }
64
- assert_raises(Sys::CPU::Error){ CPU.freq(999) }
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
- def test_version
16
- assert_equal('0.6.4', Sys::CPU::VERSION)
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 test_type
51
- assert_respond_to(CPU, :type)
52
- assert_nothing_raised{ CPU.type }
53
- assert_nothing_raised{ CPU.type(@@host) }
54
- assert_kind_of(String, CPU.type, 'Invalid Type')
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