sys-uptime 0.5.4-x86-mingw32 → 0.6.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,65 +1,109 @@
1
- #####################################################################
2
- # test_sys_uptime.rb
3
- #
4
- # Test suite for sys-uptime. This should generally be run via the
5
- # 'rake test' task, since it handles the pre-setup code for you.
6
- #####################################################################
7
- require 'sys/uptime'
8
- require 'test/unit'
9
- include Sys
10
-
11
- class TC_Sys_Uptime < Test::Unit::TestCase
12
- def test_version
13
- assert_equal('0.5.4', Uptime::VERSION)
14
- end
15
-
16
- def test_seconds
17
- assert_respond_to(Uptime, :seconds)
18
- assert_nothing_raised{ Uptime.seconds }
19
- assert_kind_of(Fixnum, Uptime.seconds)
20
- assert_equal(true, Uptime.seconds > 0)
21
- end
22
-
23
- def test_minutes
24
- assert_respond_to(Uptime, :minutes)
25
- assert_nothing_raised{ Uptime.minutes }
26
- assert_kind_of(Fixnum, Uptime.minutes)
27
- end
28
-
29
- def test_hours
30
- assert_respond_to(Uptime, :hours)
31
- assert_nothing_raised{ Uptime.hours }
32
- assert_kind_of(Fixnum, Uptime.hours)
33
- end
34
-
35
- def test_days
36
- assert_respond_to(Uptime,:days)
37
- assert_nothing_raised{ Uptime.days }
38
- assert_kind_of(Fixnum, Uptime.days)
39
- end
40
-
41
- def test_uptime
42
- assert_respond_to(Uptime,:uptime)
43
- assert_nothing_raised{ Uptime.uptime }
44
- assert_kind_of(String, Uptime.uptime)
45
- assert_equal(false, Uptime.uptime.empty?)
46
- end
47
-
48
- def test_dhms
49
- assert_respond_to(Uptime,:dhms)
50
- assert_nothing_raised{ Uptime.dhms }
51
- assert_kind_of(Array, Uptime.dhms)
52
- assert_equal(false, Uptime.dhms.empty?)
53
- assert_equal(4, Uptime.dhms.length)
54
- end
55
-
56
- def test_boot_time
57
- assert_respond_to(Uptime,:boot_time)
58
- assert_nothing_raised{ Uptime.boot_time }
59
- assert_kind_of(Time, Uptime.boot_time)
60
- end
61
-
62
- def test_uptime_error
63
- assert_kind_of(StandardError, Uptime::Error.new)
64
- end
65
- end
1
+ #####################################################################
2
+ # test_sys_uptime.rb
3
+ #
4
+ # Test suite for sys-uptime. This should generally be run via the
5
+ # 'rake test' task, since it handles the pre-setup code for you.
6
+ #####################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'sys/uptime'
11
+ require 'test/unit'
12
+ require 'socket'
13
+ include Sys
14
+
15
+ class TC_Sys_Uptime < Test::Unit::TestCase
16
+ test "version is set to expected value" do
17
+ assert_equal('0.6.0', Uptime::VERSION)
18
+ end
19
+
20
+ test "seconds method basic functionality" do
21
+ assert_respond_to(Uptime, :seconds)
22
+ assert_nothing_raised{ Uptime.seconds }
23
+ end
24
+
25
+ test "seconds method returns a plausible value" do
26
+ assert_kind_of(Integer, Uptime.seconds)
27
+ assert_true(Uptime.seconds > 300)
28
+ end
29
+
30
+ test "minutes method basic functionality" do
31
+ assert_respond_to(Uptime, :minutes)
32
+ assert_nothing_raised{ Uptime.minutes }
33
+ end
34
+
35
+ test "minutes method returns a plausible value" do
36
+ assert_kind_of(Integer, Uptime.minutes)
37
+ assert_true(Uptime.minutes > 5)
38
+ end
39
+
40
+ test "hours method basic functionality" do
41
+ assert_respond_to(Uptime, :hours)
42
+ assert_nothing_raised{ Uptime.hours }
43
+ end
44
+
45
+ test "hours method returns a plausible value" do
46
+ assert_kind_of(Integer, Uptime.hours)
47
+ assert_true(Uptime.hours > 0)
48
+ end
49
+
50
+ test "days method basic functionality" do
51
+ assert_respond_to(Uptime, :days)
52
+ assert_nothing_raised{ Uptime.days }
53
+ end
54
+
55
+ test "days method returns a plausible value" do
56
+ assert_kind_of(Fixnum, Uptime.days)
57
+ assert_true(Uptime.days >= 0)
58
+ end
59
+
60
+ test "uptime method basic functionality" do
61
+ assert_respond_to(Uptime, :uptime)
62
+ assert_nothing_raised{ Uptime.uptime }
63
+ end
64
+
65
+ test "uptime method returns a non-empty string" do
66
+ assert_kind_of(String, Uptime.uptime)
67
+ assert_false(Uptime.uptime.empty?)
68
+ end
69
+
70
+ test "uptime method does not accept any arguments" do
71
+ omit_if(File::ALT_SEPARATOR)
72
+ assert_raise(ArgumentError){ Uptime.uptime(1) }
73
+ end
74
+
75
+ test "uptime accepts a host name on Windows" do
76
+ omit_unless(File::ALT_SEPARATOR, "MS Windows only")
77
+ assert_nothing_raised{ Uptime.uptime(Socket.gethostname) }
78
+ end
79
+
80
+ test "dhms method basic functionality" do
81
+ assert_respond_to(Uptime, :dhms)
82
+ assert_nothing_raised{ Uptime.dhms }
83
+ assert_kind_of(Array, Uptime.dhms)
84
+ end
85
+
86
+ test "dhms method returns an array of four elements" do
87
+ assert_false(Uptime.dhms.empty?)
88
+ assert_equal(4, Uptime.dhms.length)
89
+ end
90
+
91
+ test "boot_time method basic functionality" do
92
+ assert_respond_to(Uptime, :boot_time)
93
+ assert_nothing_raised{ Uptime.boot_time }
94
+ end
95
+
96
+ test "boot_time method returns a Time object" do
97
+ assert_kind_of(Time, Uptime.boot_time)
98
+ end
99
+
100
+ test "Uptime class cannot be instantiated" do
101
+ assert_kind_of(StandardError, Uptime::Error.new)
102
+ end
103
+
104
+ test "Ensure that ffi functions are private" do
105
+ methods = Uptime.methods(false).map{ |e| e.to_s }
106
+ assert_false(Uptime.methods.include?('time'))
107
+ assert_false(Uptime.methods.include?('times'))
108
+ end
109
+ end
metadata CHANGED
@@ -1,82 +1,61 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sys-uptime
3
- version: !ruby/object:Gem::Version
4
- hash: 3
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 5
9
- - 4
10
- version: 0.5.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ prerelease:
11
6
  platform: x86-mingw32
12
- authors:
7
+ authors:
13
8
  - Daniel J. Berger
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-07-27 00:00:00 -06:00
19
- default_executable:
12
+ date: 2011-12-11 00:00:00.000000000Z
20
13
  dependencies: []
21
-
22
- description: " The sys-uptime library is a simple interface for gathering uptime\n information. You can retrieve data in seconds, minutes, days, hours,\n or all of the above.\n"
14
+ description: ! " The sys-uptime library is a simple interface for gathering uptime\n
15
+ \ information. You can retrieve data in seconds, minutes, days, hours,\n or
16
+ all of the above.\n"
23
17
  email: djberg96@gmail.com
24
18
  executables: []
25
-
26
19
  extensions: []
27
-
28
- extra_rdoc_files:
20
+ extra_rdoc_files:
29
21
  - CHANGES
30
22
  - README
31
23
  - MANIFEST
32
- - doc/uptime.txt
33
- files:
24
+ files:
34
25
  - CHANGES
35
- - doc/uptime.txt
36
- - examples/sys_uptime_example.rb
37
- - ext/extconf.rb
38
- - ext/sys/uptime.c
39
- - lib/linux/sys/uptime.rb
26
+ - examples/uptime_test.rb
27
+ - lib/unix/sys/uptime.rb
40
28
  - lib/windows/sys/uptime.rb
41
29
  - MANIFEST
42
30
  - Rakefile
43
31
  - README
44
32
  - sys-uptime.gemspec
45
33
  - test/test_sys_uptime.rb
46
- has_rdoc: true
47
- homepage: http://www.rubyforge.org/projects/sysutils
48
- licenses: []
49
-
34
+ homepage: https://github.com/djberg96/sys-uptime
35
+ licenses:
36
+ - Artistic 2.0
50
37
  post_install_message:
51
38
  rdoc_options: []
52
-
53
- require_paths:
39
+ require_paths:
54
40
  - lib
55
41
  - lib/windows
56
- required_ruby_version: !ruby/object:Gem::Requirement
42
+ required_ruby_version: !ruby/object:Gem::Requirement
57
43
  none: false
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- hash: 3
62
- segments:
63
- - 0
64
- version: "0"
65
- required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
49
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
74
54
  requirements: []
75
-
76
55
  rubyforge_project: sysutils
77
- rubygems_version: 1.3.7
56
+ rubygems_version: 1.7.2
78
57
  signing_key:
79
58
  specification_version: 3
80
59
  summary: A Ruby interface for getting system uptime information.
81
- test_files:
60
+ test_files:
82
61
  - test/test_sys_uptime.rb
data/doc/uptime.txt DELETED
@@ -1,98 +0,0 @@
1
- == Description
2
- The sys-uptime library provides uptime and boot time information, similar
3
- to the 'uptime' Unix command.
4
-
5
- == Synopsis
6
- require 'sys/uptime'
7
- include Sys
8
-
9
- p Uptime.days
10
- p Uptime.hours
11
- p Uptime.minutes
12
- p Uptime.seconds
13
- p Uptime.dhms.join(', ')
14
- p Uptime.uptime
15
- p Uptime.boot_time
16
-
17
- == Constants
18
- VERSION
19
- Returns the current version number of this library.
20
-
21
- == Class Methods
22
- Uptime.boot_time
23
- Returns the boot time as a Time object.
24
-
25
- Uptime.days
26
- Returns the total number of days the system has been up.
27
-
28
- Uptime.hours
29
- Returns the total number of hours the system has been up.
30
-
31
- Uptime.minutes
32
- Returns the total number of minutes the system has been up.
33
-
34
- Uptime.seconds
35
- Returns the total number of seconds the system has been up.
36
-
37
- Uptime.dhms
38
- Calculates and returns the number of days, hours, minutes and
39
- seconds the system has been running as a four-element Array.
40
-
41
- Uptime.uptime
42
- Calculates and returns the number of days, hours, minutes and
43
- seconds the system has been running as a colon-separated string.
44
-
45
- == Exceptions
46
- Uptime::Error
47
- Raised if something goes wrong. On Unix, this would likely mean a
48
- failure of the times() function. That would be highly unusual.
49
-
50
- On Windows, it probably means you failed to connect to WMI properly. The
51
- mostly likely reason would be that the WMI service wasn't running.
52
-
53
- == Notes
54
- On MS Windows each of the class methods optionally takes a host name as
55
- a single argument. The default is localhost (or whatever the result of
56
- Socket.gethostname returns).
57
-
58
- The current time, users and load average are NOT included in this
59
- module, even though you may be used to seeing them with the command
60
- line version of 'uptime'. This is because these things have
61
- absolutely nothing to do with uptime. At least, not as I logically
62
- think of uptime.
63
-
64
- This library was tested successfully on a Solaris system with over 1600
65
- days of uptime.
66
-
67
- == Known Bugs
68
- None that I am aware of. Please log any bugs you find on the project
69
- website at http://www.rubyforge.org/projects/sysutils.
70
-
71
- == Questions
72
- "Doesn't Struct::Tms do this?" - No.
73
-
74
- == License
75
- Artistic 2.0
76
-
77
- == Copyright
78
- Copyright 2002-2011, Daniel J. Berger
79
-
80
- All Rights Reserved. This module is free software. It may be used,
81
- redistributed and/or modified under the same terms as Ruby itself.
82
-
83
- == Warranty
84
- This library is provided "as is" and without any express or
85
- implied warranties, including, without limitation, the implied
86
- warranties of merchantability and fitness for a particular purpose.
87
-
88
- == Acknowledgements
89
- Mike Hall for help with the BSD side of things.
90
- Ola Eriksson, whose source code I shamelessly plagiarized to get a better
91
- implementation for systems that have the utmpx.h header file.
92
-
93
- == Authors
94
- Daniel J. Berger
95
- Mike Hall
96
-
97
- == See Also
98
- uptime(1)
data/ext/extconf.rb DELETED
@@ -1,28 +0,0 @@
1
- ##########################################################################
2
- # extconf.rb
3
- #
4
- # Configuration & build script for sys-uptime. Generally speaking you
5
- # should build sys-uptime with the 'rake build' task instead of running
6
- # this script manually.
7
- ##########################################################################
8
- require 'mkmf'
9
- require 'fileutils'
10
-
11
- if RUBY_PLATFORM =~ /windows|win32|cygwin|mingw|dos|linux/i
12
- STDERR.puts "Do not compile on this platform. Run 'rake gem:install' instead."
13
- exit
14
- end
15
-
16
- dir_config('uptime')
17
-
18
- have_header('sys/loadavg.h')
19
-
20
- if have_func('sysctl')
21
- have_header('sys/param.h')
22
- have_header('sys/time.h')
23
- have_header('sys/types.h')
24
- else
25
- have_header('utmpx.h')
26
- end
27
-
28
- create_makefile('sys/uptime', 'sys')
data/ext/sys/uptime.c DELETED
@@ -1,250 +0,0 @@
1
- /******************************************************************************
2
- * uptime.c
3
- *
4
- * Authors:
5
- * Daniel Berger
6
- * Mike Hall
7
- *
8
- * sys-uptime source code for most *nix platforms
9
- *****************************************************************************/
10
- #include <ruby.h>
11
- #include <string.h>
12
- #include <errno.h>
13
-
14
- #ifdef HAVE_SYSCTL
15
-
16
- #include <sys/sysctl.h>
17
-
18
- #ifdef HAVE_SYS_PARAM_H
19
- #include <sys/param.h>
20
- #endif
21
-
22
- #ifdef HAVE_SYS_TIME_H
23
- #include <sys/time.h>
24
- #endif
25
-
26
- #ifdef HAVE_SYS_TYPES_H
27
- #include <sys/types.h>
28
- #endif
29
-
30
- #else
31
-
32
- #include <sys/times.h>
33
- #include <unistd.h>
34
- #include <time.h>
35
-
36
- #ifdef HAVE_UTMPX_H
37
- #include <utmpx.h>
38
- #endif
39
-
40
- #ifdef _SC_CLK_TCK
41
- #define TICKS sysconf(_SC_CLK_TCK)
42
- #else
43
- #define TICKS sysconf(CLOCKS_PER_SEC)
44
- #endif
45
-
46
- #endif
47
-
48
- #ifdef HAVE_SYS_LOADAVG_H
49
- #include <sys/loadavg.h>
50
- #endif
51
-
52
- #define MAXSTRINGSIZE 32 /* reasonable limit */
53
-
54
- #define SYS_UPTIME_VERSION "0.5.4"
55
-
56
- VALUE cUptimeError;
57
-
58
- unsigned long get_uptime_secs()
59
- {
60
- #ifdef HAVE_SYSCTL
61
- struct timeval tv;
62
- size_t tvlen = sizeof(tv);
63
- int mib[2];
64
-
65
- mib[0] = CTL_KERN;
66
- mib[1] = KERN_BOOTTIME;
67
-
68
- if(sysctl(mib, 2, &tv, &tvlen, NULL, 0))
69
- rb_raise(cUptimeError, "sysctl() call failed %s", strerror(errno));
70
-
71
- return time(NULL) - tv.tv_sec;
72
- #else
73
- struct tms tms;
74
- unsigned long seconds;
75
- seconds = times(&tms) / TICKS;
76
-
77
- if(-1 == seconds)
78
- rb_raise(cUptimeError, "times() function failed: %s", strerror(errno));
79
-
80
- if(seconds < 0)
81
- rb_raise(cUptimeError, "value returned larger than type could handle");
82
-
83
- return seconds;
84
- #endif
85
- }
86
-
87
- /*
88
- * call-seq:
89
- * Uptime.seconds
90
- *
91
- * Returns the total number of seconds the system has been up.
92
- */
93
- static VALUE uptime_seconds()
94
- {
95
- return UINT2NUM(get_uptime_secs());
96
- }
97
-
98
- /*
99
- * call-seq:
100
- * Uptime.minutes
101
- *
102
- * Returns the total number of minutes the system has been up.
103
- */
104
- static VALUE uptime_minutes()
105
- {
106
- return UINT2NUM(get_uptime_secs() / 60);
107
- }
108
-
109
- /*
110
- * call-seq:
111
- * Uptime.hours
112
- *
113
- * Returns the total number of hours the system has been up.
114
- */
115
- static VALUE uptime_hours()
116
- {
117
- return UINT2NUM(get_uptime_secs() / 3600);
118
- }
119
-
120
- /*
121
- * call-seq:
122
- * Uptime.days
123
- *
124
- * Returns the total number of days the system has been up.
125
- */
126
- static VALUE uptime_days()
127
- {
128
- return UINT2NUM(get_uptime_secs() / 86400);
129
- }
130
-
131
- /*
132
- * call-seq:
133
- * Uptime.uptime
134
- *
135
- * Calculates and returns the number of days, hours, minutes and
136
- * seconds the system has been running as a colon-separated string.
137
- */
138
- static VALUE uptime_uptime()
139
- {
140
- char c_string[MAXSTRINGSIZE];
141
- long seconds, days, hours, minutes;
142
-
143
- seconds = get_uptime_secs();
144
- days = seconds/86400;
145
- seconds -= days*86400;
146
- hours = seconds/3600;
147
- seconds -= hours*3600;
148
- minutes = seconds/60;
149
- seconds -= minutes*60;
150
-
151
- sprintf(c_string, "%ld:%ld:%ld:%ld", days, hours, minutes, seconds);
152
-
153
- return rb_str_new2(c_string);
154
- }
155
-
156
- /*
157
- * call-seq:
158
- * Uptime.dhms
159
- *
160
- * Calculates and returns the number of days, hours, minutes and
161
- * seconds the system has been running as a four-element Array.
162
- */
163
- static VALUE uptime_dhms()
164
- {
165
- VALUE a = rb_ary_new2(4);
166
- long s, m, h, d;
167
-
168
- s = get_uptime_secs();
169
- d = s / (24*60*60);
170
- h = (s -= d*24*60*60) / ( 60*60);
171
- m = (s -= h* 60*60) / 60;
172
- s -= m* 60;
173
-
174
- rb_ary_push(a, INT2FIX(d));
175
- rb_ary_push(a, INT2FIX(h));
176
- rb_ary_push(a, INT2FIX(m));
177
- rb_ary_push(a, INT2FIX(s));
178
-
179
- return a;
180
- }
181
-
182
- /*
183
- * call-seq:
184
- * Uptime.boot_time
185
- *
186
- * Returns the boot time as a Time object.
187
- */
188
- static VALUE uptime_btime(){
189
- VALUE v_time = Qnil;
190
-
191
- #ifdef HAVE_SYSCTL
192
- struct timeval tv;
193
- size_t tvlen = sizeof(tv);
194
- int mib[2];
195
-
196
- mib[0] = CTL_KERN;
197
- mib[1] = KERN_BOOTTIME;
198
-
199
- if(sysctl(mib, 2, &tv, &tvlen, NULL, 0))
200
- rb_raise(cUptimeError, "sysctl() call failed: %s", strerror(errno));
201
-
202
- v_time = rb_time_new(tv.tv_sec,tv.tv_usec);
203
- #else
204
- #ifdef HAVE_UTMPX_H
205
- struct utmpx* ent;
206
-
207
- setutxent();
208
-
209
- while( (ent = getutxent()) ){
210
- if(ent->ut_type == BOOT_TIME){
211
- v_time = rb_time_new(ent->ut_tv.tv_sec, ent->ut_tv.tv_usec);
212
- break;
213
- }
214
- }
215
-
216
- endutxent();
217
- #else
218
- rb_raise(cUptimeError, "boot_time method not implemented on this platform");
219
- #endif
220
- #endif
221
-
222
- return v_time;
223
- }
224
-
225
- void Init_uptime()
226
- {
227
- VALUE mSys, cUptime;
228
-
229
- /* The Sys module only serves as a toplevel namespace */
230
- mSys = rb_define_module("Sys");
231
-
232
- /* The Uptime encapsulates various bits of uptime information */
233
- cUptime = rb_define_class_under(mSys, "Uptime", rb_cObject);
234
-
235
- /* The Uptime::Error class is raised if any of the Uptime methods fail */
236
- cUptimeError = rb_define_class_under(cUptime, "Error", rb_eStandardError);
237
-
238
- /* 0.5.4: The version of this library */
239
- rb_define_const(cUptime, "VERSION", rb_str_new2(SYS_UPTIME_VERSION));
240
-
241
- /* Singleton Methods */
242
-
243
- rb_define_singleton_method(cUptime, "seconds", uptime_seconds, 0);
244
- rb_define_singleton_method(cUptime, "minutes", uptime_minutes, 0);
245
- rb_define_singleton_method(cUptime, "hours", uptime_hours, 0);
246
- rb_define_singleton_method(cUptime, "days", uptime_days, 0);
247
- rb_define_singleton_method(cUptime, "uptime", uptime_uptime, 0);
248
- rb_define_singleton_method(cUptime, "dhms", uptime_dhms, 0);
249
- rb_define_singleton_method(cUptime, "boot_time", uptime_btime, 0);
250
- }