Commit | Line | Data |
---|---|---|
f9a76cac | 1 | /******************************************************************************* |
94cce698 | 2 | * Copyright (c) 2012, 2013 Ericsson |
f9a76cac AM |
3 | * Copyright (c) 2010, 2011 École Polytechnique de Montréal |
4 | * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com> | |
5 | * | |
6 | * All rights reserved. This program and the accompanying materials are | |
7 | * made available under the terms of the Eclipse Public License v1.0 which | |
8 | * accompanies this distribution, and is available at | |
9 | * http://www.eclipse.org/legal/epl-v10.html | |
10 | * | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.lttng2.kernel.core.tests.stateprovider; | |
14 | ||
15 | import static org.junit.Assert.assertEquals; | |
16 | import static org.junit.Assert.assertTrue; | |
17 | ||
18 | import java.util.List; | |
19 | ||
20 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes; | |
21 | import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; | |
22 | import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException; | |
23 | import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; | |
24 | import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; | |
25 | import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; | |
26 | import org.eclipse.linuxtools.tmf.core.statesystem.IStateChangeInput; | |
27 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; | |
28 | import org.junit.Test; | |
29 | ||
30 | /** | |
31 | * Base unit tests for the StateHistorySystem. Extension can be made to test | |
32 | * different state back-end types or configurations. | |
33 | * | |
34 | * @author Alexandre Montplaisir | |
35 | * | |
36 | */ | |
37 | @SuppressWarnings({"nls", "javadoc"}) | |
38 | public abstract class StateSystemTest { | |
39 | ||
92ba8466 AM |
40 | /** Index of the test trace used for these tests */ |
41 | protected static final int TRACE_INDEX = 1; | |
42 | ||
43 | /** Expected start time of the test trace/state history */ | |
44 | protected static final long startTime = 1331668247314038062L; | |
45 | ||
46 | /** Expected end time of the state history built from the test trace */ | |
47 | protected static final long endTime = 1331668259054285979L; | |
48 | ||
49 | /** Number of nanoseconds in one second */ | |
50 | private static final long NANOSECS_PER_SEC = 1000000000L; | |
51 | ||
f9a76cac AM |
52 | protected static IStateChangeInput input; |
53 | protected static ITmfStateSystem ssq; | |
54 | ||
55 | /* Offset in the trace + start time of the trace */ | |
56 | private static final long interestingTimestamp1 = 18670067372290L + 1331649577946812237L; | |
57 | ||
58 | @Test | |
59 | public void testFullQuery1() throws StateValueTypeException, | |
60 | AttributeNotFoundException, TimeRangeException, | |
61 | StateSystemDisposedException { | |
62 | ||
63 | List<ITmfStateInterval> list; | |
64 | ITmfStateInterval interval; | |
65 | int quark, valueInt; | |
66 | String valueStr; | |
67 | ||
68 | list = ssq.queryFullState(interestingTimestamp1); | |
69 | ||
70 | quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
71 | interval = list.get(quark); | |
72 | valueInt = interval.getStateValue().unboxInt(); | |
73 | assertEquals(1397, valueInt); | |
74 | ||
75 | quark = ssq.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME); | |
76 | interval = list.get(quark); | |
77 | valueStr = interval.getStateValue().unboxStr(); | |
78 | assertEquals("gdbus", valueStr); | |
79 | ||
80 | quark = ssq.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.SYSTEM_CALL); | |
81 | interval = list.get(quark); | |
82 | valueStr = interval.getStateValue().unboxStr(); | |
83 | assertTrue(valueStr.equals("sys_poll")); | |
84 | } | |
85 | ||
86 | @Test | |
87 | public void testSingleQuery1() throws AttributeNotFoundException, | |
88 | TimeRangeException, StateValueTypeException, | |
89 | StateSystemDisposedException { | |
90 | ||
91 | long timestamp = interestingTimestamp1; | |
92 | int quark; | |
93 | ITmfStateInterval interval; | |
94 | String valueStr; | |
95 | ||
96 | quark = ssq.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME); | |
97 | interval = ssq.querySingleState(timestamp, quark); | |
98 | valueStr = interval.getStateValue().unboxStr(); | |
99 | assertEquals("gdbus", valueStr); | |
100 | } | |
101 | ||
102 | /** | |
103 | * Test a range query (with no resolution parameter, so all intervals) | |
104 | */ | |
105 | @Test | |
106 | public void testRangeQuery1() throws AttributeNotFoundException, | |
107 | TimeRangeException, StateValueTypeException, | |
108 | StateSystemDisposedException { | |
109 | ||
110 | long time1 = interestingTimestamp1; | |
92ba8466 | 111 | long time2 = time1 + 1L * NANOSECS_PER_SEC; |
f9a76cac AM |
112 | int quark; |
113 | List<ITmfStateInterval> intervals; | |
114 | ||
115 | quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
116 | intervals = ssq.queryHistoryRange(quark, time1, time2); | |
117 | assertEquals(487, intervals.size()); /* Number of context switches! */ | |
118 | assertEquals(1685, intervals.get(100).getStateValue().unboxInt()); | |
119 | assertEquals(1331668248427681372L, intervals.get(205).getEndTime()); | |
120 | } | |
121 | ||
122 | /** | |
123 | * Range query, but with a t2 far off the end of the trace. | |
124 | * The result should still be valid. | |
125 | */ | |
126 | @Test | |
127 | public void testRangeQuery2() throws TimeRangeException, | |
128 | AttributeNotFoundException, StateSystemDisposedException { | |
129 | ||
130 | List<ITmfStateInterval> intervals; | |
131 | ||
132 | int quark = ssq.getQuarkAbsolute(Attributes.RESOURCES, Attributes.IRQS, "1"); | |
133 | long ts1 = ssq.getStartTime(); /* start of the trace */ | |
92ba8466 | 134 | long ts2 = startTime + 20L * NANOSECS_PER_SEC; /* invalid, but ignored */ |
f9a76cac AM |
135 | |
136 | intervals = ssq.queryHistoryRange(quark, ts1, ts2); | |
137 | ||
138 | /* Activity of IRQ 1 over the whole trace */ | |
139 | assertEquals(65, intervals.size()); | |
140 | } | |
141 | ||
142 | /** | |
143 | * Test a range query with a resolution | |
144 | */ | |
145 | @Test | |
146 | public void testRangeQuery3() throws AttributeNotFoundException, | |
147 | TimeRangeException, StateValueTypeException, | |
148 | StateSystemDisposedException { | |
149 | ||
150 | long time1 = interestingTimestamp1; | |
92ba8466 | 151 | long time2 = time1 + 1L * NANOSECS_PER_SEC; |
f9a76cac AM |
152 | long resolution = 1000000; /* One query every millisecond */ |
153 | int quark; | |
154 | List<ITmfStateInterval> intervals; | |
155 | ||
156 | quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
157 | intervals = ssq.queryHistoryRange(quark, time1, time2, resolution, null); | |
158 | assertEquals(126, intervals.size()); /* Number of context switches! */ | |
159 | assertEquals(1452, intervals.get(50).getStateValue().unboxInt()); | |
160 | assertEquals(1331668248815698779L, intervals.get(100).getEndTime()); | |
161 | } | |
162 | ||
163 | /** | |
164 | * Ask for a time range outside of the trace's range | |
165 | */ | |
166 | @Test(expected = TimeRangeException.class) | |
167 | public void testFullQueryInvalidTime1() throws TimeRangeException, | |
168 | StateSystemDisposedException { | |
92ba8466 | 169 | long ts = startTime + 20L * NANOSECS_PER_SEC; |
f9a76cac AM |
170 | ssq.queryFullState(ts); |
171 | } | |
172 | ||
173 | @Test(expected = TimeRangeException.class) | |
174 | public void testFullQueryInvalidTime2() throws TimeRangeException, | |
175 | StateSystemDisposedException { | |
92ba8466 | 176 | long ts = startTime - 20L * NANOSECS_PER_SEC; |
f9a76cac AM |
177 | ssq.queryFullState(ts); |
178 | } | |
179 | ||
180 | @Test(expected = TimeRangeException.class) | |
181 | public void testSingleQueryInvalidTime1() | |
182 | throws AttributeNotFoundException, TimeRangeException, | |
183 | StateSystemDisposedException { | |
184 | ||
185 | int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
92ba8466 | 186 | long ts = startTime + 20L * NANOSECS_PER_SEC; |
f9a76cac AM |
187 | ssq.querySingleState(ts, quark); |
188 | } | |
189 | ||
190 | @Test(expected = TimeRangeException.class) | |
191 | public void testSingleQueryInvalidTime2() | |
192 | throws AttributeNotFoundException, TimeRangeException, | |
193 | StateSystemDisposedException { | |
194 | ||
195 | int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
92ba8466 | 196 | long ts = startTime - 20L * NANOSECS_PER_SEC; |
f9a76cac AM |
197 | ssq.querySingleState(ts, quark); |
198 | } | |
199 | ||
200 | @Test(expected = TimeRangeException.class) | |
201 | public void testRangeQueryInvalidTime1() throws AttributeNotFoundException, | |
202 | TimeRangeException, StateSystemDisposedException { | |
203 | ||
204 | int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
92ba8466 AM |
205 | long ts1 = startTime - 20L * NANOSECS_PER_SEC; /* invalid */ |
206 | long ts2 = startTime + 1L * NANOSECS_PER_SEC; /* valid */ | |
f9a76cac AM |
207 | |
208 | ssq.queryHistoryRange(quark, ts1, ts2); | |
209 | } | |
210 | ||
211 | @Test(expected = TimeRangeException.class) | |
212 | public void testRangeQueryInvalidTime2() throws TimeRangeException, | |
213 | AttributeNotFoundException, StateSystemDisposedException { | |
214 | ||
215 | int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
92ba8466 AM |
216 | long ts1 = startTime - 1L * NANOSECS_PER_SEC; /* invalid */ |
217 | long ts2 = startTime + 20L * NANOSECS_PER_SEC; /* invalid */ | |
f9a76cac AM |
218 | |
219 | ssq.queryHistoryRange(quark, ts1, ts2); | |
220 | } | |
221 | ||
222 | /** | |
223 | * Ask for a non-existing attribute | |
224 | * | |
225 | * @throws AttributeNotFoundException | |
226 | */ | |
227 | @Test(expected = AttributeNotFoundException.class) | |
228 | public void testQueryInvalidAttribute() throws AttributeNotFoundException { | |
229 | ||
230 | ssq.getQuarkAbsolute("There", "is", "no", "cow", "level"); | |
231 | } | |
232 | ||
233 | /** | |
234 | * Query but with the wrong State Value type | |
235 | */ | |
236 | @Test(expected = StateValueTypeException.class) | |
237 | public void testQueryInvalidValuetype1() throws StateValueTypeException, | |
238 | AttributeNotFoundException, TimeRangeException, | |
239 | StateSystemDisposedException { | |
240 | List<ITmfStateInterval> list; | |
241 | ITmfStateInterval interval; | |
242 | int quark; | |
243 | ||
244 | list = ssq.queryFullState(interestingTimestamp1); | |
245 | quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
246 | interval = list.get(quark); | |
247 | ||
248 | /* This is supposed to be an int value */ | |
249 | interval.getStateValue().unboxStr(); | |
250 | } | |
251 | ||
252 | @Test(expected = StateValueTypeException.class) | |
253 | public void testQueryInvalidValuetype2() throws StateValueTypeException, | |
254 | AttributeNotFoundException, TimeRangeException, | |
255 | StateSystemDisposedException { | |
256 | List<ITmfStateInterval> list; | |
257 | ITmfStateInterval interval; | |
258 | int quark; | |
259 | ||
260 | list = ssq.queryFullState(interestingTimestamp1); | |
261 | quark = ssq.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME); | |
262 | interval = list.get(quark); | |
263 | ||
264 | /* This is supposed to be a String value */ | |
265 | interval.getStateValue().unboxInt(); | |
266 | } | |
267 | ||
268 | @Test | |
269 | public void testFullAttributeName() throws AttributeNotFoundException { | |
270 | int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
271 | String name = ssq.getFullAttributePath(quark); | |
272 | assertEquals(name, "CPUs/0/Current_thread"); | |
273 | } | |
274 | ||
275 | @Test | |
276 | public void testGetQuarks_begin() { | |
277 | List<Integer> list = ssq.getQuarks("*", "1577", Attributes.EXEC_NAME); | |
278 | ||
279 | assertEquals(1, list.size()); | |
280 | } | |
281 | ||
282 | @Test | |
283 | public void testGetQuarks_middle() { | |
284 | List<Integer> list = ssq.getQuarks(Attributes.THREADS, "*", Attributes.EXEC_NAME); | |
285 | ||
286 | /* Number of different kernel threads in the trace */ | |
287 | assertEquals(168, list.size()); | |
288 | } | |
289 | ||
290 | @Test | |
291 | public void testGetQuarks_end() { | |
292 | List<Integer> list = ssq.getQuarks(Attributes.THREADS, "1577", "*"); | |
293 | ||
294 | /* There should be 4 sub-attributes for each Thread node */ | |
295 | assertEquals(4, list.size()); | |
296 | } | |
297 | } |