tmf: Update interface name in commit 1433bda1
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core.tests / src / org / eclipse / linuxtools / lttng2 / kernel / core / tests / stateprovider / StateSystemFullHistoryTest.java
CommitLineData
efc403bb
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>
e743c3b8 5 *
efc403bb
AM
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
e743c3b8 10 *
efc403bb
AM
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.lttng2.kernel.core.tests.stateprovider;
14
6e71ce46
AM
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertNotNull;
17import static org.junit.Assert.assertTrue;
efc403bb
AM
18
19import java.io.File;
efc403bb
AM
20import java.util.List;
21
6e71ce46
AM
22import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
23import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput;
6d08acca 24import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
96345c5a 25import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
6d08acca
AM
26import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
27import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
1e4bb526 28import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
efc403bb 29import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
18ab1d18 30import org.eclipse.linuxtools.tmf.core.statesystem.IStateChangeInput;
f1f86dfb 31import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
6e71ce46
AM
32import org.eclipse.linuxtools.tmf.core.statesystem.StateSystemManager;
33import org.junit.AfterClass;
34import org.junit.BeforeClass;
35import org.junit.Test;
efc403bb
AM
36
37/**
38 * Unit tests for the StateHistorySystem, which uses a full (non-partial)
39 * history and the non-threaded CTF kernel handler.
e743c3b8 40 *
efc403bb 41 * @author alexmont
e743c3b8 42 *
efc403bb 43 */
e743c3b8 44@SuppressWarnings({"nls", "javadoc"})
efc403bb
AM
45public class StateSystemFullHistoryTest {
46
ebd67b34
AM
47 static File stateFile;
48 static File stateFileBenchmark;
efc403bb 49
ebd67b34 50 static IStateChangeInput input;
f1f86dfb 51 static ITmfStateSystem ssq;
efc403bb 52
cc2292bd
AM
53 /* Offset in the trace + start time of the trace */
54 private final static long interestingTimestamp1 = 18670067372290L + 1331649577946812237L;
2359ecca 55
efc403bb
AM
56 protected static String getTestFileName() {
57 return "/tmp/statefile.ht"; //$NON-NLS-1$
58 }
59
60 @BeforeClass
61 public static void initialize() {
62 stateFile = new File(getTestFileName());
63 stateFileBenchmark = new File(getTestFileName() + ".benchmark"); //$NON-NLS-1$
64 try {
dc0f7bfe 65 input = new CtfKernelStateInput(CtfTestFiles.getTestTrace());
e45de797 66 ssq = StateSystemManager.loadStateHistory(stateFile, input, true);
efc403bb
AM
67 } catch (Exception e) {
68 e.printStackTrace();
69 }
efc403bb
AM
70 }
71
72 @AfterClass
73 public static void cleanup() {
ebd67b34
AM
74 boolean ret1, ret2;
75 ret1 = stateFile.delete();
76 ret2 = stateFileBenchmark.delete();
77 if ( !(ret1 && ret2) ) {
6b78e55b
AM
78 System.err.println("Error cleaning up during unit testing, " + //$NON-NLS-1$
79 "you might have leftovers state history files in /tmp"); //$NON-NLS-1$
ebd67b34 80 }
efc403bb
AM
81 }
82
83 /**
84 * Rebuild independently so we can benchmark it. Too bad JUnit doesn't allow
85 * us to @Test the @BeforeClass...
e743c3b8
AM
86 *
87 * @throws IOException
88 * @throws TmfTraceException
efc403bb
AM
89 */
90 @Test
51e216bd 91 public void testBuild() throws TmfTraceException {
6e71ce46 92 IStateChangeInput input2;
f1f86dfb 93 ITmfStateSystem ssb2;
e743c3b8 94
6e71ce46 95 input2 = new CtfKernelStateInput(CtfTestFiles.getTestTrace());
e45de797 96 ssb2 = StateSystemManager.loadStateHistory(stateFileBenchmark, input2, true);
1e4bb526 97
6e71ce46
AM
98 assertEquals(CtfTestFiles.startTime, ssb2.getStartTime());
99 assertEquals(CtfTestFiles.endTime, ssb2.getCurrentEndTime());
efc403bb
AM
100 }
101
102 @Test
51e216bd 103 public void testOpenExistingStateFile() throws TmfTraceException {
f1f86dfb 104 ITmfStateSystem ssb2;
1e4bb526
AM
105
106 /* 'newStateFile' should have already been created */
e45de797 107 ssb2 = StateSystemManager.loadStateHistory(stateFile, null, true);
1e4bb526 108
d26f90fd 109 assertNotNull(ssb2);
6e71ce46
AM
110 assertEquals(CtfTestFiles.startTime, ssb2.getStartTime());
111 assertEquals(CtfTestFiles.endTime, ssb2.getCurrentEndTime());
efc403bb
AM
112 }
113
114 @Test
115 public void testFullQuery1() throws StateValueTypeException,
96345c5a
AM
116 AttributeNotFoundException, TimeRangeException,
117 StateSystemDisposedException {
efc403bb 118
dad01d27 119 List<ITmfStateInterval> list;
efc403bb 120 ITmfStateInterval interval;
4b3ed6ff 121 int quark, valueInt;
efc403bb
AM
122 String valueStr;
123
6e71ce46 124 list = ssq.queryFullState(interestingTimestamp1);
efc403bb 125
6e71ce46 126 quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
dad01d27 127 interval = list.get(quark);
efc403bb 128 valueInt = interval.getStateValue().unboxInt();
2359ecca 129 assertEquals(1397, valueInt);
efc403bb 130
6e71ce46 131 quark = ssq.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME);
dad01d27 132 interval = list.get(quark);
efc403bb 133 valueStr = interval.getStateValue().unboxStr();
2359ecca 134 assertEquals("gdbus", valueStr);
efc403bb 135
6e71ce46 136 quark = ssq.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.SYSTEM_CALL);
ab9bc51b 137 interval = list.get(quark);
ae54340d
AM
138 valueStr = interval.getStateValue().unboxStr();
139 assertTrue(valueStr.equals("sys_poll"));
efc403bb
AM
140 }
141
142 @Test
143 public void testFullQuery2() {
144 //
145 }
146
147 @Test
148 public void testFullQuery3() {
149 //
150 }
151
152 @Test
153 public void testSingleQuery1() throws AttributeNotFoundException,
96345c5a
AM
154 TimeRangeException, StateValueTypeException,
155 StateSystemDisposedException {
efc403bb 156
2359ecca 157 long timestamp = interestingTimestamp1;
efc403bb
AM
158 int quark;
159 ITmfStateInterval interval;
160 String valueStr;
161
6e71ce46
AM
162 quark = ssq.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME);
163 interval = ssq.querySingleState(timestamp, quark);
efc403bb 164 valueStr = interval.getStateValue().unboxStr();
2359ecca 165 assertEquals("gdbus", valueStr);
efc403bb
AM
166 }
167
168 @Test
169 public void testSingleQuery2() {
170 //
171 }
172
173 @Test
174 public void testSingleQuery3() {
175 //
176 }
177
ab9bc51b
AM
178 /**
179 * Test a range query (with no resolution parameter, so all intervals)
180 */
efc403bb
AM
181 @Test
182 public void testRangeQuery1() throws AttributeNotFoundException,
96345c5a
AM
183 TimeRangeException, StateValueTypeException,
184 StateSystemDisposedException {
efc403bb 185
2359ecca 186 long time1 = interestingTimestamp1;
dc0f7bfe 187 long time2 = time1 + 1L * CtfTestFiles.NANOSECS_PER_SEC;
efc403bb
AM
188 int quark;
189 List<ITmfStateInterval> intervals;
190
6e71ce46
AM
191 quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
192 intervals = ssq.queryHistoryRange(quark, time1, time2);
2359ecca
AM
193 assertEquals(487, intervals.size()); /* Number of context switches! */
194 assertEquals(1685, intervals.get(100).getStateValue().unboxInt());
cc2292bd 195 assertEquals(1331668248427681372L, intervals.get(205).getEndTime());
efc403bb
AM
196 }
197
1d3d1293
AM
198 /**
199 * Range query, but with a t2 far off the end of the trace.
200 * The result should still be valid.
201 */
202 @Test
203 public void testRangeQuery2() throws TimeRangeException,
96345c5a 204 AttributeNotFoundException, StateSystemDisposedException {
1d3d1293
AM
205
206 List<ITmfStateInterval> intervals;
e743c3b8 207
6e71ce46
AM
208 int quark = ssq.getQuarkAbsolute(Attributes.RESOURCES, Attributes.IRQS, "1");
209 long ts1 = ssq.getStartTime(); /* start of the trace */
1d3d1293
AM
210 long ts2 = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid, but ignored */
211
6e71ce46 212 intervals = ssq.queryHistoryRange(quark, ts1, ts2);
1d3d1293 213
06552532
AM
214 /* Activity of IRQ 1 over the whole trace */
215 assertEquals(65, intervals.size());
1d3d1293
AM
216 }
217
ab9bc51b
AM
218 /**
219 * Test a range query with a resolution
220 */
221 @Test
1d3d1293 222 public void testRangeQuery3() throws AttributeNotFoundException,
96345c5a
AM
223 TimeRangeException, StateValueTypeException,
224 StateSystemDisposedException {
ab9bc51b
AM
225
226 long time1 = interestingTimestamp1;
dc0f7bfe 227 long time2 = time1 + 1L * CtfTestFiles.NANOSECS_PER_SEC;
ab9bc51b
AM
228 long resolution = 1000000; /* One query every millisecond */
229 int quark;
230 List<ITmfStateInterval> intervals;
231
6e71ce46 232 quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
b5a8d0cc 233 intervals = ssq.queryHistoryRange(quark, time1, time2, resolution, null);
a9f966a2 234 assertEquals(126, intervals.size()); /* Number of context switches! */
ab9bc51b 235 assertEquals(1452, intervals.get(50).getStateValue().unboxInt());
a9f966a2 236 assertEquals(1331668248815698779L, intervals.get(100).getEndTime());
ab9bc51b
AM
237 }
238
efc403bb
AM
239 /**
240 * Ask for a time range outside of the trace's range
efc403bb
AM
241 */
242 @Test(expected = TimeRangeException.class)
96345c5a
AM
243 public void testFullQueryInvalidTime1() throws TimeRangeException,
244 StateSystemDisposedException {
dc0f7bfe 245 long ts = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC;
6e71ce46 246 ssq.queryFullState(ts);
efc403bb
AM
247 }
248
249 @Test(expected = TimeRangeException.class)
96345c5a
AM
250 public void testFullQueryInvalidTime2() throws TimeRangeException,
251 StateSystemDisposedException {
dc0f7bfe 252 long ts = CtfTestFiles.startTime - 20L * CtfTestFiles.NANOSECS_PER_SEC;
6e71ce46 253 ssq.queryFullState(ts);
efc403bb
AM
254 }
255
256 @Test(expected = TimeRangeException.class)
257 public void testSingleQueryInvalidTime1()
96345c5a
AM
258 throws AttributeNotFoundException, TimeRangeException,
259 StateSystemDisposedException {
efc403bb 260
6e71ce46 261 int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
dc0f7bfe 262 long ts = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC;
6e71ce46 263 ssq.querySingleState(ts, quark);
efc403bb
AM
264 }
265
266 @Test(expected = TimeRangeException.class)
267 public void testSingleQueryInvalidTime2()
96345c5a
AM
268 throws AttributeNotFoundException, TimeRangeException,
269 StateSystemDisposedException {
efc403bb 270
6e71ce46 271 int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
dc0f7bfe 272 long ts = CtfTestFiles.startTime - 20L * CtfTestFiles.NANOSECS_PER_SEC;
6e71ce46 273 ssq.querySingleState(ts, quark);
efc403bb
AM
274 }
275
276 @Test(expected = TimeRangeException.class)
277 public void testRangeQueryInvalidTime1() throws AttributeNotFoundException,
96345c5a 278 TimeRangeException, StateSystemDisposedException {
efc403bb 279
6e71ce46 280 int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
dc0f7bfe
AM
281 long ts1 = CtfTestFiles.startTime - 20L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid */
282 long ts2 = CtfTestFiles.startTime + 1L * CtfTestFiles.NANOSECS_PER_SEC; /* valid */
efc403bb 283
6e71ce46 284 ssq.queryHistoryRange(quark, ts1, ts2);
efc403bb
AM
285 }
286
287 @Test(expected = TimeRangeException.class)
288 public void testRangeQueryInvalidTime2() throws TimeRangeException,
96345c5a 289 AttributeNotFoundException, StateSystemDisposedException {
efc403bb 290
6e71ce46 291 int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
dc0f7bfe
AM
292 long ts1 = CtfTestFiles.startTime - 1L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid */
293 long ts2 = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid */
efc403bb 294
6e71ce46 295 ssq.queryHistoryRange(quark, ts1, ts2);
efc403bb
AM
296 }
297
298 /**
299 * Ask for a non-existing attribute
e743c3b8 300 *
efc403bb
AM
301 * @throws AttributeNotFoundException
302 */
303 @Test(expected = AttributeNotFoundException.class)
304 public void testQueryInvalidAttribute() throws AttributeNotFoundException {
305
6e71ce46 306 ssq.getQuarkAbsolute("There", "is", "no", "cow", "level");
efc403bb
AM
307 }
308
309 /**
310 * Query but with the wrong State Value type
efc403bb
AM
311 */
312 @Test(expected = StateValueTypeException.class)
313 public void testQueryInvalidValuetype1() throws StateValueTypeException,
96345c5a
AM
314 AttributeNotFoundException, TimeRangeException,
315 StateSystemDisposedException {
dad01d27 316 List<ITmfStateInterval> list;
efc403bb
AM
317 ITmfStateInterval interval;
318 int quark;
319
6e71ce46
AM
320 list = ssq.queryFullState(interestingTimestamp1);
321 quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
dad01d27 322 interval = list.get(quark);
2359ecca
AM
323
324 /* This is supposed to be an int value */
325 interval.getStateValue().unboxStr();
efc403bb
AM
326 }
327
328 @Test(expected = StateValueTypeException.class)
329 public void testQueryInvalidValuetype2() throws StateValueTypeException,
96345c5a
AM
330 AttributeNotFoundException, TimeRangeException,
331 StateSystemDisposedException {
dad01d27 332 List<ITmfStateInterval> list;
efc403bb
AM
333 ITmfStateInterval interval;
334 int quark;
335
6e71ce46
AM
336 list = ssq.queryFullState(interestingTimestamp1);
337 quark = ssq.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME);
dad01d27 338 interval = list.get(quark);
2359ecca
AM
339
340 /* This is supposed to be a String value */
341 interval.getStateValue().unboxInt();
efc403bb
AM
342 }
343
344 @Test
345 public void testFullAttributeName() throws AttributeNotFoundException {
6e71ce46
AM
346 int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
347 String name = ssq.getFullAttributePath(quark);
2359ecca 348 assertEquals(name, "CPUs/0/Current_thread");
efc403bb
AM
349 }
350
6abc2d88
AM
351 @Test
352 public void testGetQuarks_begin() {
6e71ce46 353 List<Integer> list = ssq.getQuarks("*", "1577", Attributes.EXEC_NAME);
6abc2d88
AM
354
355 assertEquals(1, list.size());
6abc2d88
AM
356 }
357
358 @Test
359 public void testGetQuarks_middle() {
6e71ce46 360 List<Integer> list = ssq.getQuarks(Attributes.THREADS, "*", Attributes.EXEC_NAME);
6abc2d88 361
1ba498e5
AM
362 /* Number of different kernel threads in the trace */
363 assertEquals(168, list.size());
6abc2d88
AM
364 }
365
366 @Test
367 public void testGetQuarks_end() {
6e71ce46 368 List<Integer> list = ssq.getQuarks(Attributes.THREADS, "1577", "*");
6abc2d88 369
1ba498e5
AM
370 /* There should be 4 sub-attributes for each Thread node */
371 assertEquals(4, list.size());
6abc2d88 372 }
efc403bb 373}
This page took 0.050748 seconds and 5 git commands to generate.