cpuinfo 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ require_relative 'sys/cpu'
@@ -0,0 +1,97 @@
1
+ #############################################################
2
+ # test_sys_cpu_bsd.rb
3
+ #
4
+ # The test case for sys-cpu on BSD flavors, including OS X.
5
+ #############################################################
6
+ require 'sys/cpu'
7
+ require 'rbconfig'
8
+ require 'test-unit'
9
+ require 'test_sys_cpu_version'
10
+ include Sys
11
+
12
+ class TC_Sys_CPU_BSD < Test::Unit::TestCase
13
+ test "architecture method basic functionality" do
14
+ assert_respond_to(CPU, :architecture)
15
+ assert_nothing_raised{ CPU.architecture }
16
+ end
17
+
18
+ test "architecture method returns a sane value" do
19
+ assert_kind_of(String, CPU.architecture)
20
+ assert_true(CPU.architecture.size > 0)
21
+ end
22
+
23
+ test "architecture method does not accept any arguments" do
24
+ assert_raises(ArgumentError){ CPU.architecture(0) }
25
+ end
26
+
27
+ test "freq method basic functionality" do
28
+ assert_respond_to(CPU, :freq)
29
+ assert_nothing_raised{ CPU.freq }
30
+ end
31
+
32
+ test "freq method returns expected value" do
33
+ assert_kind_of(Integer, CPU.freq)
34
+ assert_true(CPU.freq > 0)
35
+ end
36
+
37
+ test "freq method does not accept any arguments" do
38
+ assert_raises(ArgumentError){ CPU.freq(0) }
39
+ end
40
+
41
+ test "load_avg method basic functionality" do
42
+ assert_respond_to(CPU, :load_avg)
43
+ assert_nothing_raised{ CPU.load_avg }
44
+ end
45
+
46
+ test "load_avg returns the expected results" do
47
+ assert_kind_of(Array, CPU.load_avg)
48
+ assert_equal(3, CPU.load_avg.length)
49
+ assert_kind_of(Float, CPU.load_avg[0])
50
+ end
51
+
52
+ test "load_avg does not accept any arguments" do
53
+ assert_raises(ArgumentError){ CPU.load_avg(0) }
54
+ end
55
+
56
+ test "machine method basic functionality" do
57
+ assert_respond_to(CPU, :machine)
58
+ assert_nothing_raised{ CPU.machine }
59
+ end
60
+
61
+ test "machine method returns sane value" do
62
+ assert_kind_of(String, CPU.machine)
63
+ assert_true(CPU.machine.size > 0)
64
+ end
65
+
66
+ test "machine method does not accept any arguments" do
67
+ assert_raises(ArgumentError){ CPU.machine(0) }
68
+ end
69
+
70
+ test "model method basic functionality" do
71
+ assert_respond_to(CPU, :model)
72
+ assert_nothing_raised{ CPU.model }
73
+ end
74
+
75
+ test "model method returns sane value" do
76
+ assert_kind_of(String, CPU.model)
77
+ assert_true(CPU.model.length > 0)
78
+ end
79
+
80
+ test "model method does not accept any arguments" do
81
+ assert_raises(ArgumentError){ CPU.model(0) }
82
+ end
83
+
84
+ test "num_cpu method basic functionality" do
85
+ assert_respond_to(CPU, :num_cpu)
86
+ assert_nothing_raised{ CPU.num_cpu }
87
+ end
88
+
89
+ test "num_cpu method returns expected value" do
90
+ assert_kind_of(Integer, CPU.num_cpu)
91
+ assert_true(CPU.num_cpu > 0)
92
+ end
93
+
94
+ test "num_cpu method does not accept any arguments" do
95
+ assert_raises(ArgumentError){ CPU.num_cpu(0) }
96
+ end
97
+ end
@@ -0,0 +1,49 @@
1
+ #####################################################################
2
+ # test_sys_cpu_hpux.rb
3
+ #
4
+ # Test suite for the HP-UX platform. This should be run via the
5
+ # 'rake test' task.
6
+ #####################################################################
7
+ require 'sys/cpu'
8
+ require 'test-unit'
9
+ require 'test_sys_cpu_version'
10
+ include Sys
11
+
12
+ class TC_Sys_CPU_HPUX < Test::Unit::TestCase
13
+ def test_cpu_freq
14
+ assert_respond_to(CPU, :freq)
15
+ assert_nothing_raised{ CPU.freq }
16
+ assert_nothing_raised{ CPU.freq(0) }
17
+ assert_kind_of(Integer, CPU.freq, 'Invalid Type')
18
+ end
19
+
20
+ def test_num_cpu
21
+ assert_respond_to(CPU, :num_cpu)
22
+ assert_nothing_raised{ CPU.num_cpu }
23
+ assert_kind_of(Integer, CPU.num_cpu, 'Invalid Type')
24
+ end
25
+
26
+ def test_num_active_cpu
27
+ assert_respond_to(CPU, :num_active_cpu)
28
+ assert_nothing_raised{ CPU.num_active_cpu }
29
+ assert_kind_of(Integer, CPU.num_active_cpu, 'Invalid Type')
30
+ end
31
+
32
+ def test_cpu_architecture
33
+ assert_respond_to(CPU, :architecture)
34
+ assert_nothing_raised{ CPU.architecture }
35
+ assert_kind_of(String, CPU.architecture, 'Invalid Type')
36
+ end
37
+
38
+ def test_load_avg
39
+ assert_respond_to(CPU, :load_avg)
40
+ assert_nothing_raised{ CPU.load_avg }
41
+ assert_nothing_raised{ CPU.load_avg(0) }
42
+ assert_nothing_raised{ CPU.load_avg{ |e| } }
43
+ assert_raises(ArgumentError){ CPU.load_avg(0){ } }
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')
48
+ end
49
+ end
@@ -0,0 +1,31 @@
1
+ ###########################################################
2
+ # test_sys_cpu_linux.rb
3
+ #
4
+ # Test Suite for sys-cpu for Linux. This should be run via
5
+ # the 'rake test' task.
6
+ ###########################################################
7
+ require 'sys/cpu'
8
+ require 'test-unit'
9
+ require 'test_sys_cpu_version'
10
+ include Sys
11
+
12
+ class TC_Sys_CPU_Linux < Test::Unit::TestCase
13
+ def test_all_dynamic_methods
14
+ assert_nothing_raised{
15
+ CPU.processors{ |cs|
16
+ cs.members.each{ |m| cs[m].to_s }
17
+ }
18
+ }
19
+ end
20
+
21
+ def test_load_avg
22
+ assert_nothing_raised{ CPU.load_avg }
23
+ assert_equal(3, CPU.load_avg.length)
24
+ end
25
+
26
+ def test_cpu_stats
27
+ assert_nothing_raised{ CPU.cpu_stats }
28
+ assert_kind_of(Hash, CPU.cpu_stats)
29
+ assert_equal(true, CPU.cpu_stats['cpu0'].length >= 4)
30
+ end
31
+ end
@@ -0,0 +1,81 @@
1
+ ###########################################################
2
+ # test_sys_cpu_sunos.rb
3
+ #
4
+ # Test suite for sys-cpu on Solaris. This should be run
5
+ # via the 'rake test' task.
6
+ ###########################################################
7
+ require 'sys/cpu'
8
+ require 'test-unit'
9
+ include Sys
10
+
11
+ class TC_Sys_CPU_SunOS < Test::Unit::TestCase
12
+ test "freq method basic functionality" do
13
+ assert_respond_to(CPU, :freq)
14
+ assert_nothing_raised{ CPU.freq }
15
+ end
16
+
17
+ test "freq method does not accept any arguments" do
18
+ assert_raise(ArgumentError){ CPU.freq(0) }
19
+ end
20
+
21
+ test "freq method returns a sane value" do
22
+ assert_kind_of(Integer, CPU.freq)
23
+ assert_true(CPU.freq > 100)
24
+ end
25
+
26
+ test "fpu_type basic functionality" do
27
+ assert_respond_to(CPU, :fpu_type)
28
+ assert_nothing_raised{ CPU.fpu_type }
29
+ end
30
+
31
+ test "fpu_type returns a sane value" do
32
+ assert_kind_of(String, CPU.fpu_type)
33
+ assert_false(CPU.fpu_type.empty?)
34
+ end
35
+
36
+ test "load_avg basic functionality" do
37
+ assert_respond_to(CPU, :load_avg)
38
+ assert_nothing_raised{ CPU.load_avg }
39
+ end
40
+
41
+ test "load_avg method returns the expected values" do
42
+ assert_kind_of(Array, CPU.load_avg)
43
+ assert_equal(3, CPU.load_avg.length)
44
+ assert_kind_of(Float, CPU.load_avg.first)
45
+ end
46
+
47
+ test "model method basic functionality" do
48
+ assert_respond_to(CPU, :model)
49
+ assert_nothing_raised{ CPU.model }
50
+ end
51
+
52
+ test "model method returns a sane value" do
53
+ assert_kind_of(String, CPU.model)
54
+ assert_false(CPU.model.empty?)
55
+ end
56
+
57
+ test "num_cpu method basic functionalty" do
58
+ assert_respond_to(CPU, :num_cpu)
59
+ assert_nothing_raised{ CPU.num_cpu }
60
+ end
61
+
62
+ test "num_cpu method returns a sane value" do
63
+ assert_kind_of(Integer, CPU.num_cpu)
64
+ assert_true(CPU.num_cpu > 0)
65
+ end
66
+
67
+ test "state basic functionality" do
68
+ assert_respond_to(CPU, :state)
69
+ assert_nothing_raised{ CPU.state }
70
+ end
71
+
72
+ test "state method accepts one optional argument" do
73
+ assert_nothing_raised{ CPU.state(0) }
74
+ assert_raise(ArgumentError){ CPU.state(0,0) }
75
+ end
76
+
77
+ test "state method returns a sane value" do
78
+ assert_kind_of(String, CPU.state(0))
79
+ assert_false(CPU.state.empty?)
80
+ end
81
+ end
@@ -0,0 +1,15 @@
1
+ #######################################################################
2
+ # test_sys_cpu_version.rb
3
+ #
4
+ # The sole purpose of this test case is to verify the version number.
5
+ # This reduces the pain of having separate tests for the VERSION
6
+ # constant in every single test case.
7
+ #######################################################################
8
+ require 'sys/cpu'
9
+ require 'test-unit'
10
+
11
+ class TC_Sys_CPU_VERSION < Test::Unit::TestCase
12
+ test "version number is set to the expected value" do
13
+ assert_equal('0.7.2', Sys::CPU::VERSION)
14
+ end
15
+ end
@@ -0,0 +1,72 @@
1
+ ######################################################################
2
+ # test_sys_cpu_windows.rb
3
+ #
4
+ # Test suite for MS Windows systems. This should be run via the
5
+ # 'rake test' task.
6
+ ######################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'test/unit'
11
+ require 'sys/cpu'
12
+ require 'test_sys_cpu_version'
13
+ require 'socket'
14
+ include Sys
15
+
16
+ class TC_Sys_CPU_Windows < Test::Unit::TestCase
17
+ def self.startup
18
+ @@host = Socket.gethostname
19
+ end
20
+
21
+ def test_architecture
22
+ assert_respond_to(CPU, :architecture)
23
+ assert_nothing_raised{ CPU.architecture }
24
+ assert_nothing_raised{ CPU.architecture(@@host) }
25
+ assert_kind_of(String, CPU.architecture, 'Invalid Type')
26
+ end
27
+
28
+ def test_freq
29
+ assert_respond_to(CPU, :freq)
30
+ assert_nothing_raised{ CPU.freq }
31
+ assert_nothing_raised{ CPU.freq(0) }
32
+ assert_nothing_raised{ CPU.freq(0, @@host) }
33
+ assert_kind_of(Integer, CPU.freq, 'Invalid Type')
34
+ end
35
+
36
+ def test_model
37
+ assert_respond_to(CPU, :model)
38
+ assert_nothing_raised{ CPU.model }
39
+ assert_nothing_raised{ CPU.model(@@host) }
40
+ assert_kind_of(String, CPU.model, 'Invalid Type')
41
+ end
42
+
43
+ def test_num_cpu
44
+ assert_respond_to(CPU, :num_cpu)
45
+ assert_nothing_raised{ CPU.num_cpu }
46
+ assert_nothing_raised{ CPU.num_cpu(@@host) }
47
+ assert_kind_of(Integer, CPU.num_cpu, 'Invalid Type')
48
+ end
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
+ end
56
+
57
+ def test_load_avg
58
+ assert_respond_to(CPU, :load_avg)
59
+ assert_nothing_raised{ CPU.load_avg }
60
+ assert_nothing_raised{ CPU.load_avg(0, @@host) }
61
+ assert_kind_of(Integer, CPU.load_avg, 'Invalid Type')
62
+ end
63
+
64
+ def test_processors
65
+ assert_respond_to(CPU, :processors)
66
+ assert_nothing_raised{ CPU.processors{} }
67
+ end
68
+
69
+ def self.shutdown
70
+ @@host = nil
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cpuinfo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthias Winkelmann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.3'
41
+ description: " Very basic parsing of /proc/cpuinfo for now.\n"
42
+ email: m@matthi.coffee
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - cpuinfo/LICENSE
48
+ - cpuinfo/README.md
49
+ - cpuinfo/Rakefile
50
+ - cpuinfo/cpuinfo.gemspec
51
+ - cpuinfo/lib/cpuinfo.rb
52
+ - cpuinfo/test/fixtures/cpuinfo
53
+ - cpuinfo/test/test.rb
54
+ - lib/cp/cpu.rb
55
+ - lib/cp/unix/sys/cpu.rb
56
+ - lib/cp/windows/sys/cpu.rb
57
+ - lib/sys-cpu.rb
58
+ - test/test_sys_cpu_bsd.rb
59
+ - test/test_sys_cpu_hpux.rb
60
+ - test/test_sys_cpu_linux.rb
61
+ - test/test_sys_cpu_sunos.rb
62
+ - test/test_sys_cpu_version.rb
63
+ - test/test_sys_cpu_windows.rb
64
+ homepage: https://github.com/MatthiasWinkelmann/cpuinfo
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.7.6
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: A Ruby interface to system CPU info
88
+ test_files: []