sys-cpu 0.5.5 → 0.6.0
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/ext/bsd/bsd.c +252 -0
- data/ext/extconf.rb +24 -0
- data/ext/hpux/hpux.c +219 -0
- data/{lib/sys → ext/sunos}/sunos.c +20 -17
- data/{lib → ext}/version.h +1 -1
- 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 +20 -12
- data/extconf.rb +0 -36
- data/test/tc_freebsd.rb +0 -71
- data/test/ts_all.rb +0 -17
data/ext/hpux/hpux.c
ADDED
@@ -0,0 +1,219 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
* hpux.c (cpu.c) - sys-cpu extension for HP-UX
|
3
|
+
*
|
4
|
+
* Author: Daniel J. Berger
|
5
|
+
*
|
6
|
+
* Interface to provide various types of cpu information.
|
7
|
+
* Based on the Unix::Processors Perl module (Wilson Snyder) with ideas from
|
8
|
+
* Sys::CPU (Matt Sanford) and Solaris::Kstat (Alan Burlison) as well.
|
9
|
+
*****************************************************************************/
|
10
|
+
#include <ruby.h>
|
11
|
+
#include "version.h"
|
12
|
+
#include <unistd.h>
|
13
|
+
#include <sys/pstat.h>
|
14
|
+
|
15
|
+
#ifndef PST_MAX_PROCS
|
16
|
+
#define PST_MAX_PROCS 32
|
17
|
+
#endif
|
18
|
+
|
19
|
+
#ifdef __cplusplus
|
20
|
+
extern "C"
|
21
|
+
{
|
22
|
+
#endif
|
23
|
+
|
24
|
+
VALUE cCPUError;
|
25
|
+
|
26
|
+
/*
|
27
|
+
* call-seq:
|
28
|
+
* CPU.load_avg
|
29
|
+
* CPU.load_avg(cpu_num)
|
30
|
+
* CPU.load_avg{ block }
|
31
|
+
*
|
32
|
+
* In non-block form returns an array of three floats indicating the 1, 5
|
33
|
+
* and 15 minute overall load average.
|
34
|
+
*
|
35
|
+
* In block form, it returns an array of three floats indicating the 1, 5
|
36
|
+
* and 15 minute load average for each cpu. Only useful on multi-cpu
|
37
|
+
* systems.
|
38
|
+
*
|
39
|
+
* If 'cpu_num' is provided, returns the load average (as a 3-element
|
40
|
+
* array) for that cpu only.
|
41
|
+
*
|
42
|
+
* You cannot provide +cpu_num+ and use block form at the same time.
|
43
|
+
*/
|
44
|
+
static VALUE cpu_load_avg(int argc, VALUE *argv)
|
45
|
+
{
|
46
|
+
struct pst_processor psp[PST_MAX_PROCS];
|
47
|
+
struct pst_dynamic psd;
|
48
|
+
int i, num_cpu;
|
49
|
+
VALUE ncpu = Qnil;
|
50
|
+
VALUE la_ary = rb_ary_new();
|
51
|
+
|
52
|
+
rb_scan_args(argc,argv,"01",&ncpu);
|
53
|
+
|
54
|
+
if( (ncpu != Qnil) && (rb_block_given_p()) )
|
55
|
+
{
|
56
|
+
rb_raise(rb_eArgError,"Can't use block form when CPU number is provided");
|
57
|
+
}
|
58
|
+
|
59
|
+
if( (ncpu != Qnil) || ((ncpu == Qnil) && (rb_block_given_p())) )
|
60
|
+
{
|
61
|
+
num_cpu = pstat_getprocessor(psp,sizeof(struct pst_processor),PST_MAX_PROCS,0);
|
62
|
+
if(num_cpu < 0)
|
63
|
+
{
|
64
|
+
rb_raise(cCPUError,"Call to pstat_getprocessor() failed.");
|
65
|
+
}
|
66
|
+
else
|
67
|
+
{
|
68
|
+
for(i = 0; i < num_cpu; i++)
|
69
|
+
{
|
70
|
+
if( (ncpu != Qnil) && (NUM2INT(ncpu)) != i){ continue; }
|
71
|
+
|
72
|
+
rb_ary_push(la_ary,rb_float_new(psp[i].psp_avg_1_min));
|
73
|
+
rb_ary_push(la_ary,rb_float_new(psp[i].psp_avg_5_min));
|
74
|
+
rb_ary_push(la_ary,rb_float_new(psp[i].psp_avg_15_min));
|
75
|
+
if(rb_block_given_p())
|
76
|
+
{
|
77
|
+
rb_yield(la_ary);
|
78
|
+
}
|
79
|
+
else
|
80
|
+
{
|
81
|
+
return la_ary;
|
82
|
+
}
|
83
|
+
rb_ary_clear(la_ary);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
else
|
88
|
+
{
|
89
|
+
if(pstat_getdynamic(&psd,sizeof(psd), (size_t)1, 0) == -1)
|
90
|
+
{
|
91
|
+
rb_raise(cCPUError,"Call to pstat_getdynamic() failed.");
|
92
|
+
}
|
93
|
+
else
|
94
|
+
{
|
95
|
+
rb_ary_push(la_ary,rb_float_new(psd.psd_avg_1_min));
|
96
|
+
rb_ary_push(la_ary,rb_float_new(psd.psd_avg_5_min));
|
97
|
+
rb_ary_push(la_ary,rb_float_new(psd.psd_avg_15_min));
|
98
|
+
return la_ary;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
return Qnil;
|
103
|
+
}
|
104
|
+
|
105
|
+
/*
|
106
|
+
* call-seq:
|
107
|
+
* CPU.num_cpu
|
108
|
+
*
|
109
|
+
* Returns the number of CPU's on the system.
|
110
|
+
*/
|
111
|
+
static VALUE cpu_num()
|
112
|
+
{
|
113
|
+
struct pst_dynamic dyn;
|
114
|
+
pstat_getdynamic(&dyn, sizeof(dyn), 0, 0);
|
115
|
+
return INT2NUM(dyn.psd_max_proc_cnt);
|
116
|
+
}
|
117
|
+
|
118
|
+
/* call-seq:
|
119
|
+
* CPU.num_active_cpu
|
120
|
+
*
|
121
|
+
* Returns the number of active CPU's on the system.
|
122
|
+
*/
|
123
|
+
static VALUE cpu_num_active()
|
124
|
+
{
|
125
|
+
struct pst_dynamic dyn;
|
126
|
+
pstat_getdynamic(&dyn, sizeof(dyn), 0, 0);
|
127
|
+
return INT2NUM(dyn.psd_proc_cnt);
|
128
|
+
}
|
129
|
+
|
130
|
+
/*
|
131
|
+
* call-seq:
|
132
|
+
* CPU.architecture
|
133
|
+
*
|
134
|
+
* Returns the cpu architecture, e.g. PA RISC 1.2, etc, or nil if it
|
135
|
+
* cannot be determined.
|
136
|
+
*/
|
137
|
+
static VALUE cpu_architecture()
|
138
|
+
{
|
139
|
+
long cpu_ver = sysconf(_SC_CPU_VERSION);
|
140
|
+
|
141
|
+
if(cpu_ver == CPU_HP_MC68020){ return rb_str_new2("Motorola MC68020"); }
|
142
|
+
if(cpu_ver == CPU_HP_MC68030){ return rb_str_new2("Motorola MC68030"); }
|
143
|
+
if(cpu_ver == CPU_HP_MC68040){ return rb_str_new2("Motorola MC68040"); }
|
144
|
+
if(cpu_ver == CPU_PA_RISC1_0){ return rb_str_new2("HP PA-RISC 1.0"); }
|
145
|
+
if(cpu_ver == CPU_PA_RISC1_1){ return rb_str_new2("HP PA-RISC 1.1"); }
|
146
|
+
if(cpu_ver == CPU_PA_RISC1_2){ return rb_str_new2("HP PA-RISC 1.2"); }
|
147
|
+
if(cpu_ver == CPU_PA_RISC2_0){ return rb_str_new2("HP PA-RISC 2.0"); }
|
148
|
+
|
149
|
+
return Qnil;
|
150
|
+
}
|
151
|
+
|
152
|
+
/*
|
153
|
+
* call-seq:
|
154
|
+
* CPU.freq(cpu_num=0)
|
155
|
+
*
|
156
|
+
* Returns an integer indicating the speed (i.e. frequency in Mhz) of
|
157
|
+
* +cpu_num+, or CPU 0 if no +cpu_num+ is specified.
|
158
|
+
*/
|
159
|
+
static VALUE cpu_freq(int argc, VALUE *argv)
|
160
|
+
{
|
161
|
+
int cpu_num = 0; /* default value */
|
162
|
+
struct pst_processor psp;
|
163
|
+
unsigned long int clock_speed, scclktick;
|
164
|
+
VALUE ncpu = Qnil;
|
165
|
+
|
166
|
+
rb_scan_args(argc, argv, "01", &ncpu);
|
167
|
+
|
168
|
+
if(ncpu != Qnil)
|
169
|
+
{
|
170
|
+
Check_Type(ncpu,T_FIXNUM);
|
171
|
+
cpu_num = NUM2INT(ncpu);
|
172
|
+
}
|
173
|
+
|
174
|
+
if((pstat_getprocessor(&psp,sizeof(psp),(size_t)1,cpu_num)) == -1)
|
175
|
+
rb_raise(cCPUError, "Invalid CPU number?");
|
176
|
+
|
177
|
+
scclktick=sysconf(_SC_CLK_TCK);
|
178
|
+
clock_speed = (psp.psp_iticksperclktick * scclktick) / 1000000;
|
179
|
+
|
180
|
+
/************************************************************************/
|
181
|
+
/* It appears that pstat_getprocessor does not return a failure code */
|
182
|
+
/* for an invalid processor number. So, we'll assume that if the clock */
|
183
|
+
/* speed is 0 that an invalid number was provided. */
|
184
|
+
/************************************************************************/
|
185
|
+
if(clock_speed <= 0)
|
186
|
+
rb_raise(cCPUError, "Invalid CPU number?");
|
187
|
+
|
188
|
+
return UINT2NUM(clock_speed);
|
189
|
+
}
|
190
|
+
|
191
|
+
void Init_cpu()
|
192
|
+
{
|
193
|
+
VALUE mSys, cCPU;
|
194
|
+
|
195
|
+
/* The Sys module serves as a toplevel namespace only */
|
196
|
+
mSys = rb_define_module("Sys");
|
197
|
+
|
198
|
+
/* The CPU class provides class methods for obtaining CPU information */
|
199
|
+
cCPU = rb_define_class_under(mSys, "CPU", rb_cObject);
|
200
|
+
|
201
|
+
/* The CPU::Error Exception class is raised whenever any of the CPU class
|
202
|
+
* methods fail.
|
203
|
+
*/
|
204
|
+
cCPUError = rb_define_class_under(cCPU, "Error", rb_eStandardError);
|
205
|
+
|
206
|
+
/* 0.6.0: The version of this package, returned as a String */
|
207
|
+
rb_define_const(cCPU, "VERSION", rb_str_new2(SYS_CPU_VERSION));
|
208
|
+
|
209
|
+
/* Class Methods */
|
210
|
+
rb_define_singleton_method(cCPU, "freq", cpu_freq, -1);
|
211
|
+
rb_define_singleton_method(cCPU, "num_cpu", cpu_num, 0);
|
212
|
+
rb_define_singleton_method(cCPU, "num_active_cpu", cpu_num_active, 0);
|
213
|
+
rb_define_singleton_method(cCPU, "load_avg", cpu_load_avg, -1);
|
214
|
+
rb_define_singleton_method(cCPU, "architecture", cpu_architecture, 0);
|
215
|
+
}
|
216
|
+
|
217
|
+
#ifdef __cplusplus
|
218
|
+
}
|
219
|
+
#endif
|
@@ -8,8 +8,8 @@
|
|
8
8
|
* The kstat code for load_avg() was taken largely from a post by Casper Dik
|
9
9
|
* on comp.unix.solaris.
|
10
10
|
*****************************************************************************/
|
11
|
-
#include
|
12
|
-
#include "
|
11
|
+
#include <ruby.h>
|
12
|
+
#include "version.h"
|
13
13
|
#include <unistd.h>
|
14
14
|
#include <sys/types.h>
|
15
15
|
#include <sys/processor.h>
|
@@ -38,8 +38,8 @@ VALUE cCPUError;
|
|
38
38
|
* CPU.freq(cpu_num=0)
|
39
39
|
*
|
40
40
|
* Returns an integer indicating the speed (i.e. frequency in Mhz) of
|
41
|
-
* +cpu_num+, or
|
42
|
-
* invalid
|
41
|
+
* +cpu_num+, or cpu 0 (zero) if no number is provided. If you provide an
|
42
|
+
* invalid cpu number then a CPUError is raised.
|
43
43
|
*/
|
44
44
|
static VALUE cpu_freq(int argc, VALUE *argv)
|
45
45
|
{
|
@@ -74,7 +74,7 @@ static VALUE cpu_freq(int argc, VALUE *argv)
|
|
74
74
|
* call-seq:
|
75
75
|
* CPU.state(cpu_num=0)
|
76
76
|
*
|
77
|
-
* Returns a string indicating the cpu state of +cpu_num+, or
|
77
|
+
* Returns a string indicating the cpu state of +cpu_num+, or cpu 0 if no
|
78
78
|
* number is specified. Raises a CPUError if an invalid +cpu_num+ is provided.
|
79
79
|
*/
|
80
80
|
static VALUE cpu_state(int argc, VALUE *argv)
|
@@ -116,7 +116,7 @@ static VALUE cpu_state(int argc, VALUE *argv)
|
|
116
116
|
* call-seq:
|
117
117
|
* CPU.num_cpu
|
118
118
|
*
|
119
|
-
* Returns the number of
|
119
|
+
* Returns the number of cpu's on your system.
|
120
120
|
*/
|
121
121
|
static VALUE cpu_num()
|
122
122
|
{
|
@@ -127,7 +127,7 @@ static VALUE cpu_num()
|
|
127
127
|
|
128
128
|
/*
|
129
129
|
* call-seq:
|
130
|
-
* CPU.
|
130
|
+
* CPU.cpu_type
|
131
131
|
*
|
132
132
|
* Returns a string indicating the type of processor. This is the
|
133
133
|
* architecture (e.g. sparcv9), not the exact model (e.g. Ultra-IIe).
|
@@ -247,26 +247,29 @@ static VALUE cpu_load_avg()
|
|
247
247
|
return la_ary;
|
248
248
|
}
|
249
249
|
|
250
|
-
/*
|
251
|
-
* Provides information about your CPU, including load average information.
|
252
|
-
*/
|
253
250
|
void Init_cpu()
|
254
251
|
{
|
255
|
-
VALUE
|
252
|
+
VALUE mSys, cCPU;
|
256
253
|
|
257
|
-
/*
|
258
|
-
|
259
|
-
|
260
|
-
|
254
|
+
/* The Sys module serves as a toplevel namespace only */
|
255
|
+
mSys = rb_define_module("Sys");
|
256
|
+
|
257
|
+
/* The CPU class provides class methods for obtaining CPU information */
|
258
|
+
cCPU = rb_define_class_under(mSys, "CPU", rb_cObject);
|
259
|
+
|
260
|
+
/* The CPU::Error Exception class is raised whenever any of the CPU class
|
261
|
+
* methods fail.
|
262
|
+
*/
|
263
|
+
cCPUError = rb_define_class_under(cCPU, "Error", rb_eStandardError);
|
261
264
|
|
262
|
-
/*
|
265
|
+
/* 0.6.0: The version of this package, returned as a String */
|
263
266
|
rb_define_const(cCPU, "VERSION", rb_str_new2(SYS_CPU_VERSION));
|
264
267
|
|
265
268
|
/* Class Methods */
|
266
269
|
rb_define_singleton_method(cCPU, "freq", cpu_freq, -1);
|
267
270
|
rb_define_singleton_method(cCPU, "state", cpu_state, -1);
|
268
271
|
rb_define_singleton_method(cCPU, "num_cpu", cpu_num, 0);
|
269
|
-
rb_define_singleton_method(cCPU, "
|
272
|
+
rb_define_singleton_method(cCPU, "cpu_type", cpu_type, 0);
|
270
273
|
rb_define_singleton_method(cCPU, "fpu_type", cpu_fpu_type, 0);
|
271
274
|
rb_define_singleton_method(cCPU, "model", cpu_model, 0);
|
272
275
|
rb_define_singleton_method(cCPU, "load_avg", cpu_load_avg, 0);
|
data/{lib → ext}/version.h
RENAMED
@@ -1,2 +1,2 @@
|
|
1
1
|
/* version.h - one version to rule them all */
|
2
|
-
#define SYS_CPU_VERSION "0.
|
2
|
+
#define SYS_CPU_VERSION "0.6.0"
|
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|solaris/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
|