sys-cpu 0.5.5-mswin32 → 0.6.0-mswin32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +12 -0
- data/MANIFEST +28 -0
- data/README +20 -19
- data/doc/{freebsd.txt → bsd.txt} +8 -6
- data/doc/hpux.txt +4 -4
- data/doc/sunos.txt +4 -2
- data/doc/windows.txt +3 -3
- data/lib/sys/cpu.rb +11 -11
- data/test/tc_bsd.rb +56 -0
- data/test/tc_cpu.rb +17 -0
- data/test/tc_hpux.rb +13 -27
- data/test/tc_linux.rb +5 -12
- data/test/tc_sunos.rb +8 -25
- data/test/tc_version.rb +1 -29
- data/test/tc_windows.rb +11 -18
- metadata +11 -8
- data/test/tc_freebsd.rb +0 -71
- data/test/ts_all.rb +0 -17
data/CHANGES
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
== 0.6.0 - 11-Apr-2007
|
2
|
+
* Added support for most BSD flavors, including OS X. The freebsd.c file is
|
3
|
+
now just bsd.c.
|
4
|
+
* The CPU.type method for Solaris has been changed to CPU.cpu_type to avoid
|
5
|
+
conflicting with the Object.type method.
|
6
|
+
* Added a Rakefile. There are now tasks for building, testing and installing,
|
7
|
+
among other things. Run 'rake -T' to check your options.
|
8
|
+
* Many internal directory layout changes - C source files are now under the
|
9
|
+
'ext' directory.
|
10
|
+
* Improved RDoc comments in the C source files.
|
11
|
+
* Changed CPUError to CPU::Error.
|
12
|
+
|
1
13
|
== 0.5.5 - 17-Nov-2006
|
2
14
|
* Fixed a bug in the Linux version where there could be a key but no
|
3
15
|
associated value, causing a String#strip! call to fail. Now the value is
|
data/MANIFEST
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
* install.rb
|
2
|
+
* MANIFEST
|
3
|
+
* CHANGES
|
4
|
+
* Rakefile
|
5
|
+
* README
|
6
|
+
* sys-cpu.gemspec
|
7
|
+
* doc/bsd.txt
|
8
|
+
* doc/hpux.txt
|
9
|
+
* doc/linux.txt
|
10
|
+
* doc/sunos.txt
|
11
|
+
* doc/windows.txt
|
12
|
+
* examples/test_cpu_freebsd.rb
|
13
|
+
* examples/test_cpu_hpux.rb
|
14
|
+
* examples/test_cpu_linux.rb
|
15
|
+
* examples/test_cpu_sunos.rb
|
16
|
+
* examples/test_cpu_windows.rb
|
17
|
+
* ext/extconf.rb
|
18
|
+
* ext/version.h
|
19
|
+
* ext/bsd/bsd.c
|
20
|
+
* ext/hpux/hpux.c
|
21
|
+
* ext/sunos/sunos.c
|
22
|
+
* lib/sys/linux.rb
|
23
|
+
* lib/sys/windows.rb
|
24
|
+
* test/tc_bsd.rb
|
25
|
+
* test/tc_hpux.rb
|
26
|
+
* test/tc_sunos.rb
|
27
|
+
* test/tc_linux.rb
|
28
|
+
* test/tc_windows.rb
|
data/README
CHANGED
@@ -2,26 +2,27 @@
|
|
2
2
|
A Ruby interface for getting cpu information.
|
3
3
|
|
4
4
|
= Installation
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
ruby
|
11
|
-
|
12
|
-
ruby test/ts_all.rb (optional)
|
13
|
-
make site-install
|
5
|
+
== Standard Installation
|
6
|
+
rake test (optional)
|
7
|
+
rake install (non-gem)
|
8
|
+
== Gem installation
|
9
|
+
rake test (optional)
|
10
|
+
ruby sys-cpu.gemspec
|
11
|
+
gem install sys-cpu-X.Y.Z.gem # where 'X.Y.Z' corresponds to the version.
|
14
12
|
|
15
13
|
= Notes
|
16
14
|
=== All Platforms
|
17
15
|
As of version 0.5.0 Ruby 1.8.0 or later is required. It may work with
|
18
|
-
earlier versions, but I will not support it.
|
19
|
-
no longer auto-generated for you. If wish to run the test suite, cd to the
|
20
|
-
'test' directory and run the test suite appropriate for your platform.
|
16
|
+
earlier versions, but I will not support it.
|
21
17
|
|
22
18
|
=== Solaris
|
23
19
|
Currently there is no 'processors()' iterative method for multi-cpu systems.
|
24
20
|
I plan to add it this in a future release.
|
21
|
+
|
22
|
+
=== OS X
|
23
|
+
The CPU.freq method is not supported at the moment. The sysctl() approach
|
24
|
+
returns a bogus, hard coded value of some sort. I suspect it's possible
|
25
|
+
by using kernel modules via kldload(), but I'm not sure how yet.
|
25
26
|
|
26
27
|
=== Linux
|
27
28
|
This is pure Ruby. This version reads information out of /proc/cpuinfo and
|
@@ -35,14 +36,14 @@
|
|
35
36
|
The text documentation for Linux is dynamically generated during the
|
36
37
|
build process because the fields vary depending on your setup. So, don't
|
37
38
|
look at it until *after* you've installed it. You will see a doc/linux.txt
|
38
|
-
file after you run install.rb.
|
39
|
+
file after you run 'rake install' (via install.rb).
|
39
40
|
|
40
41
|
=== HP-UX
|
41
42
|
Unlike other platforms, you can get load averages for an individual cpu (in
|
42
|
-
multi-cpu systems).
|
43
|
+
multi-cpu systems). See documentation for more details.
|
43
44
|
|
44
|
-
===
|
45
|
-
This is a pure Ruby implementation using the win32ole package + WMI.
|
45
|
+
=== MS Windows
|
46
|
+
This is a pure Ruby implementation using the win32ole package + WMI. The C
|
46
47
|
version has been scrapped.
|
47
48
|
|
48
49
|
As of version 0.5.0, the CPU.usage method has been removed in favor of the
|
@@ -56,15 +57,15 @@
|
|
56
57
|
http://www.rubyforge.org/projects/sysutils.
|
57
58
|
|
58
59
|
= Future Plans
|
59
|
-
=== Solaris
|
60
60
|
Add iterative CPU.processors method.
|
61
|
+
Make CPU.freq work on OS X.
|
61
62
|
Add more information in general, such as what 'prtdiag' shows.
|
62
63
|
|
63
64
|
= License
|
64
65
|
Ruby's.
|
65
66
|
|
66
67
|
= Copyright
|
67
|
-
(C) 2003-
|
68
|
+
(C) 2003-2007 Daniel J. Berger
|
68
69
|
All Rights Reserved
|
69
70
|
|
70
71
|
= Warranty
|
@@ -74,5 +75,5 @@
|
|
74
75
|
|
75
76
|
= Author
|
76
77
|
Daniel J. Berger
|
77
|
-
djberg96 at gmail dot com
|
78
|
+
djberg96 at nospam at gmail dot com
|
78
79
|
imperator on IRC (irc.freenode.net)
|
data/doc/{freebsd.txt → bsd.txt}
RENAMED
@@ -5,7 +5,7 @@
|
|
5
5
|
require "sys/cpu"
|
6
6
|
include Sys
|
7
7
|
|
8
|
-
#
|
8
|
+
# BSD and OS X
|
9
9
|
puts "Architecture: " + CPU.architecture
|
10
10
|
puts "Machine: " + CPU.machine
|
11
11
|
puts "Mhz: " + CPU.cpu_freq.to_s
|
@@ -24,6 +24,8 @@ CPU.architecture
|
|
24
24
|
CPU.freq
|
25
25
|
Returns an integer indicating the speed (i.e. frequency in Mhz) of
|
26
26
|
the cpu.
|
27
|
+
|
28
|
+
Not supported on OS X.
|
27
29
|
|
28
30
|
CPU.load_avg
|
29
31
|
Returns an array of three floats indicating the 1, 5 and 15 minute load
|
@@ -39,16 +41,16 @@ CPU.num_cpu
|
|
39
41
|
Returns an integer indicating the number of cpu's on the system.
|
40
42
|
|
41
43
|
= Error Classes
|
42
|
-
|
44
|
+
CPU::Error < StandardError
|
43
45
|
Raised is response to internal function errors, usually relating to an
|
44
46
|
invalid cpu number.
|
45
47
|
|
46
48
|
= Known Bugs
|
47
49
|
None known. Please post bug reports to the SourceForge home page at
|
48
|
-
http://www.rubyforge.org/projects/sysutils
|
50
|
+
http://www.rubyforge.org/projects/sysutils
|
49
51
|
|
50
52
|
= Copyright
|
51
|
-
(C) 2003-
|
53
|
+
(C) 2003-2007 Daniel J. Berger
|
52
54
|
All Rights Reserved
|
53
55
|
|
54
56
|
= Warranty
|
@@ -61,5 +63,5 @@ CPUError < StandardError
|
|
61
63
|
|
62
64
|
= Author
|
63
65
|
Daniel J. Berger
|
64
|
-
djberg96 at
|
65
|
-
imperator
|
66
|
+
djberg96 at nospam at gmail dot com
|
67
|
+
imperator on IRC (Freenode)
|
data/doc/hpux.txt
CHANGED
@@ -46,7 +46,7 @@ CPU.num_active_cpu
|
|
46
46
|
Returns an integer indicating the number of active cpu's on the system.
|
47
47
|
|
48
48
|
= Error Classes
|
49
|
-
|
49
|
+
CPU::Error < StandardError
|
50
50
|
Raised is response to internal function errors, usually relating to an
|
51
51
|
invalid cpu number.
|
52
52
|
|
@@ -58,7 +58,7 @@ CPUError < StandardError
|
|
58
58
|
Add cpu model and type
|
59
59
|
|
60
60
|
= Copyright
|
61
|
-
(C) 2003-
|
61
|
+
(C) 2003-2007 Daniel J. Berger
|
62
62
|
All Rights Reserved
|
63
63
|
|
64
64
|
= Warranty
|
@@ -71,5 +71,5 @@ CPUError < StandardError
|
|
71
71
|
|
72
72
|
= Author
|
73
73
|
Daniel J. Berger
|
74
|
-
djberg96 at
|
75
|
-
imperator
|
74
|
+
djberg96 at nospam at gmail dot com
|
75
|
+
imperator on IRC (Freenode)
|
data/doc/sunos.txt
CHANGED
@@ -48,7 +48,7 @@ CPU.state(cpu_num)
|
|
48
48
|
Returns a string indicating the cpu state of 'cpu_num'.
|
49
49
|
|
50
50
|
= Error Classes
|
51
|
-
|
51
|
+
CPU::Error < StandardError
|
52
52
|
Raised is response to internal function errors, usually relating to an
|
53
53
|
invalid cpu number.
|
54
54
|
|
@@ -61,7 +61,7 @@ CPUError < StandardError
|
|
61
61
|
Get the model() method to display more specific information.
|
62
62
|
|
63
63
|
= Copyright
|
64
|
-
(C) 2003-
|
64
|
+
(C) 2003-2007 Daniel J. Berger
|
65
65
|
All Rights Reserved
|
66
66
|
|
67
67
|
= Warranty
|
@@ -74,3 +74,5 @@ CPUError < StandardError
|
|
74
74
|
|
75
75
|
= Author
|
76
76
|
Daniel J. Berger
|
77
|
+
djberg96 at nospam at gmail dot com
|
78
|
+
imperator on IRC (Freenode)
|
data/doc/windows.txt
CHANGED
@@ -102,7 +102,7 @@ CPU.type(host=localhost)
|
|
102
102
|
Returns a string indicating the type of processor, e.g. GenuineIntel.
|
103
103
|
|
104
104
|
= Exception Classes
|
105
|
-
|
105
|
+
CPU::Error < StandardError
|
106
106
|
Raised is response to internal function errors, most likely to be raised
|
107
107
|
in the event that in invalid cpu number is provided for the 'freq'
|
108
108
|
method.
|
@@ -135,7 +135,7 @@ CPUError < StandardError
|
|
135
135
|
Win32_PerfFormattedData_PerfOS_Processor class.
|
136
136
|
|
137
137
|
= Copyright
|
138
|
-
(C) 2003-
|
138
|
+
(C) 2003-2007 Daniel J. Berger
|
139
139
|
All Rights Reserved
|
140
140
|
|
141
141
|
= Warranty
|
@@ -148,5 +148,5 @@ CPUError < StandardError
|
|
148
148
|
|
149
149
|
= Author
|
150
150
|
Daniel J. Berger
|
151
|
-
djberg96 at
|
151
|
+
djberg96 at nospam at gmail dot com
|
152
152
|
imperator/rubyhacker1 on IRC (Freenode)
|
data/lib/sys/cpu.rb
CHANGED
@@ -2,10 +2,10 @@ require 'win32ole'
|
|
2
2
|
require 'socket'
|
3
3
|
|
4
4
|
module Sys
|
5
|
-
class CPUError < StandardError; end
|
6
|
-
|
7
5
|
class CPU
|
8
|
-
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
VERSION = '0.6.0'
|
9
9
|
|
10
10
|
fields = %w/
|
11
11
|
address_width
|
@@ -64,7 +64,7 @@ module Sys
|
|
64
64
|
begin
|
65
65
|
wmi = WIN32OLE.connect(cs)
|
66
66
|
rescue WIN32OLERuntimeError => e
|
67
|
-
raise
|
67
|
+
raise Error, e
|
68
68
|
else
|
69
69
|
self.get_cpu_arch(wmi.Architecture)
|
70
70
|
end
|
@@ -73,14 +73,14 @@ module Sys
|
|
73
73
|
# Returns an integer indicating the speed (i.e. frequency in Mhz) of
|
74
74
|
# +cpu_num+ on +host+, or the localhost if no +host+ is specified.
|
75
75
|
# If +cpu_num+ +1 is greater than the number of cpu's on your system
|
76
|
-
# or this call fails for any other reason, a
|
76
|
+
# or this call fails for any other reason, a Error is raised.
|
77
77
|
#
|
78
78
|
def self.freq(cpu_num = 0, host = Socket.gethostname)
|
79
79
|
cs = "winmgmts://#{host}/root/cimv2:Win32_Processor='cpu#{cpu_num}'"
|
80
80
|
begin
|
81
81
|
wmi = WIN32OLE.connect(cs)
|
82
82
|
rescue WIN32OLERuntimeError => e
|
83
|
-
raise
|
83
|
+
raise Error, e
|
84
84
|
else
|
85
85
|
return wmi.CurrentClockSpeed
|
86
86
|
end
|
@@ -99,7 +99,7 @@ module Sys
|
|
99
99
|
begin
|
100
100
|
wmi = WIN32OLE.connect(cs)
|
101
101
|
rescue WIN32OLERuntimeError => e
|
102
|
-
raise
|
102
|
+
raise Error, e
|
103
103
|
else
|
104
104
|
return wmi.LoadPercentage
|
105
105
|
end
|
@@ -112,7 +112,7 @@ module Sys
|
|
112
112
|
begin
|
113
113
|
wmi = WIN32OLE.connect(cs)
|
114
114
|
rescue WIN32OLERuntimeError => e
|
115
|
-
raise
|
115
|
+
raise Error, e
|
116
116
|
else
|
117
117
|
return wmi.Name
|
118
118
|
end
|
@@ -127,7 +127,7 @@ module Sys
|
|
127
127
|
begin
|
128
128
|
wmi = WIN32OLE.connect(cs)
|
129
129
|
rescue WIN32OLERuntimeError => e
|
130
|
-
raise
|
130
|
+
raise Error, e
|
131
131
|
else
|
132
132
|
return wmi.NumberOfProcessors
|
133
133
|
end
|
@@ -187,7 +187,7 @@ module Sys
|
|
187
187
|
begin
|
188
188
|
wmi = WIN32OLE.connect("winmgmts://#{host}/root/cimv2")
|
189
189
|
rescue WIN32OLERuntimeError => e
|
190
|
-
raise
|
190
|
+
raise Error, e
|
191
191
|
else
|
192
192
|
wmi.InstancesOf("Win32_Processor").each{ |cpu|
|
193
193
|
yield CPUStruct.new(
|
@@ -247,7 +247,7 @@ module Sys
|
|
247
247
|
begin
|
248
248
|
wmi = WIN32OLE.connect(cs)
|
249
249
|
rescue WIN32OLERuntimeError => e
|
250
|
-
raise
|
250
|
+
raise Error, e
|
251
251
|
else
|
252
252
|
return wmi.Manufacturer
|
253
253
|
end
|
data/test/tc_bsd.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#############################################################
|
2
|
+
# tc_bsd.rb
|
3
|
+
#
|
4
|
+
# The test case for sys-cpu on BSD flavors, including OS X.
|
5
|
+
#############################################################
|
6
|
+
require "sys/cpu"
|
7
|
+
require "test/unit"
|
8
|
+
require "tc_version"
|
9
|
+
include Sys
|
10
|
+
|
11
|
+
class TC_BSD < Test::Unit::TestCase
|
12
|
+
def test_architecture
|
13
|
+
assert_respond_to(CPU, :architecture)
|
14
|
+
assert_nothing_raised{ CPU.architecture }
|
15
|
+
assert_kind_of(String, CPU.architecture)
|
16
|
+
assert_raises(ArgumentError){ CPU.architecture(0) }
|
17
|
+
end
|
18
|
+
|
19
|
+
unless RUBY_PLATFORM.match('darwin')
|
20
|
+
def test_cpu_freq
|
21
|
+
assert_respond_to(CPU, :freq)
|
22
|
+
assert_nothing_raised{ CPU.freq }
|
23
|
+
assert_kind_of(Integer, CPU.freq)
|
24
|
+
assert_raises(ArgumentError){ CPU.freq(0) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_load_avg
|
29
|
+
assert_respond_to(CPU, :load_avg)
|
30
|
+
assert_nothing_raised{ CPU.load_avg }
|
31
|
+
assert_kind_of(Array, CPU.load_avg)
|
32
|
+
assert_equal(3,CPU.load_avg.length)
|
33
|
+
assert_raises(ArgumentError){ CPU.load_avg(0) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_machine
|
37
|
+
assert_respond_to(CPU, :machine)
|
38
|
+
assert_nothing_raised{ CPU.machine }
|
39
|
+
assert_kind_of(String, CPU.machine)
|
40
|
+
assert_raises(ArgumentError){ CPU.machine(0) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_model
|
44
|
+
assert_respond_to(CPU, :model)
|
45
|
+
assert_nothing_raised{ CPU.model }
|
46
|
+
assert_kind_of(String, CPU.model)
|
47
|
+
assert_raises(ArgumentError){ CPU.model(0) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_num_cpu
|
51
|
+
assert_respond_to(CPU, :num_cpu)
|
52
|
+
assert_nothing_raised{ CPU.num_cpu }
|
53
|
+
assert_kind_of(Integer, CPU.num_cpu)
|
54
|
+
assert_raises(ArgumentError){ CPU.num_cpu(0) }
|
55
|
+
end
|
56
|
+
end
|
data/test/tc_cpu.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
|
2
|
+
require 'tc_version'
|
3
|
+
|
4
|
+
case RUBY_PLATFORM
|
5
|
+
when /bsd|darwin|mach|osx/i
|
6
|
+
require 'tc_bsd'
|
7
|
+
when /hpux/i
|
8
|
+
require 'tc_hpux'
|
9
|
+
when /linux/i
|
10
|
+
require 'tc_linux'
|
11
|
+
when /sunos/i
|
12
|
+
require 'tc_sunos'
|
13
|
+
when /mswin|win32|dos|mingw|cygwin/i
|
14
|
+
require 'tc_windows'
|
15
|
+
else
|
16
|
+
raise "Platform not supported"
|
17
|
+
end
|
data/test/tc_hpux.rb
CHANGED
@@ -1,26 +1,12 @@
|
|
1
|
-
|
1
|
+
#####################################################################
|
2
2
|
# tc_hpux.rb
|
3
3
|
#
|
4
|
-
# Test suite for the HP-UX platform.
|
5
|
-
#
|
6
|
-
|
7
|
-
base = File.basename(Dir.pwd)
|
8
|
-
if base == "test" || base =~ /sys-cpu/
|
9
|
-
require "ftools"
|
10
|
-
Dir.chdir ".." if base == "test"
|
11
|
-
|
12
|
-
Dir.mkdir("sys") unless File.exists?("sys")
|
13
|
-
if File.exist?("cpu.sl")
|
14
|
-
File.copy("cpu.sl","sys")
|
15
|
-
else
|
16
|
-
puts "No cpu.sl file found. Please run extconf.rb and make first"
|
17
|
-
exit
|
18
|
-
end
|
19
|
-
$LOAD_PATH.unshift Dir.pwd
|
20
|
-
end
|
21
|
-
|
4
|
+
# Test suite for the HP-UX platform. This should be run via the
|
5
|
+
# 'rake test' task.
|
6
|
+
#####################################################################
|
22
7
|
require "sys/cpu"
|
23
8
|
require "test/unit"
|
9
|
+
require "tc_version"
|
24
10
|
include Sys
|
25
11
|
|
26
12
|
class TC_HPUX < Test::Unit::TestCase
|
@@ -28,25 +14,25 @@ class TC_HPUX < Test::Unit::TestCase
|
|
28
14
|
assert_respond_to(CPU, :freq)
|
29
15
|
assert_nothing_raised{ CPU.freq }
|
30
16
|
assert_nothing_raised{ CPU.freq(0) }
|
31
|
-
assert_kind_of(Integer,CPU.freq,"Invalid Type")
|
17
|
+
assert_kind_of(Integer, CPU.freq, "Invalid Type")
|
32
18
|
end
|
33
19
|
|
34
20
|
def test_num_cpu
|
35
21
|
assert_respond_to(CPU, :num_cpu)
|
36
22
|
assert_nothing_raised{ CPU.num_cpu }
|
37
|
-
assert_kind_of(Integer,CPU.num_cpu,"Invalid Type")
|
23
|
+
assert_kind_of(Integer, CPU.num_cpu, "Invalid Type")
|
38
24
|
end
|
39
25
|
|
40
26
|
def test_num_active_cpu
|
41
27
|
assert_respond_to(CPU, :num_active_cpu)
|
42
28
|
assert_nothing_raised{ CPU.num_active_cpu }
|
43
|
-
assert_kind_of(Integer,CPU.num_active_cpu,"Invalid Type")
|
29
|
+
assert_kind_of(Integer, CPU.num_active_cpu, "Invalid Type")
|
44
30
|
end
|
45
31
|
|
46
32
|
def test_cpu_architecture
|
47
33
|
assert_respond_to(CPU, :architecture)
|
48
34
|
assert_nothing_raised{ CPU.architecture }
|
49
|
-
assert_kind_of(String,CPU.architecture,"Invalid Type")
|
35
|
+
assert_kind_of(String, CPU.architecture, "Invalid Type")
|
50
36
|
end
|
51
37
|
|
52
38
|
def test_load_avg
|
@@ -55,9 +41,9 @@ class TC_HPUX < Test::Unit::TestCase
|
|
55
41
|
assert_nothing_raised{ CPU.load_avg(0) }
|
56
42
|
assert_nothing_raised{ CPU.load_avg{ |e| } }
|
57
43
|
assert_raises(ArgumentError){ CPU.load_avg(0){ } }
|
58
|
-
assert_kind_of(Array,CPU.load_avg,"Invalid Type")
|
59
|
-
assert_kind_of(Array,CPU.load_avg(0),"Invalid Type")
|
60
|
-
assert_equal(3,CPU.load_avg.length,"Bad number of elements")
|
61
|
-
assert_equal(3,CPU.load_avg(0).length,"Bad number of elements")
|
44
|
+
assert_kind_of(Array, CPU.load_avg, "Invalid Type")
|
45
|
+
assert_kind_of(Array, CPU.load_avg(0), "Invalid Type")
|
46
|
+
assert_equal(3, CPU.load_avg.length, "Bad number of elements")
|
47
|
+
assert_equal(3, CPU.load_avg(0).length, "Bad number of elements")
|
62
48
|
end
|
63
49
|
end
|
data/test/tc_linux.rb
CHANGED
@@ -1,19 +1,12 @@
|
|
1
|
-
|
1
|
+
###########################################################
|
2
2
|
# tc_linux.rb
|
3
3
|
#
|
4
|
-
# Test Suite for sys-cpu for Linux
|
5
|
-
|
6
|
-
|
7
|
-
if base == "test" || base =~ /sys-cpu/
|
8
|
-
require "ftools"
|
9
|
-
Dir.chdir ".." if base == "test"
|
10
|
-
Dir.mkdir("sys") unless File.exists?("sys")
|
11
|
-
File.copy("lib/sys/linux.rb","sys/cpu.rb")
|
12
|
-
$LOAD_PATH.unshift Dir.pwd
|
13
|
-
end
|
14
|
-
|
4
|
+
# Test Suite for sys-cpu for Linux. This should be run via
|
5
|
+
# the 'rake test' task.
|
6
|
+
###########################################################
|
15
7
|
require "sys/cpu"
|
16
8
|
require "test/unit"
|
9
|
+
require "tc_version"
|
17
10
|
include Sys
|
18
11
|
|
19
12
|
class TC_Linux < Test::Unit::TestCase
|
data/test/tc_sunos.rb
CHANGED
@@ -1,31 +1,14 @@
|
|
1
1
|
###########################################################
|
2
2
|
# tc_sunos.rb
|
3
3
|
#
|
4
|
-
# Test suite for sys-cpu on Solaris.
|
5
|
-
#
|
4
|
+
# Test suite for sys-cpu on Solaris. This should be run
|
5
|
+
# via the 'rake test' task.
|
6
6
|
###########################################################
|
7
|
-
base = File.basename(Dir.pwd)
|
8
|
-
if base == "test" || base =~ /sys-cpu/
|
9
|
-
require "ftools"
|
10
|
-
Dir.chdir ".." if base == "test"
|
11
|
-
|
12
|
-
Dir.mkdir("sys") unless File.exist?("sys")
|
13
|
-
|
14
|
-
if File.exist?("cpu.so")
|
15
|
-
File.copy("cpu.so","sys")
|
16
|
-
else
|
17
|
-
puts "No cpu.so file found. Please run extconf.rb and make first"
|
18
|
-
exit
|
19
|
-
end
|
20
|
-
|
21
|
-
$LOAD_PATH.unshift Dir.pwd
|
22
|
-
end
|
23
|
-
|
24
7
|
require "sys/cpu"
|
25
8
|
require "test/unit"
|
9
|
+
require "tc_version"
|
26
10
|
include Sys
|
27
11
|
|
28
|
-
# I could really use a mock object here
|
29
12
|
class TC_SunOS < Test::Unit::TestCase
|
30
13
|
def test_cpu_freq
|
31
14
|
assert_respond_to(CPU, :freq)
|
@@ -35,9 +18,9 @@ class TC_SunOS < Test::Unit::TestCase
|
|
35
18
|
end
|
36
19
|
|
37
20
|
def test_cpu_type
|
38
|
-
assert_respond_to(CPU, :
|
39
|
-
assert_nothing_raised{ CPU.
|
40
|
-
assert_kind_of(String, CPU.
|
21
|
+
assert_respond_to(CPU, :cpu_type)
|
22
|
+
assert_nothing_raised{ CPU.cpu_type }
|
23
|
+
assert_kind_of(String, CPU.cpu_type)
|
41
24
|
end
|
42
25
|
|
43
26
|
def test_fpu_type
|
@@ -74,9 +57,9 @@ class TC_SunOS < Test::Unit::TestCase
|
|
74
57
|
end
|
75
58
|
|
76
59
|
def test_exceptions
|
77
|
-
assert_raises(Sys::
|
60
|
+
assert_raises(Sys::CPU::Error){ CPU.state(55) }
|
78
61
|
assert_raises(TypeError){ CPU.state("yo") }
|
79
|
-
assert_raises(Sys::
|
62
|
+
assert_raises(Sys::CPU::Error){ CPU.freq(999) }
|
80
63
|
assert_raises(TypeError){ CPU.freq("yo") }
|
81
64
|
end
|
82
65
|
end
|
data/test/tc_version.rb
CHANGED
@@ -5,40 +5,12 @@
|
|
5
5
|
# version. This reduces the pain of having separate tests
|
6
6
|
# for the VERSION constant in every single test case.
|
7
7
|
###########################################################
|
8
|
-
base = File.basename(Dir.pwd)
|
9
|
-
|
10
|
-
if base == "test" || base =~ /sys-cpu/
|
11
|
-
require "ftools"
|
12
|
-
|
13
|
-
Dir.chdir("..") if base == "test"
|
14
|
-
Dir.mkdir("sys") unless File.exist?("sys")
|
15
|
-
|
16
|
-
case RUBY_PLATFORM
|
17
|
-
when /mswin|dos|cygwin|mingw/i
|
18
|
-
file = 'lib/sys/windows.rb'
|
19
|
-
when /linux/i
|
20
|
-
file = 'lib/sys/linux.rb'
|
21
|
-
else
|
22
|
-
require "rbconfig"
|
23
|
-
file = "cpu." << Config::CONFIG["DLEXT"]
|
24
|
-
end
|
25
|
-
|
26
|
-
if File.exist?(file)
|
27
|
-
File.copy(file, "sys/cpu.rb")
|
28
|
-
else
|
29
|
-
puts "No '#{file}' file found. Please run extconf.rb and make first"
|
30
|
-
exit
|
31
|
-
end
|
32
|
-
|
33
|
-
$LOAD_PATH.unshift Dir.pwd
|
34
|
-
end
|
35
|
-
|
36
8
|
require "sys/cpu"
|
37
9
|
require "test/unit"
|
38
10
|
include Sys
|
39
11
|
|
40
12
|
class TC_Sys_CPU_VERSION < Test::Unit::TestCase
|
41
13
|
def test_version
|
42
|
-
assert_equal('0.
|
14
|
+
assert_equal('0.6.0', CPU::VERSION)
|
43
15
|
end
|
44
16
|
end
|
data/test/tc_windows.rb
CHANGED
@@ -1,19 +1,12 @@
|
|
1
1
|
######################################################################
|
2
2
|
# tc_windows.rb
|
3
3
|
#
|
4
|
-
# Test suite for
|
4
|
+
# Test suite for MS Windows systems. This should be run via the
|
5
|
+
# 'rake test' task.
|
5
6
|
######################################################################
|
6
|
-
base = File.basename(Dir.pwd)
|
7
|
-
if base == "test" || base =~ /sys-cpu/
|
8
|
-
require "ftools" if base == "test"
|
9
|
-
Dir.chdir '..'
|
10
|
-
Dir.mkdir("sys") unless File.exists?("sys")
|
11
|
-
File.copy("lib/sys/windows.rb","sys/cpu.rb")
|
12
|
-
$LOAD_PATH.unshift Dir.pwd
|
13
|
-
end
|
14
|
-
|
15
7
|
require "test/unit"
|
16
8
|
require "sys/cpu"
|
9
|
+
require "tc_version"
|
17
10
|
require "socket"
|
18
11
|
include Sys
|
19
12
|
|
@@ -26,43 +19,43 @@ class TC_Windows_CPU < Test::Unit::TestCase
|
|
26
19
|
assert_respond_to(CPU, :architecture)
|
27
20
|
assert_nothing_raised{ CPU.architecture }
|
28
21
|
assert_nothing_raised{ CPU.architecture(@host) }
|
29
|
-
assert_kind_of(String,CPU.architecture,"Invalid Type")
|
22
|
+
assert_kind_of(String, CPU.architecture, "Invalid Type")
|
30
23
|
end
|
31
24
|
|
32
25
|
def test_freq
|
33
26
|
assert_respond_to(CPU, :freq)
|
34
27
|
assert_nothing_raised{ CPU.freq }
|
35
28
|
assert_nothing_raised{ CPU.freq(0) }
|
36
|
-
assert_nothing_raised{ CPU.freq(0
|
37
|
-
assert_kind_of(Integer,CPU.freq,"Invalid Type")
|
29
|
+
assert_nothing_raised{ CPU.freq(0, @host) }
|
30
|
+
assert_kind_of(Integer, CPU.freq, "Invalid Type")
|
38
31
|
end
|
39
32
|
|
40
33
|
def test_model
|
41
34
|
assert_respond_to(CPU, :model)
|
42
35
|
assert_nothing_raised{ CPU.model }
|
43
36
|
assert_nothing_raised{ CPU.model(@host) }
|
44
|
-
assert_kind_of(String,CPU.model,"Invalid Type")
|
37
|
+
assert_kind_of(String, CPU.model, "Invalid Type")
|
45
38
|
end
|
46
39
|
|
47
40
|
def test_num_cpu
|
48
41
|
assert_respond_to(CPU, :num_cpu)
|
49
42
|
assert_nothing_raised{ CPU.num_cpu }
|
50
43
|
assert_nothing_raised{ CPU.num_cpu(@host) }
|
51
|
-
assert_kind_of(Integer,CPU.num_cpu,"Invalid Type")
|
44
|
+
assert_kind_of(Integer, CPU.num_cpu, "Invalid Type")
|
52
45
|
end
|
53
46
|
|
54
47
|
def test_type
|
55
48
|
assert_respond_to(CPU, :type)
|
56
49
|
assert_nothing_raised{ CPU.type }
|
57
50
|
assert_nothing_raised{ CPU.type(@host) }
|
58
|
-
assert_kind_of(String,CPU.type,"Invalid Type")
|
51
|
+
assert_kind_of(String, CPU.type, "Invalid Type")
|
59
52
|
end
|
60
53
|
|
61
54
|
def test_load_avg
|
62
55
|
assert_respond_to(CPU, :load_avg)
|
63
56
|
assert_nothing_raised{ CPU.load_avg }
|
64
|
-
assert_nothing_raised{ CPU.load_avg(0
|
65
|
-
assert_kind_of(Integer,CPU.load_avg,"Invalid Type")
|
57
|
+
assert_nothing_raised{ CPU.load_avg(0, @host) }
|
58
|
+
assert_kind_of(Integer, CPU.load_avg, "Invalid Type")
|
66
59
|
end
|
67
60
|
|
68
61
|
def test_processors
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.2
|
3
3
|
specification_version: 1
|
4
4
|
name: sys-cpu
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date:
|
6
|
+
version: 0.6.0
|
7
|
+
date: 2007-04-26 00:00:00 -06:00
|
8
8
|
summary: A Ruby interface for providing CPU information
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
|
-
email: djberg96
|
11
|
+
email: djberg96 at nospam at gmail dot com
|
12
12
|
homepage: http://www.rubyforge.org/projects/sysutils
|
13
13
|
rubyforge_project: sysutils
|
14
14
|
description: A Ruby interface for providing CPU information
|
@@ -29,28 +29,31 @@ post_install_message:
|
|
29
29
|
authors:
|
30
30
|
- Daniel J. Berger
|
31
31
|
files:
|
32
|
-
- doc/
|
32
|
+
- doc/bsd.txt
|
33
33
|
- doc/hpux.txt
|
34
34
|
- doc/linux.txt
|
35
35
|
- doc/sunos.txt
|
36
36
|
- doc/windows.txt
|
37
|
-
- test/
|
37
|
+
- test/tc_bsd.rb
|
38
|
+
- test/tc_cpu.rb
|
38
39
|
- test/tc_hpux.rb
|
39
40
|
- test/tc_linux.rb
|
40
41
|
- test/tc_sunos.rb
|
41
42
|
- test/tc_version.rb
|
42
43
|
- test/tc_windows.rb
|
43
|
-
- test/ts_all.rb
|
44
44
|
- CHANGES
|
45
45
|
- README
|
46
|
+
- MANIFEST
|
46
47
|
- lib/sys/cpu.rb
|
47
48
|
test_files:
|
48
|
-
- test/
|
49
|
+
- test/tc_windows.rb
|
49
50
|
rdoc_options: []
|
50
51
|
|
51
52
|
extra_rdoc_files:
|
52
53
|
- CHANGES
|
53
54
|
- README
|
55
|
+
- MANIFEST
|
56
|
+
- lib/sys/cpu.rb
|
54
57
|
executables: []
|
55
58
|
|
56
59
|
extensions: []
|
data/test/tc_freebsd.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
###########################################################
|
2
|
-
# tc_freebsd.rb
|
3
|
-
#
|
4
|
-
# Test suite for sys-cpu on FreeBSD. This should only be
|
5
|
-
# run *after* the make process.
|
6
|
-
###########################################################
|
7
|
-
base = File.basename(Dir.pwd)
|
8
|
-
if base == "test" || base =~ /sys-cpu/
|
9
|
-
require "ftools"
|
10
|
-
Dir.chdir ".." if base == "test"
|
11
|
-
|
12
|
-
Dir.mkdir("sys") unless File.exist?("sys")
|
13
|
-
|
14
|
-
if File.exist?("cpu.so")
|
15
|
-
File.copy("cpu.so","sys")
|
16
|
-
else
|
17
|
-
puts "No cpu.so file found. Please run extconf.rb and make first"
|
18
|
-
exit
|
19
|
-
end
|
20
|
-
|
21
|
-
$LOAD_PATH.unshift Dir.pwd
|
22
|
-
end
|
23
|
-
|
24
|
-
require "sys/cpu"
|
25
|
-
require "test/unit"
|
26
|
-
include Sys
|
27
|
-
|
28
|
-
class TC_FreeBSD < Test::Unit::TestCase
|
29
|
-
def test_architecture
|
30
|
-
assert_respond_to(CPU, :architecture)
|
31
|
-
assert_nothing_raised{ CPU.architecture }
|
32
|
-
assert_kind_of(String,CPU.architecture)
|
33
|
-
assert_raises(ArgumentError){ CPU.architecture(0) }
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_cpu_freq
|
37
|
-
assert_respond_to(CPU, :freq)
|
38
|
-
assert_nothing_raised{ CPU.freq }
|
39
|
-
assert_kind_of(Integer,CPU.freq)
|
40
|
-
assert_raises(ArgumentError){ CPU.freq(0) }
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_load_avg
|
44
|
-
assert_respond_to(CPU, :load_avg)
|
45
|
-
assert_nothing_raised{ CPU.load_avg }
|
46
|
-
assert_kind_of(Array,CPU.load_avg)
|
47
|
-
assert_equal(3,CPU.load_avg.length)
|
48
|
-
assert_raises(ArgumentError){ CPU.load_avg(0) }
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_machine
|
52
|
-
assert_respond_to(CPU, :machine)
|
53
|
-
assert_nothing_raised{ CPU.machine }
|
54
|
-
assert_kind_of(String,CPU.machine)
|
55
|
-
assert_raises(ArgumentError){ CPU.machine(0) }
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_model
|
59
|
-
assert_respond_to(CPU, :model)
|
60
|
-
assert_nothing_raised{ CPU.model }
|
61
|
-
assert_kind_of(String,CPU.model)
|
62
|
-
assert_raises(ArgumentError){ CPU.model(0) }
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_num_cpu
|
66
|
-
assert_respond_to(CPU, :num_cpu)
|
67
|
-
assert_nothing_raised{ CPU.num_cpu }
|
68
|
-
assert_kind_of(Integer,CPU.num_cpu)
|
69
|
-
assert_raises(ArgumentError){ CPU.num_cpu(0) }
|
70
|
-
end
|
71
|
-
end
|
data/test/ts_all.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift Dir.pwd
|
2
|
-
$LOAD_PATH.unshift Dir.pwd + '/test'
|
3
|
-
|
4
|
-
require 'tc_version'
|
5
|
-
|
6
|
-
case RUBY_PLATFORM
|
7
|
-
when /sunos|solaris/i
|
8
|
-
require 'tc_sunos'
|
9
|
-
when /linux/i
|
10
|
-
require 'tc_linux'
|
11
|
-
when /mswin|cygwin|mingw/i
|
12
|
-
require 'tc_windows'
|
13
|
-
when /hpux/i
|
14
|
-
require 'tc_hpux'
|
15
|
-
when /bsd/i
|
16
|
-
require 'tc_freebsd'
|
17
|
-
end
|