sys-uptime 0.4.5-i586-linux
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +109 -0
- data/MANIFEST +17 -0
- data/README +20 -0
- data/doc/uptime.txt +97 -0
- data/ext/uptime.c +231 -0
- data/lib/sys/uptime.rb +59 -0
- data/test/tc_uptime.rb +80 -0
- metadata +56 -0
data/CHANGES
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
== 0.4.5 - 19-Nov-2006
|
2
|
+
* Internal layout changes, minor doc updates and gemspec improvements.
|
3
|
+
* No code changes.
|
4
|
+
|
5
|
+
== 0.4.4 - 30-Jun-2006
|
6
|
+
* Added inline rdoc documentation to the source files.
|
7
|
+
* Added a gemspec.
|
8
|
+
|
9
|
+
== 0.4.3 - 18-Dec-2005
|
10
|
+
* Changed the Linux version to pure Ruby. The current method of determining
|
11
|
+
uptime in unix.c does not work in Linux kernel 2.6+. So, from now on it
|
12
|
+
reads out of /proc/uptime.
|
13
|
+
|
14
|
+
== 0.4.2 - 6-May-2005
|
15
|
+
* Fixed a potential boot_time bug.
|
16
|
+
* Removed the version.h file. It's no longer needed since the Windows
|
17
|
+
version is pure Ruby.
|
18
|
+
* NetBSD 2.x and FreeBSD 5.x now supported.
|
19
|
+
* Removed the INSTALL file. Installation instructions are now in
|
20
|
+
the README file.
|
21
|
+
* Removed the uptime.rd file. You can generate html documentation by
|
22
|
+
running rdoc over the uptime.txt file.
|
23
|
+
* Made most documents rdoc friendly.
|
24
|
+
* Moved project to RubyForge.
|
25
|
+
|
26
|
+
== 0.4.1 - 14-Dec-2004
|
27
|
+
* Moved freebsd code into unix.c file.
|
28
|
+
* Should now work past 249 days (2**31) on systems that have utmpx.h.
|
29
|
+
* Fixed a bug with regards to boot_time, where it was possible that it would
|
30
|
+
simply be empty.
|
31
|
+
|
32
|
+
== 0.4.0 - 8-Jul-2004
|
33
|
+
* Removed all reference to the CLK_TCK constant, as per documentation from
|
34
|
+
Richard Stevens that it is deprecated and that sysconf() should be used
|
35
|
+
instead (well, I knew about this, but ignored it until now).
|
36
|
+
* Scrapped the C version for Windows in favor of a pure Ruby version that
|
37
|
+
uses win32ole + WMI.
|
38
|
+
* Added a boot_time method for Unix systems (Windows already had this).
|
39
|
+
* Added an UptimeError class on Unix systems (and replaced UptimeException
|
40
|
+
on Windows).
|
41
|
+
* Modified an internal function to raise an UptimeError if the times()
|
42
|
+
function fails. Also, it now returns an unsigned long instead of a plain
|
43
|
+
long.
|
44
|
+
* Replaced the two different test suites with a single, unified test suite.
|
45
|
+
* Cleaned up the extconf.rb script. I now assume that TestUnit is installed.
|
46
|
+
* Removed the load_avg method (which was never advertised and which I hope
|
47
|
+
you weren't using). You can find a load_avg method in the sys-cpu package.
|
48
|
+
* Changed uptime.rd2 to uptime.rd to be consistent with my other packages.
|
49
|
+
* Removed the uptime.html file - you may generate that on your own.
|
50
|
+
* Added warranty and license info.
|
51
|
+
|
52
|
+
== 0.3.2 - 30-Dec-2003
|
53
|
+
* Cleaned up some warnings that showed up with -Wall on some unix platforms
|
54
|
+
(int vs long format, explicit include)
|
55
|
+
* Minor test suite and extconf.rb changes
|
56
|
+
|
57
|
+
== 0.3.1 - 25-Jun-2003
|
58
|
+
* Modified test files to handle HP-UX extensions
|
59
|
+
* Minor doc updates
|
60
|
+
* Added the dhms() method. Actually, this was in the 0.3.0
|
61
|
+
release, I just forgot to mention it in this file :)
|
62
|
+
|
63
|
+
== 0.3.0 - 22-Jun-2003
|
64
|
+
* Added OS X support - thanks go to Mike Hall for the patch
|
65
|
+
* Fixed incorrect values in FreeBSD (again Mike Hall)
|
66
|
+
* Modified tc_unix.rb test suite to handle OS X, along with a bit
|
67
|
+
* of minor cleanup
|
68
|
+
* Removed VERSION class method. Use the constant instead
|
69
|
+
* Separated FreeBSD/OS X source into its own file (freebsd.c).
|
70
|
+
The #ifdefs were starting to get too ugly for me
|
71
|
+
|
72
|
+
== 0.2.1 - 13-May-2003
|
73
|
+
* Fixed bug in extconf.rb file, and made some major changes
|
74
|
+
* Modified test.rb for those without TestUnit
|
75
|
+
* Modified TestUnit tests - some bogus tests were removed
|
76
|
+
* Added a README file with some additional info
|
77
|
+
* Created a version.h file, so that I can keep the VERSION number
|
78
|
+
in one place
|
79
|
+
* Docs automatically included in doc directory (i.e. no more interactive
|
80
|
+
document creation)
|
81
|
+
|
82
|
+
== 0.2.0 - 13-Mar-2003
|
83
|
+
* Added MS Windows support
|
84
|
+
* Added a VERSION constant
|
85
|
+
* Added a test suite (for those with TestUnit installed)
|
86
|
+
* Internal directory layout change
|
87
|
+
* uptime.c is now split into unix.c and windows.c (and linked appropriately)
|
88
|
+
* Changelog and Manifest are now CHANGES and MANIFEST, respectively
|
89
|
+
* Many changes to extconf.rb
|
90
|
+
|
91
|
+
== 0.1.3 - 6-Jan-2003
|
92
|
+
* Added a VERSION class method
|
93
|
+
* Added a copyright notice
|
94
|
+
* Fixed up the docs a bit and moved them to the doc directory
|
95
|
+
* Changed the tarball name to match the RAA package name
|
96
|
+
* Modified test.rb script to make it better
|
97
|
+
* Changed install instructions slightly
|
98
|
+
|
99
|
+
== 0.1.2 - 25-Aug-2002
|
100
|
+
* Slight change to preprocessor commands to avoid redefining CLK_TCK on
|
101
|
+
those systems that define it in time.h
|
102
|
+
* Added an INSTALL file
|
103
|
+
|
104
|
+
== 0.1.1 - 21-Jun-2002
|
105
|
+
* The CLK_TCK constant wasn't necessarily being set correctly, which could
|
106
|
+
lead to some odd results. This has been fixed.
|
107
|
+
|
108
|
+
== 0.1.0 - 17-Jun-2002
|
109
|
+
* Initial release
|
data/MANIFEST
ADDED
data/README
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
= Description
|
2
|
+
A Ruby interface for getting system uptime information.
|
3
|
+
|
4
|
+
= Prerequisites
|
5
|
+
Ruby 1.8.0 or later.
|
6
|
+
Ruby 1.8.2 or later is recommended on MS Windows.
|
7
|
+
|
8
|
+
= Installation
|
9
|
+
=== Unix:
|
10
|
+
ruby extconf.rb
|
11
|
+
make
|
12
|
+
ruby test/tc_uptime.rb (optional)
|
13
|
+
make install
|
14
|
+
|
15
|
+
=== Windows and Linux:
|
16
|
+
ruby test\tc_uptime.rb (optional)
|
17
|
+
ruby install.rb
|
18
|
+
|
19
|
+
== Notes
|
20
|
+
For additional documentation see doc/uptime.txt.
|
data/doc/uptime.txt
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
== Synopsis
|
2
|
+
require 'sys/uptime'
|
3
|
+
include Sys
|
4
|
+
|
5
|
+
p Uptime.days
|
6
|
+
p Uptime.hours
|
7
|
+
p Uptime.minutes
|
8
|
+
p Uptime.seconds
|
9
|
+
p Uptime.dhms.join(', ')
|
10
|
+
p Uptime.uptime
|
11
|
+
p Uptime.boot_time
|
12
|
+
|
13
|
+
== Description
|
14
|
+
This package provides uptime and boot time information, similar to the
|
15
|
+
'uptime' Unix command.
|
16
|
+
|
17
|
+
== Constants
|
18
|
+
VERSION
|
19
|
+
Returns the current version number of this package (as a string).
|
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
|
+
UptimeError
|
47
|
+
Raised if something goes wrong. On Unix, this would likely mean a
|
48
|
+
failure of the times() function. On Windows, it probably means you
|
49
|
+
failed to connect to WMI properly.
|
50
|
+
|
51
|
+
== Notes
|
52
|
+
On MS Windows each of the class methods optionally takes a host name as
|
53
|
+
a single argument. The default is localhost (or whatever the result of
|
54
|
+
Socket.gethostname returns).
|
55
|
+
|
56
|
+
The current time, users and load average are NOT included in this
|
57
|
+
module, even though you may be used to seeing them with the command
|
58
|
+
line version of 'uptime'. This is because these things have
|
59
|
+
_absolutely nothing_ to do with uptime (at least, not as I
|
60
|
+
logically think of uptime).
|
61
|
+
|
62
|
+
This package was tested successfully on a Solaris system with over 1600
|
63
|
+
days of uptime.
|
64
|
+
|
65
|
+
== Known Bugs
|
66
|
+
None that I am aware of. Please log any bugs you find on the project
|
67
|
+
website at http://www.rubyforge.org/projects/sysutils.
|
68
|
+
|
69
|
+
== Questions
|
70
|
+
"Doesn't Struct::Tms do this?" - No.
|
71
|
+
|
72
|
+
== License
|
73
|
+
Ruby's
|
74
|
+
|
75
|
+
== Copyright
|
76
|
+
Copyright 2002-2006, Daniel J. Berger
|
77
|
+
|
78
|
+
All Rights Reserved. This module is free software. It may be used,
|
79
|
+
redistributed and/or modified under the same terms as Ruby itself.
|
80
|
+
|
81
|
+
== Warranty
|
82
|
+
This package is provided "as is" and without any express or
|
83
|
+
implied warranties, including, without limitation, the implied
|
84
|
+
warranties of merchantability and fitness for a particular purpose.
|
85
|
+
|
86
|
+
== Acknowledgements
|
87
|
+
Mike Hall for help with the BSD side of things.
|
88
|
+
Ola Eriksson, whose source code I shamelessly plagiarized to get a better
|
89
|
+
implementation for systems that have the utmpx.h header file.
|
90
|
+
|
91
|
+
== Author
|
92
|
+
Daniel J. Berger
|
93
|
+
djberg96 at gmail dot com
|
94
|
+
imperator on IRC (Freenode)
|
95
|
+
|
96
|
+
== See Also
|
97
|
+
uptime
|
data/ext/uptime.c
ADDED
@@ -0,0 +1,231 @@
|
|
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
|
+
|
12
|
+
#if defined (__FreeBSD__) || defined (__NetBSD__)
|
13
|
+
#include <sys/time.h>
|
14
|
+
|
15
|
+
#if defined (__NetBSD__)
|
16
|
+
#include <sys/param.h>
|
17
|
+
#endif
|
18
|
+
|
19
|
+
#if (__FreeBSD >= 5)
|
20
|
+
#include <sys/types.h>
|
21
|
+
#endif
|
22
|
+
|
23
|
+
#include <sys/sysctl.h>
|
24
|
+
|
25
|
+
#else
|
26
|
+
#include <sys/times.h>
|
27
|
+
#include <unistd.h>
|
28
|
+
#include <time.h>
|
29
|
+
|
30
|
+
#ifdef HAVE_UTMPX_H
|
31
|
+
#include <utmpx.h>
|
32
|
+
#endif
|
33
|
+
|
34
|
+
#ifdef HAVE_SYS_LOADAVG_H
|
35
|
+
#include <sys/loadavg.h>
|
36
|
+
#endif
|
37
|
+
|
38
|
+
#ifdef _SC_CLK_TCK
|
39
|
+
#define TICKS sysconf(_SC_CLK_TCK)
|
40
|
+
#else
|
41
|
+
#define TICKS sysconf(CLOCKS_PER_SEC)
|
42
|
+
#endif
|
43
|
+
|
44
|
+
#endif
|
45
|
+
|
46
|
+
#define MAXSTRINGSIZE 32 /* reasonable limit */
|
47
|
+
|
48
|
+
#define SYS_UPTIME_VERSION "0.4.5"
|
49
|
+
|
50
|
+
VALUE cUptimeError;
|
51
|
+
|
52
|
+
unsigned long get_uptime_secs()
|
53
|
+
{
|
54
|
+
#if defined (__FreeBSD__) || defined (__NetBSD__)
|
55
|
+
struct timeval tv;
|
56
|
+
size_t tvlen = sizeof(tv);
|
57
|
+
int mib[2];
|
58
|
+
|
59
|
+
mib[0] = CTL_KERN;
|
60
|
+
mib[1] = KERN_BOOTTIME;
|
61
|
+
if(sysctl(mib, 2, &tv, &tvlen, NULL, 0)){
|
62
|
+
rb_raise(cUptimeError, "sysctl() call failed");
|
63
|
+
}
|
64
|
+
return time(NULL) - tv.tv_sec;
|
65
|
+
#else
|
66
|
+
struct tms tms;
|
67
|
+
unsigned long seconds;
|
68
|
+
seconds = times(&tms) / TICKS;
|
69
|
+
|
70
|
+
if(-1 == seconds)
|
71
|
+
rb_raise(cUptimeError,"times() function failed");
|
72
|
+
|
73
|
+
if(seconds < 0)
|
74
|
+
rb_raise(cUptimeError,"value returned larger than type could handle");
|
75
|
+
|
76
|
+
return seconds;
|
77
|
+
#endif
|
78
|
+
}
|
79
|
+
|
80
|
+
/*
|
81
|
+
* call-seq:
|
82
|
+
* Uptime.seconds
|
83
|
+
*
|
84
|
+
* Returns the total number of seconds the system has been up.
|
85
|
+
*/
|
86
|
+
static VALUE uptime_seconds()
|
87
|
+
{
|
88
|
+
return UINT2NUM(get_uptime_secs());
|
89
|
+
}
|
90
|
+
|
91
|
+
/*
|
92
|
+
* call-seq:
|
93
|
+
* Uptime.minutes
|
94
|
+
*
|
95
|
+
* Returns the total number of minutes the system has been up.
|
96
|
+
*/
|
97
|
+
static VALUE uptime_minutes()
|
98
|
+
{
|
99
|
+
return UINT2NUM(get_uptime_secs() / 60);
|
100
|
+
}
|
101
|
+
|
102
|
+
/*
|
103
|
+
* call-seq:
|
104
|
+
* Uptime.hours
|
105
|
+
*
|
106
|
+
* Returns the total number of hours the system has been up.
|
107
|
+
*/
|
108
|
+
static VALUE uptime_hours()
|
109
|
+
{
|
110
|
+
return UINT2NUM(get_uptime_secs() / 3600);
|
111
|
+
}
|
112
|
+
|
113
|
+
/*
|
114
|
+
* call-seq:
|
115
|
+
* Uptime.days
|
116
|
+
*
|
117
|
+
* Returns the total number of days the system has been up.
|
118
|
+
*/
|
119
|
+
static VALUE uptime_days()
|
120
|
+
{
|
121
|
+
return UINT2NUM(get_uptime_secs() / 86400);
|
122
|
+
}
|
123
|
+
|
124
|
+
/*
|
125
|
+
* call-seq:
|
126
|
+
* Uptime.uptime
|
127
|
+
*
|
128
|
+
* Calculates and returns the number of days, hours, minutes and
|
129
|
+
* seconds the system has been running as a colon-separated string.
|
130
|
+
*/
|
131
|
+
static VALUE uptime_uptime()
|
132
|
+
{
|
133
|
+
char c_string[MAXSTRINGSIZE];
|
134
|
+
long seconds, days, hours, minutes;
|
135
|
+
|
136
|
+
seconds = get_uptime_secs();
|
137
|
+
days = seconds/86400;
|
138
|
+
seconds -= days*86400;
|
139
|
+
hours = seconds/3600;
|
140
|
+
seconds -= hours*3600;
|
141
|
+
minutes = seconds/60;
|
142
|
+
seconds -= minutes*60;
|
143
|
+
|
144
|
+
sprintf(c_string, "%ld:%ld:%ld:%ld", days, hours, minutes, seconds);
|
145
|
+
return rb_str_new2(c_string);
|
146
|
+
}
|
147
|
+
|
148
|
+
/*
|
149
|
+
* call-seq:
|
150
|
+
* Uptime.dhms
|
151
|
+
*
|
152
|
+
* Calculates and returns the number of days, hours, minutes and
|
153
|
+
* seconds the system has been running as a four-element Array.
|
154
|
+
*/
|
155
|
+
static VALUE uptime_dhms()
|
156
|
+
{
|
157
|
+
VALUE a = rb_ary_new2(4);
|
158
|
+
long s, m, h, d;
|
159
|
+
|
160
|
+
s = get_uptime_secs();
|
161
|
+
d = s / (24*60*60);
|
162
|
+
h = (s -= d*24*60*60) / ( 60*60);
|
163
|
+
m = (s -= h* 60*60) / 60;
|
164
|
+
s -= m* 60;
|
165
|
+
|
166
|
+
rb_ary_push(a, INT2FIX(d));
|
167
|
+
rb_ary_push(a, INT2FIX(h));
|
168
|
+
rb_ary_push(a, INT2FIX(m));
|
169
|
+
rb_ary_push(a, INT2FIX(s));
|
170
|
+
return a;
|
171
|
+
}
|
172
|
+
|
173
|
+
/*
|
174
|
+
* call-seq:
|
175
|
+
* Uptime.boot_time
|
176
|
+
*
|
177
|
+
* Returns the boot time as a Time object.
|
178
|
+
*/
|
179
|
+
static VALUE uptime_btime(){
|
180
|
+
#if defined (__FreeBSD__) || defined (__NetBSD__)
|
181
|
+
struct timeval tv;
|
182
|
+
size_t tvlen = sizeof(tv);
|
183
|
+
int mib[2];
|
184
|
+
|
185
|
+
mib[0] = CTL_KERN;
|
186
|
+
mib[1] = KERN_BOOTTIME;
|
187
|
+
if(sysctl(mib, 2, &tv, &tvlen, NULL, 0)){
|
188
|
+
rb_raise(cUptimeError,"sysctl() call failed");
|
189
|
+
}
|
190
|
+
return rb_time_new(tv.tv_sec,tv.tv_usec);
|
191
|
+
#else
|
192
|
+
#ifdef HAVE_UTMPX_H
|
193
|
+
struct utmpx* ent;
|
194
|
+
|
195
|
+
setutxent();
|
196
|
+
|
197
|
+
while( (ent = getutxent()) ){
|
198
|
+
if(ent->ut_type == BOOT_TIME){
|
199
|
+
return rb_time_new(ent->ut_tv.tv_sec,ent->ut_tv.tv_usec);
|
200
|
+
}
|
201
|
+
}
|
202
|
+
|
203
|
+
endutxent();
|
204
|
+
#else
|
205
|
+
rb_raise(cUptimeError,"boot_time() not implemented on this platform");
|
206
|
+
#endif
|
207
|
+
#endif
|
208
|
+
return Qnil;
|
209
|
+
}
|
210
|
+
|
211
|
+
void Init_uptime()
|
212
|
+
{
|
213
|
+
VALUE mSys, cUptime;
|
214
|
+
|
215
|
+
/* Modules and Classes */
|
216
|
+
mSys = rb_define_module("Sys");
|
217
|
+
cUptime = rb_define_class_under(mSys, "Uptime", rb_cObject);
|
218
|
+
cUptimeError = rb_define_class_under(mSys, "UptimeError", rb_eStandardError);
|
219
|
+
|
220
|
+
/* Constants */
|
221
|
+
rb_define_const(cUptime, "VERSION", rb_str_new2(SYS_UPTIME_VERSION));
|
222
|
+
|
223
|
+
/* Class Methods */
|
224
|
+
rb_define_singleton_method(cUptime, "seconds", uptime_seconds, 0);
|
225
|
+
rb_define_singleton_method(cUptime, "minutes", uptime_minutes, 0);
|
226
|
+
rb_define_singleton_method(cUptime, "hours", uptime_hours, 0);
|
227
|
+
rb_define_singleton_method(cUptime, "days", uptime_days, 0);
|
228
|
+
rb_define_singleton_method(cUptime, "uptime", uptime_uptime, 0);
|
229
|
+
rb_define_singleton_method(cUptime, "dhms", uptime_dhms, 0);
|
230
|
+
rb_define_singleton_method(cUptime, "boot_time", uptime_btime, 0);
|
231
|
+
}
|
data/lib/sys/uptime.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# On Linux, parse /proc/uptime
|
2
|
+
module Sys
|
3
|
+
class Uptime
|
4
|
+
VERSION = '0.4.5'
|
5
|
+
|
6
|
+
@@file = '/proc/uptime'
|
7
|
+
|
8
|
+
# Returns the uptime in seconds
|
9
|
+
#
|
10
|
+
def self.seconds
|
11
|
+
IO.readlines(@@file).to_s.split.first.to_i
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns the uptime in minutes
|
15
|
+
#
|
16
|
+
def self.minutes
|
17
|
+
self.seconds / 60
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns the uptime in hours
|
21
|
+
#
|
22
|
+
def self.hours
|
23
|
+
self.minutes / 60
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns the uptime in days
|
27
|
+
#
|
28
|
+
def self.days
|
29
|
+
self.hours / 24
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns the uptime as a colon separated string, including days,
|
33
|
+
# hours, minutes and seconds
|
34
|
+
#
|
35
|
+
def self.uptime
|
36
|
+
seconds = self.seconds
|
37
|
+
days = seconds / 86400
|
38
|
+
seconds -= days * 86400
|
39
|
+
hours = seconds / 3600
|
40
|
+
seconds -= hours * 3600
|
41
|
+
minutes = seconds / 60
|
42
|
+
seconds -= minutes * 60
|
43
|
+
|
44
|
+
"#{days}:#{hours}:#{minutes}:#{seconds}"
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns the uptime as a four element array, including days, hours,
|
48
|
+
# minutes and seconds
|
49
|
+
#
|
50
|
+
def self.dhms
|
51
|
+
self.uptime.split(":")
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns the time the system was booted as a Time object
|
55
|
+
def self.boot_time
|
56
|
+
Time.now - self.seconds
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/test/tc_uptime.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
#################################
|
2
|
+
# tc_uptime.rb
|
3
|
+
#
|
4
|
+
# Test suite for sys-uptime.
|
5
|
+
#################################
|
6
|
+
base = File.basename(Dir.pwd)
|
7
|
+
if base == 'test' || base =~ /sys-uptime.*/
|
8
|
+
require 'fileutils'
|
9
|
+
Dir.chdir('..') if base == 'test'
|
10
|
+
Dir.mkdir('sys') unless File.exists?('sys')
|
11
|
+
|
12
|
+
if RUBY_PLATFORM.match('mswin')
|
13
|
+
FileUtils.cp('lib/sys/windows.rb', 'sys/uptime.rb') rescue nil
|
14
|
+
elsif RUBY_PLATFORM.match('linux')
|
15
|
+
FileUtils.cp('lib/sys/linux.rb', 'sys/uptime.rb') rescue nil
|
16
|
+
else
|
17
|
+
require 'rbconfig'
|
18
|
+
file = 'ext/uptime.' + Config::CONFIG['DLEXT']
|
19
|
+
FileUtils.cp(file, 'sys')
|
20
|
+
end
|
21
|
+
|
22
|
+
$LOAD_PATH.unshift(Dir.pwd)
|
23
|
+
$LOAD_PATH.unshift(Dir.pwd + '/lib')
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'sys/uptime'
|
27
|
+
require 'test/unit'
|
28
|
+
include Sys
|
29
|
+
|
30
|
+
class TC_Uptime < Test::Unit::TestCase
|
31
|
+
def test_version
|
32
|
+
assert_equal('0.4.5', Uptime::VERSION)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_seconds
|
36
|
+
assert_respond_to(Uptime, :seconds)
|
37
|
+
assert_nothing_raised{ Uptime.seconds }
|
38
|
+
assert_kind_of(Fixnum, Uptime.seconds)
|
39
|
+
assert_equal(true, Uptime.seconds > 0)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_minutes
|
43
|
+
assert_respond_to(Uptime, :minutes)
|
44
|
+
assert_nothing_raised{ Uptime.minutes }
|
45
|
+
assert_kind_of(Fixnum, Uptime.minutes)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_hours
|
49
|
+
assert_respond_to(Uptime, :hours)
|
50
|
+
assert_nothing_raised{ Uptime.hours }
|
51
|
+
assert_kind_of(Fixnum, Uptime.hours)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_days
|
55
|
+
assert_respond_to(Uptime,:days)
|
56
|
+
assert_nothing_raised{ Uptime.days }
|
57
|
+
assert_kind_of(Fixnum, Uptime.days)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_uptime
|
61
|
+
assert_respond_to(Uptime,:uptime)
|
62
|
+
assert_nothing_raised{ Uptime.uptime }
|
63
|
+
assert_kind_of(String, Uptime.uptime)
|
64
|
+
assert_equal(false, Uptime.uptime.empty?)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_dhms
|
68
|
+
assert_respond_to(Uptime,:dhms)
|
69
|
+
assert_nothing_raised{ Uptime.dhms }
|
70
|
+
assert_kind_of(Array, Uptime.dhms)
|
71
|
+
assert_equal(false, Uptime.dhms.empty?)
|
72
|
+
assert_equal(4, Uptime.dhms.length)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_boot_time
|
76
|
+
assert_respond_to(Uptime,:boot_time)
|
77
|
+
assert_nothing_raised{ Uptime.boot_time }
|
78
|
+
assert_kind_of(Time, Uptime.boot_time)
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: sys-uptime
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.4.5
|
7
|
+
date: 2006-11-20 00:00:00 -06:00
|
8
|
+
summary: A Ruby interface for getting system uptime information.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: djberg96@gmail.com
|
12
|
+
homepage: http://www.rubyforge.org/projects/sysutils
|
13
|
+
rubyforge_project: sysutils
|
14
|
+
description: A Ruby interface for getting system uptime information.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.8.0
|
24
|
+
version:
|
25
|
+
platform: i586-linux
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Daniel J. Berger
|
31
|
+
files:
|
32
|
+
- doc/uptime.txt
|
33
|
+
- test/tc_uptime.rb
|
34
|
+
- CHANGES
|
35
|
+
- README
|
36
|
+
- MANIFEST
|
37
|
+
- ext/uptime.c
|
38
|
+
- lib/sys/uptime.rb
|
39
|
+
test_files:
|
40
|
+
- test/tc_uptime.rb
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- CHANGES
|
45
|
+
- README
|
46
|
+
- MANIFEST
|
47
|
+
- doc/uptime.txt
|
48
|
+
- ext/uptime.c
|
49
|
+
executables: []
|
50
|
+
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
dependencies: []
|
56
|
+
|