Commit | Line | Data |
---|---|---|
f9a76cac AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 Ericsson | |
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 | ||
40 | protected static IStateChangeInput input; | |
41 | protected static ITmfStateSystem ssq; | |
42 | ||
43 | /* Offset in the trace + start time of the trace */ | |
44 | private static final long interestingTimestamp1 = 18670067372290L + 1331649577946812237L; | |
45 | ||
46 | @Test | |
47 | public void testFullQuery1() throws StateValueTypeException, | |
48 | AttributeNotFoundException, TimeRangeException, | |
49 | StateSystemDisposedException { | |
50 | ||
51 | List<ITmfStateInterval> list; | |
52 | ITmfStateInterval interval; | |
53 | int quark, valueInt; | |
54 | String valueStr; | |
55 | ||
56 | list = ssq.queryFullState(interestingTimestamp1); | |
57 | ||
58 | quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
59 | interval = list.get(quark); | |
60 | valueInt = interval.getStateValue().unboxInt(); | |
61 | assertEquals(1397, valueInt); | |
62 | ||
63 | quark = ssq.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME); | |
64 | interval = list.get(quark); | |
65 | valueStr = interval.getStateValue().unboxStr(); | |
66 | assertEquals("gdbus", valueStr); | |
67 | ||
68 | quark = ssq.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.SYSTEM_CALL); | |
69 | interval = list.get(quark); | |
70 | valueStr = interval.getStateValue().unboxStr(); | |
71 | assertTrue(valueStr.equals("sys_poll")); | |
72 | } | |
73 | ||
74 | @Test | |
75 | public void testSingleQuery1() throws AttributeNotFoundException, | |
76 | TimeRangeException, StateValueTypeException, | |
77 | StateSystemDisposedException { | |
78 | ||
79 | long timestamp = interestingTimestamp1; | |
80 | int quark; | |
81 | ITmfStateInterval interval; | |
82 | String valueStr; | |
83 | ||
84 | quark = ssq.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME); | |
85 | interval = ssq.querySingleState(timestamp, quark); | |
86 | valueStr = interval.getStateValue().unboxStr(); | |
87 | assertEquals("gdbus", valueStr); | |
88 | } | |
89 | ||
90 | /** | |
91 | * Test a range query (with no resolution parameter, so all intervals) | |
92 | */ | |
93 | @Test | |
94 | public void testRangeQuery1() throws AttributeNotFoundException, | |
95 | TimeRangeException, StateValueTypeException, | |
96 | StateSystemDisposedException { | |
97 | ||
98 | long time1 = interestingTimestamp1; | |
99 | long time2 = time1 + 1L * CtfTestFiles.NANOSECS_PER_SEC; | |
100 | int quark; | |
101 | List<ITmfStateInterval> intervals; | |
102 | ||
103 | quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
104 | intervals = ssq.queryHistoryRange(quark, time1, time2); | |
105 | assertEquals(487, intervals.size()); /* Number of context switches! */ | |
106 | assertEquals(1685, intervals.get(100).getStateValue().unboxInt()); | |
107 | assertEquals(1331668248427681372L, intervals.get(205).getEndTime()); | |
108 | } | |
109 | ||
110 | /** | |
111 | * Range query, but with a t2 far off the end of the trace. | |
112 | * The result should still be valid. | |
113 | */ | |
114 | @Test | |
115 | public void testRangeQuery2() throws TimeRangeException, | |
116 | AttributeNotFoundException, StateSystemDisposedException { | |
117 | ||
118 | List<ITmfStateInterval> intervals; | |
119 | ||
120 | int quark = ssq.getQuarkAbsolute(Attributes.RESOURCES, Attributes.IRQS, "1"); | |
121 | long ts1 = ssq.getStartTime(); /* start of the trace */ | |
122 | long ts2 = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid, but ignored */ | |
123 | ||
124 | intervals = ssq.queryHistoryRange(quark, ts1, ts2); | |
125 | ||
126 | /* Activity of IRQ 1 over the whole trace */ | |
127 | assertEquals(65, intervals.size()); | |
128 | } | |
129 | ||
130 | /** | |
131 | * Test a range query with a resolution | |
132 | */ | |
133 | @Test | |
134 | public void testRangeQuery3() throws AttributeNotFoundException, | |
135 | TimeRangeException, StateValueTypeException, | |
136 | StateSystemDisposedException { | |
137 | ||
138 | long time1 = interestingTimestamp1; | |
139 | long time2 = time1 + 1L * CtfTestFiles.NANOSECS_PER_SEC; | |
140 | long resolution = 1000000; /* One query every millisecond */ | |
141 | int quark; | |
142 | List<ITmfStateInterval> intervals; | |
143 | ||
144 | quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
145 | intervals = ssq.queryHistoryRange(quark, time1, time2, resolution, null); | |
146 | assertEquals(126, intervals.size()); /* Number of context switches! */ | |
147 | assertEquals(1452, intervals.get(50).getStateValue().unboxInt()); | |
148 | assertEquals(1331668248815698779L, intervals.get(100).getEndTime()); | |
149 | } | |
150 | ||
151 | /** | |
152 | * Ask for a time range outside of the trace's range | |
153 | */ | |
154 | @Test(expected = TimeRangeException.class) | |
155 | public void testFullQueryInvalidTime1() throws TimeRangeException, | |
156 | StateSystemDisposedException { | |
157 | long ts = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC; | |
158 | ssq.queryFullState(ts); | |
159 | } | |
160 | ||
161 | @Test(expected = TimeRangeException.class) | |
162 | public void testFullQueryInvalidTime2() throws TimeRangeException, | |
163 | StateSystemDisposedException { | |
164 | long ts = CtfTestFiles.startTime - 20L * CtfTestFiles.NANOSECS_PER_SEC; | |
165 | ssq.queryFullState(ts); | |
166 | } | |
167 | ||
168 | @Test(expected = TimeRangeException.class) | |
169 | public void testSingleQueryInvalidTime1() | |
170 | throws AttributeNotFoundException, TimeRangeException, | |
171 | StateSystemDisposedException { | |
172 | ||
173 | int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
174 | long ts = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC; | |
175 | ssq.querySingleState(ts, quark); | |
176 | } | |
177 | ||
178 | @Test(expected = TimeRangeException.class) | |
179 | public void testSingleQueryInvalidTime2() | |
180 | throws AttributeNotFoundException, TimeRangeException, | |
181 | StateSystemDisposedException { | |
182 | ||
183 | int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
184 | long ts = CtfTestFiles.startTime - 20L * CtfTestFiles.NANOSECS_PER_SEC; | |
185 | ssq.querySingleState(ts, quark); | |
186 | } | |
187 | ||
188 | @Test(expected = TimeRangeException.class) | |
189 | public void testRangeQueryInvalidTime1() throws AttributeNotFoundException, | |
190 | TimeRangeException, StateSystemDisposedException { | |
191 | ||
192 | int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
193 | long ts1 = CtfTestFiles.startTime - 20L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid */ | |
194 | long ts2 = CtfTestFiles.startTime + 1L * CtfTestFiles.NANOSECS_PER_SEC; /* valid */ | |
195 | ||
196 | ssq.queryHistoryRange(quark, ts1, ts2); | |
197 | } | |
198 | ||
199 | @Test(expected = TimeRangeException.class) | |
200 | public void testRangeQueryInvalidTime2() throws TimeRangeException, | |
201 | AttributeNotFoundException, StateSystemDisposedException { | |
202 | ||
203 | int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
204 | long ts1 = CtfTestFiles.startTime - 1L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid */ | |
205 | long ts2 = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid */ | |
206 | ||
207 | ssq.queryHistoryRange(quark, ts1, ts2); | |
208 | } | |
209 | ||
210 | /** | |
211 | * Ask for a non-existing attribute | |
212 | * | |
213 | * @throws AttributeNotFoundException | |
214 | */ | |
215 | @Test(expected = AttributeNotFoundException.class) | |
216 | public void testQueryInvalidAttribute() throws AttributeNotFoundException { | |
217 | ||
218 | ssq.getQuarkAbsolute("There", "is", "no", "cow", "level"); | |
219 | } | |
220 | ||
221 | /** | |
222 | * Query but with the wrong State Value type | |
223 | */ | |
224 | @Test(expected = StateValueTypeException.class) | |
225 | public void testQueryInvalidValuetype1() throws StateValueTypeException, | |
226 | AttributeNotFoundException, TimeRangeException, | |
227 | StateSystemDisposedException { | |
228 | List<ITmfStateInterval> list; | |
229 | ITmfStateInterval interval; | |
230 | int quark; | |
231 | ||
232 | list = ssq.queryFullState(interestingTimestamp1); | |
233 | quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
234 | interval = list.get(quark); | |
235 | ||
236 | /* This is supposed to be an int value */ | |
237 | interval.getStateValue().unboxStr(); | |
238 | } | |
239 | ||
240 | @Test(expected = StateValueTypeException.class) | |
241 | public void testQueryInvalidValuetype2() throws StateValueTypeException, | |
242 | AttributeNotFoundException, TimeRangeException, | |
243 | StateSystemDisposedException { | |
244 | List<ITmfStateInterval> list; | |
245 | ITmfStateInterval interval; | |
246 | int quark; | |
247 | ||
248 | list = ssq.queryFullState(interestingTimestamp1); | |
249 | quark = ssq.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME); | |
250 | interval = list.get(quark); | |
251 | ||
252 | /* This is supposed to be a String value */ | |
253 | interval.getStateValue().unboxInt(); | |
254 | } | |
255 | ||
256 | @Test | |
257 | public void testFullAttributeName() throws AttributeNotFoundException { | |
258 | int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); | |
259 | String name = ssq.getFullAttributePath(quark); | |
260 | assertEquals(name, "CPUs/0/Current_thread"); | |
261 | } | |
262 | ||
263 | @Test | |
264 | public void testGetQuarks_begin() { | |
265 | List<Integer> list = ssq.getQuarks("*", "1577", Attributes.EXEC_NAME); | |
266 | ||
267 | assertEquals(1, list.size()); | |
268 | } | |
269 | ||
270 | @Test | |
271 | public void testGetQuarks_middle() { | |
272 | List<Integer> list = ssq.getQuarks(Attributes.THREADS, "*", Attributes.EXEC_NAME); | |
273 | ||
274 | /* Number of different kernel threads in the trace */ | |
275 | assertEquals(168, list.size()); | |
276 | } | |
277 | ||
278 | @Test | |
279 | public void testGetQuarks_end() { | |
280 | List<Integer> list = ssq.getQuarks(Attributes.THREADS, "1577", "*"); | |
281 | ||
282 | /* There should be 4 sub-attributes for each Thread node */ | |
283 | assertEquals(4, list.size()); | |
284 | } | |
285 | } |