sys-proctable 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/version.h ADDED
@@ -0,0 +1,2 @@
1
+ /* version.h - stores the version number for all platforms (that use C) */
2
+ #define SYS_PROCTABLE_VERSION "0.8.0"
data/test/tc_all.rb ADDED
@@ -0,0 +1,69 @@
1
+ ##################################################
2
+ # tc_all.rb
3
+ #
4
+ # Test suite for methods common to all platforms.
5
+ ##################################################
6
+ base = File.basename(Dir.pwd)
7
+
8
+ if base == "test" || base =~ /sys-proctable.*/
9
+ require "ftools"
10
+ Dir.chdir ".." if base == "test"
11
+ Dir.mkdir("sys") unless File.exists?("sys")
12
+ $LOAD_PATH.unshift Dir.pwd
13
+ end
14
+
15
+ if File::ALT_SEPARATOR
16
+ File.copy("lib/os/windows.rb","sys/proctable.rb")
17
+ else
18
+ extension = ".so"
19
+ extension = ".bundle" if RUBY_PLATFORM =~ /powerpc|darwin/i
20
+ extension = ".sl" if RUBY_PLATFORM =~ /hpux/i
21
+
22
+ pt_file = "proctable" + extension
23
+
24
+ if File.exist?(pt_file)
25
+ File.copy(pt_file, "sys")
26
+ end
27
+ end
28
+
29
+ require "sys/proctable"
30
+ require "test/unit"
31
+ include Sys
32
+
33
+ class TC_ProcTable_All < Test::Unit::TestCase
34
+
35
+ def test_version
36
+ assert_equal('0.8.0', ProcTable::VERSION, "Bad VERSION constant")
37
+ end
38
+
39
+ def test_fields
40
+ assert_respond_to(ProcTable, :fields)
41
+ assert_nothing_raised{ ProcTable.fields }
42
+ assert_kind_of(Array, ProcTable.fields)
43
+ assert_kind_of(String, ProcTable.fields.first)
44
+ end
45
+
46
+ def test_ps
47
+ assert_respond_to(ProcTable, :ps)
48
+ assert_nothing_raised{ ProcTable.ps }
49
+ assert_nothing_raised{ ProcTable.ps{} }
50
+ end
51
+
52
+ def test_ps_with_args
53
+ assert_nothing_raised{ ProcTable.ps(0) }
54
+ assert_nothing_raised{ ProcTable.ps(nil) }
55
+ assert_raises(TypeError){ ProcTable.ps("vim") }
56
+ assert_raises(ArgumentError){ ProcTable.ps(0,1) }
57
+ end
58
+
59
+ def test_ps_return_values
60
+ assert_kind_of(Array, ProcTable.ps)
61
+ assert_kind_of(Struct::ProcTableStruct, ProcTable.ps(1))
62
+ assert_equal(nil, ProcTable.ps(999999999))
63
+ assert_equal(nil, ProcTable.ps{})
64
+ end
65
+
66
+ alias :set_up :setup
67
+ alias :tear_down :teardown
68
+
69
+ end
@@ -0,0 +1,60 @@
1
+ ############################################
2
+ # tc_freebsd.rb
3
+ #
4
+ # Test suite for sys-proctable for FreeBSD.
5
+ ############################################
6
+ base = File.basename(Dir.pwd)
7
+
8
+ if base == "test" || base =~ /sys-proctable.*/
9
+ require "ftools"
10
+ Dir.chdir("..") if base == "test"
11
+ Dir.mkdir("sys") unless File.exists?("sys")
12
+ File.copy("proctable.so","sys") if File.exists?("proctable.so")
13
+ $LOAD_PATH.unshift(Dir.pwd)
14
+ end
15
+
16
+ require "sys/proctable"
17
+ require "test/unit"
18
+ require "test/tc_all"
19
+ include Sys
20
+
21
+ class TC_ProcTable_FreeBSD < Test::Unit::TestCase
22
+
23
+ def setup
24
+ @fields = %w/
25
+ comm pid ppid pgid sid tdev_maj tdev_min flags start
26
+ utime stime wchan euid ruid rgid egid groups cmdline
27
+ /
28
+ @pt = ProcTable.ps.first
29
+ end
30
+
31
+ def test_field_members
32
+ msg = "Struct members don't match expected fields"
33
+ assert_equal(@fields.length, @pt.length, "Bad length")
34
+ assert_equal(@fields, ProcTable.fields, "Bad fields")
35
+ assert_equal(@fields, @pt.members, msg)
36
+ end
37
+
38
+ def test_struct_member_types
39
+ @fields.each{ |f|
40
+ if %w/comm cmdline groups wchan flags/.include?(f)
41
+ assert_kind_of(String, @pt.send(f), "Bad #{f} type")
42
+ elsif %w/utime stime/.include?(f)
43
+ assert_kind_of(Float, @pt.send(f), "Bad #{f} type")
44
+ elsif %w/start/.include?(f)
45
+ assert_kind_of(Time, @pt.send(f), "Bad #{f} type")
46
+ else
47
+ assert_kind_of(Fixnum, @pt.send(f), "Bad #{f} type")
48
+ end
49
+ }
50
+ end
51
+
52
+ def teardown
53
+ @fields = nil
54
+ @pt = nil
55
+ end
56
+
57
+ alias :set_up :setup
58
+ alias :tear_down :teardown
59
+
60
+ end
data/test/tc_hpux.rb ADDED
@@ -0,0 +1,64 @@
1
+ ##################################################
2
+ # tc_hpux.rb
3
+ #
4
+ # Test suite for sys-proctable for HP-UX
5
+ # Requires testunit 0.1.6 or later.
6
+ ##################################################
7
+ base = File.basename(Dir.pwd)
8
+
9
+ if base == "test" || base =~ /sys-proctable.*/
10
+ require "ftools"
11
+ Dir.chdir("..") if base == "test"
12
+ Dir.mkdir("sys") unless File.exists?("sys")
13
+ File.copy("proctable.sl","sys") if File.exists?("proctable.sl")
14
+ $LOAD_PATH.unshift(Dir.pwd)
15
+ end
16
+
17
+ require "sys/proctable"
18
+ require "test/unit"
19
+ require "test/tc_all"
20
+ include Sys
21
+
22
+ class TC_ProcTable_HPUX < Test::Unit::TestCase
23
+
24
+ def setup
25
+ @fields = %w/
26
+ comm uid pid ppid dsize tsize ssize nice ttydev pgrp pri addr
27
+ cpu utime stime start flag stat wchan procnum cmd cmdline time
28
+ cpticks cptickstotal fss pctcpu rssize suid shmsize mmsize usize
29
+ iosize vtsize vdsize vssize vshmsize vmmsize vusize viosize
30
+ minorfaults majorfaults nswap nsignals msgrcv msgsnd maxrss
31
+ sid schedpolicy ticksleft euid egid gid sgid
32
+ /
33
+ @pt = ProcTable.ps.first
34
+ end
35
+
36
+ def test_expected_fields
37
+ msg = "Struct members don't match expected fields"
38
+ assert_equal(@fields.length, @pt.length,"Bad length")
39
+ assert_equal(@fields, ProcTable.fields,"Bad fields")
40
+ assert_equal(@fields, @pt.members,msg)
41
+ end
42
+
43
+ def test_struct_member_types
44
+ @fields.each{ |f|
45
+ if %w/comm stat cmd cmdline ttydev/.include?(f)
46
+ assert_kind_of(String,@pt.send(f),"Bad #{f} type")
47
+ elsif %w/pctcpu/.include?(f)
48
+ assert_kind_of(Float,@pt.send(f),"Bad #{f} type")
49
+ elsif %w/start/.include(f)
50
+ assert_kind_of(Time,@pt.send(f),"Bad #{f} type")
51
+ else
52
+ assert_kind_of(Fixnum,@pt.send(f),"Bad #{f} type")
53
+ end
54
+ }
55
+ end
56
+
57
+ def teardown
58
+ @fields = nil
59
+ @pt = nil
60
+ end
61
+
62
+ alias :set_up :setup
63
+ alias :tear_down :teardown
64
+ end
@@ -0,0 +1,40 @@
1
+ ################################################################
2
+ # tc_kvm_bsd.rb
3
+ #
4
+ # Test suite for the BSD specific version of the kvm interface.
5
+ ################################################################
6
+ base = File.basename(Dir.pwd)
7
+ if base == "test" || base =~ /sys-proctable.*/
8
+ require "ftools"
9
+ Dir.chdir("..") if base == "test"
10
+ Dir.mkdir("sys") unless File.exists?("sys")
11
+ File.copy("proctable.so","sys") if File.exists?("proctable.so")
12
+ $LOAD_PATH.unshift(Dir.pwd)
13
+ end
14
+
15
+ require "test/unit"
16
+ require "sys/proctable"
17
+ include Sys
18
+
19
+ class TC_KVM_BSD < Test::Unit::TestCase
20
+ def setup
21
+ @fields = %w/
22
+ pid ppid pgid ruid rgid comm state pct_cpu cpu_num tty_num
23
+ tty_dev wchan time priority usr_priority nice cmdline start_time
24
+ max_rss ix_rss id_rss is_rss minflt maxflt nswap inblock oublock
25
+ msgsnd msgrcv nsignals nvcsw nivcsw user_time system_time
26
+ /
27
+ @pt = ProcTable.ps.first
28
+ end
29
+
30
+ def test_field_members
31
+ msg = "Struct members don't match expected fields"
32
+ assert_equal(@fields.length, @pt.length, "Bad number of fields")
33
+ assert_equal(@fields, ProcTable.fields, "Bad field members")
34
+ assert_equal(@fields, @pt.members, msg)
35
+ end
36
+
37
+ def teardown
38
+ @fields = nil
39
+ end
40
+ end
data/test/tc_linux.rb ADDED
@@ -0,0 +1,61 @@
1
+ ##########################################
2
+ # tc_linux.rb
3
+ #
4
+ # Test suite for sys-proctable for Linux.
5
+ ##########################################
6
+ base = File.basename(Dir.pwd)
7
+
8
+ if base == "test" || base =~ /sys-proctable.*/
9
+ require "ftools"
10
+ Dir.chdir("..") if base == "test"
11
+ Dir.mkdir("sys") unless File.exists?("sys")
12
+ File.delete("sys/proctable.so") rescue nil
13
+ File.copy("proctable.so","sys") if File.exists?("proctable.so")
14
+ $LOAD_PATH.unshift(Dir.pwd)
15
+ end
16
+
17
+ require "sys/proctable"
18
+ require "test/unit"
19
+ require "test/tc_all"
20
+ include Sys
21
+
22
+ class TC_ProcTable_Linux < Test::Unit::TestCase
23
+
24
+ def setup
25
+ @fields = %w/
26
+ cmdline cwd exe pid name uid euid gid egid comm state ppid pgrp
27
+ session tty_num tpgid flags minflt cminflt majflt cmajflt utime
28
+ stime cutime cstime priority nice itrealvalue starttime vsize
29
+ rss rlim startcode endcode startstack kstkesp kstkeip signal blocked
30
+ sigignore sigcatch wchan nswap cnswap exit_signal processor environ
31
+ /
32
+ @pt = ProcTable.ps.first
33
+ end
34
+
35
+ def test_field_members
36
+ msg = "Struct members don't match expected fields"
37
+ assert_equal(@fields.length, @pt.length, "Bad length")
38
+ assert_equal(@fields, ProcTable.fields, "Bad fields")
39
+ assert_equal(@fields, @pt.members,msg)
40
+ end
41
+
42
+ def test_struct_member_types
43
+ @fields.each{ |f|
44
+ if %w/cmdline cwd exe name comm state/.include?(f)
45
+ assert_kind_of(String,@pt.send(f),"Bad #{f} type")
46
+ elsif f == "environ"
47
+ assert_kind_of(Hash,@pt.environ,"Bad environ type")
48
+ else
49
+ assert_kind_of(Integer,@pt.send(f),"Bad #{f} type")
50
+ end
51
+ }
52
+ end
53
+
54
+ def teardown
55
+ @pt = nil
56
+ end
57
+
58
+ alias :set_up :setup
59
+ alias :tear_down :teardown
60
+
61
+ end
data/test/tc_sunos.rb ADDED
@@ -0,0 +1,65 @@
1
+ ##################################################
2
+ # tc_sunos.rb
3
+ #
4
+ # Test suite for sys-proctable for SunOS/Solaris.
5
+ ##################################################
6
+ base = File.basename(Dir.pwd)
7
+
8
+ if base == "test" || base =~ /sys-proctable.*/
9
+ require "ftools"
10
+ Dir.chdir("..") if base == "test"
11
+ Dir.mkdir("sys") unless File.exists?("sys")
12
+ File.copy("proctable.so","sys") if File.exists?("proctable.so")
13
+ $LOAD_PATH.unshift(Dir.pwd)
14
+ end
15
+
16
+ require "sys/proctable"
17
+ require "test/unit"
18
+ require "test/tc_all"
19
+ include Sys
20
+
21
+ class TC_ProcTable_SunOS < Test::Unit::TestCase
22
+ def setup
23
+ @fields = %w/
24
+ flag nlwp pid ppid pgid sid uid euid gid egid priority
25
+ nice ttydev time ctime size rss wchan pctcpu pctmem
26
+ state fname cmdline start processor comm num_args
27
+ cmd_args lwpid count tstamp create term rtime utime
28
+ stime ttime tftime dftime kftime ltime slptime wtime
29
+ stoptime minf majf nswap inblk oublk msnd mrcv sigs
30
+ vctx ictx sysc ioch
31
+ /
32
+ @pt = ProcTable.ps.first
33
+ end
34
+
35
+ def test_field_members
36
+ msg = "Struct members don't match expected fields"
37
+ assert_equal(@fields.length, @pt.length, "Bad number of fields")
38
+ assert_equal(@fields, ProcTable.fields, "Bad field members")
39
+ assert_equal(@fields, @pt.members, msg)
40
+ end
41
+
42
+ def test_struct_member_types
43
+ @fields.each{ |f|
44
+ if %w/comm state fname cmdline/.include?(f)
45
+ assert_kind_of(String,@pt.send(f),"Bad #{f} type")
46
+ elsif %w/pctcpu pctmem/.include?(f)
47
+ assert_kind_of(Float,@pt.send(f),"Bad #{f} type")
48
+ elsif %w/cmd_args/.include?(f)
49
+ assert_kind_of(Array,@pt.send(f),"Bad #{f} type")
50
+ elsif %w/start/.include?(f)
51
+ assert_kind_of(Time,@pt.send(f),"Bad #{f} type")
52
+ else
53
+ assert_kind_of(Fixnum,@pt.send(f),"Bad #{f} type")
54
+ end
55
+ }
56
+ end
57
+
58
+ def teardown
59
+ @pt = nil
60
+ @fields = nil
61
+ end
62
+
63
+ alias :set_up :setup
64
+ alias :tear_down :teardown
65
+ end
data/test/tc_top.rb ADDED
@@ -0,0 +1,37 @@
1
+ ##############################################################################
2
+ # tc_top.rb
3
+ #
4
+ # Test suite for the sys-top package that is included with this distribution.
5
+ ##############################################################################
6
+ base = File.basename(Dir.pwd)
7
+
8
+ if base == "test" || base =~ /sys-proctable.*/
9
+ require "ftools"
10
+ Dir.chdir("..") if base == "test"
11
+ Dir.mkdir("sys") unless File.exists?("sys")
12
+ File.copy("lib/top.rb","sys")
13
+ $LOAD_PATH.unshift Dir.pwd
14
+ $LOAD_PATH.unshift Dir.pwd + "/lib"
15
+ end
16
+
17
+ require "sys/top"
18
+ require "test/unit"
19
+ include Sys
20
+
21
+ class TC_Top < Test::Unit::TestCase
22
+ def test_version
23
+ assert_equal("1.0.1", Top::VERSION)
24
+ end
25
+
26
+ def test_top
27
+ assert_respond_to(Top,:top)
28
+ assert_nothing_raised{ Top.top }
29
+ assert_nothing_raised{ Top.top(5) }
30
+ assert_nothing_raised{ Top.top(5,"cmdline") }
31
+ assert_raises(ArgumentError){ Top.top(1,"foo",2) }
32
+ assert_kind_of(Array,Top.top)
33
+ assert_equal(10,Top.top.length)
34
+ assert_equal(5,Top.top(5).length)
35
+ assert_kind_of(Struct::ProcTableStruct,Top.top.first)
36
+ end
37
+ end
@@ -0,0 +1,51 @@
1
+ ##################################################
2
+ # tc_windows.rb
3
+ #
4
+ # Test suite for sys-proctable for MS Windows
5
+ ##################################################
6
+ base = File.basename(Dir.pwd)
7
+
8
+ if base == "test" || base =~ /sys-proctable.*/
9
+ require "ftools"
10
+ Dir.chdir ".." if base == "test"
11
+ Dir.mkdir("sys") unless File.exists?("sys")
12
+ File.copy("lib/os/windows.rb","sys/proctable.rb")
13
+ $LOAD_PATH.unshift Dir.pwd
14
+ end
15
+
16
+ require "sys/proctable"
17
+ require "test/unit"
18
+ require "test/tc_all"
19
+ include Sys
20
+
21
+ class TC_ProcTable_MSWindows < Test::Unit::TestCase
22
+ def setup
23
+ @fields = %w/
24
+ caption cmdline comm creation_class_name creation_date
25
+ cs_creation_class_name cs_name description executable_path
26
+ execution_state handle handle_count install_date kernel_mode_time
27
+ maximum_working_set_size minimum_working_set_size name
28
+ os_creation_class_name os_name other_operation_count
29
+ other_transfer_count page_faults page_file_usage
30
+ peak_virtual_size ppid peak_working_set_size priority
31
+ private_page_count pid quota_non_paged_pool_usage
32
+ quota_paged_pool_usage quota_peak_non_paged_pool_usage
33
+ quota_non_paged_pool_usage read_operation_count read_transfer_count
34
+ session_id termination_date thread_count user_mode_time virtual_size
35
+ windows_version working_set_size write_operation_count write_transfer_count
36
+ /
37
+ @pt = ProcTable.ps.first
38
+ end
39
+
40
+ def test_field_members
41
+ msg = "Struct members don't match expected fields"
42
+ assert_equal(@fields.length, @pt.length, "Bad length")
43
+ assert_equal(@fields, ProcTable.fields, "Bad fields")
44
+ assert_equal(@fields, @pt.members, msg)
45
+ end
46
+
47
+ def teardown
48
+ @pt = nil
49
+ @fields = nil
50
+ end
51
+ end