Skip to content
Newer
Older
100644 150 lines (112 sloc) 3.85 KB
ea041ff @poelzi more work on reference code.
authored Dec 26, 2010
1 module(..., package.seeall)
2
3 function test_list_pids()
4 pids = ulatency.list_pids()
5
ae32b11 @poelzi more tests and api, more datastructures
authored Dec 27, 2010
6 assert_true(#pids > 10, "very unlikely that less then 10 processes exist")
ea041ff @poelzi more work on reference code.
authored Dec 26, 2010
7
8 for k,v in pairs(pids) do
9 assert_number(k, "key not number")
10 assert_number(v, "pid not number")
11 assert_true(v > 0, "pid not > 0")
12 end
13
14 end
15
16 function test_get_pid()
17 pid = ulatency.get_pid(1)
18
19 assert_equal(1, pid.pid)
20 assert_equal(true, pid.is_valid)
0697c38 @poelzi more tests and fixes and api enhancements
authored Jan 5, 2011
21
22 assert_true(pid:get_n_children() > 1, "init should have more then 1 children")
23
24 local childs = pid:get_children()
25
26 assert_equal(pid:get_n_children(), #childs, "size of get_n_children differs")
27
28 for k,v in pairs(childs) do
ae32b11 @poelzi more tests and api, more datastructures
authored Dec 27, 2010
29 assert_u_proc(v)
30 end
0697c38 @poelzi more tests and fixes and api enhancements
authored Jan 5, 2011
31
32
33 end
34
35 function test_flag_inherence()
36 pid = ulatency.get_pid(1)
37
38 local flag_in = ulatency.new_flag{name = "inher", inherit = true}
39 local flag_non = ulatency.new_flag{name = "loc", inherit = false}
ae32b11 @poelzi more tests and api, more datastructures
authored Dec 27, 2010
40
0697c38 @poelzi more tests and fixes and api enhancements
authored Jan 5, 2011
41 pid:add_flag(flag_in)
42 pid:add_flag(flag_non)
43
44 local childs = pid:get_children()
45
46 assert_cmp_table({flag_non, flag_in}, pid:list_flags())
47
48 local exp_child = {flag_in}
49
50 for k,v in pairs(childs) do
51 assert_u_proc(v)
52 assert_cmp_table(exp_child, v:list_flags(true))
53 end
54
55
ea041ff @poelzi more work on reference code.
authored Dec 26, 2010
56 end
57
ae32b11 @poelzi more tests and api, more datastructures
authored Dec 27, 2010
58 function test_list_processes()
59 procs = ulatency.list_processes()
60
61 assert_true(#procs > 10, "very unlikely that less then 10 processes exist")
62
63 for k,v in pairs(procs) do
64 assert_userdata(v, "Not a userdata")
65 assert_u_proc(v)
66 -- FIXME
67 --assert_metatable(ulatency, v, "Not metatable U_PROC")
68 assert_number(k, "key not a number")
69
70 -- except for the root process very one must have a parent
71 local parent = v:get_parent()
72 --print("pid", v.pid)
73 --print("parent:", parent)
74
75 if(v.ppid == 0) then
76 assert_nil(v:get_parent(), "Parent of pid " .. tostring(v.pid) .. " is not nil")
77 else
78 assert_u_proc(parent)
79 end
80 end
81
82 end
ea041ff @poelzi more work on reference code.
authored Dec 26, 2010
83
fdfaa33 @poelzi more mappings and flags api
authored Dec 28, 2010
84 function test_new_flag()
85 local flag = ulatency.new_flag("test")
86 assert_u_flag(flag)
0697c38 @poelzi more tests and fixes and api enhancements
authored Jan 5, 2011
87 assert_equal("test", flag.name)
fdfaa33 @poelzi more mappings and flags api
authored Dec 28, 2010
88 flag.name = "blubb"
0697c38 @poelzi more tests and fixes and api enhancements
authored Jan 5, 2011
89 assert_equal("blubb", flag.name)
90 assert_equal(false, flag.inherit, "inherit")
85a2307 @poelzi add system flags api
authored Jan 13, 2011
91 assert_equal(0, flag.priority, "priority")
92 assert_equal(0, flag.timeout, "timeout")
93 assert_equal(nil, flag.reason, "reason")
94 assert_equal(0, flag.value, "value")
95 assert_equal(0, flag.threshold, "threshold")
96 flag.reason = "bla"
97 assert_equal("bla", flag.reason, "reason test")
fdfaa33 @poelzi more mappings and flags api
authored Dec 28, 2010
98 flag.value = -21823
0697c38 @poelzi more tests and fixes and api enhancements
authored Jan 5, 2011
99 assert_equal(-21823, flag.value)
fdfaa33 @poelzi more mappings and flags api
authored Dec 28, 2010
100 local pid = ulatency.get_pid(1)
101 pid:add_flag(flag)
102 pid:add_flag(flag)
103 pid:add_flag(flag)
104 pprint(pid:list_flags())
105 assert_len(1, pid:list_flags(), "to much flags on proc")
106
107 local flag2 = ulatency.new_flag("haha")
108 pid:add_flag(flag2)
109 pprint(pid:list_flags())
110 assert_len(2, pid:list_flags(), "to much flags on proc")
111
112 pid:del_flag(flag2)
113 pprint(pid:list_flags())
114 assert_len(1, pid:list_flags(), "to much flags on proc")
115 flag2.name = "haha"
116 pid:add_flag(flag2)
117 pid:clear_flag_name("haha")
118 assert_len(1, pid:list_flags(), "to much flags on proc")
119
120 pid:clear_flag_source()
121 assert_len(0, pid:list_flags(), "source clear failed")
122
123 pid:add_flag(flag2)
124 pid:add_flag(flag)
125 pid:clear_flag_all()
85a2307 @poelzi add system flags api
authored Jan 13, 2011
126
fdfaa33 @poelzi more mappings and flags api
authored Dec 28, 2010
127 assert_len(0, pid:list_flags(), "all clear failed")
128
0697c38 @poelzi more tests and fixes and api enhancements
authored Jan 5, 2011
129 -- test with table init
130 local flag3 = ulatency.new_flag{name = "huhu",
131 inherit = 1,
132 priority = 64,
133 value = 23,
134 threshold = 443,
135 timeout = 55,
136 reason = 2,
137 nonsense = 22345}
138 assert_equal("huhu", flag3.name, "name")
139 assert_equal(true, flag3.inherit)
140 assert_equal(64, flag3.priority)
141 assert_equal(55, flag3.timeout)
85a2307 @poelzi add system flags api
authored Jan 13, 2011
142 assert_equal("2", flag3.reason)
0697c38 @poelzi more tests and fixes and api enhancements
authored Jan 5, 2011
143 assert_equal(23, flag3.value)
144 assert_equal(443, flag3.threshold)
145 assert_equal(nil, flag3.nonsense)
146
fdfaa33 @poelzi more mappings and flags api
authored Dec 28, 2010
147 end
148
149
Something went wrong with that request. Please try again.