1d0178f3ba12ea00914c5332202abd6dfe044af8
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core.tests / src / org / eclipse / linuxtools / lttng2 / kernel / core / tests / stateprovider / StateSystemFullHistoryTest.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Alexandre Montplaisir - Initial API and implementation
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.assertNotNull;
17 import static org.junit.Assume.assumeTrue;
18
19 import java.io.File;
20 import java.io.IOException;
21
22 import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput;
23 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
24 import org.eclipse.linuxtools.tmf.core.statesystem.IStateChangeInput;
25 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
26 import org.eclipse.linuxtools.tmf.core.statesystem.StateSystemManager;
27 import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30
31 /**
32 * State system tests using a full history back-end and the LTTng kernel state
33 * input.
34 *
35 * @author Alexandre Montplaisir
36 */
37 public class StateSystemFullHistoryTest extends StateSystemTest {
38
39 private static File stateFile;
40 private static File stateFileBenchmark;
41
42 /**
43 * Initialize the test cases (build the history file once for all tests).
44 */
45 @BeforeClass
46 public static void initialize() {
47 assumeTrue(CtfTmfTestTraces.tracesExist());
48 try {
49 stateFile = File.createTempFile("test", ".ht"); //$NON-NLS-1$ //$NON-NLS-2$
50 stateFileBenchmark = File.createTempFile("test", ".ht.benchmark"); //$NON-NLS-1$ //$NON-NLS-2$
51
52 input = new CtfKernelStateInput(CtfTmfTestTraces.getTestTrace(TRACE_INDEX));
53 ssq = StateSystemManager.loadStateHistory(stateFile, input, true);
54 } catch (IOException e) {
55 e.printStackTrace();
56 } catch (TmfTraceException e) {
57 e.printStackTrace();
58 } finally {
59 stateFile.deleteOnExit();
60 stateFileBenchmark.deleteOnExit();
61 }
62 }
63
64 // ------------------------------------------------------------------------
65 // Tests specific to a full-history
66 // ------------------------------------------------------------------------
67
68 /**
69 * Rebuild independently so we can benchmark it. Too bad JUnit doesn't allow
70 * us to @Test the @BeforeClass...
71 *
72 * @throws TmfTraceException
73 * Fails the test
74 */
75 @Test
76 public void testBuild() throws TmfTraceException {
77 IStateChangeInput input2;
78 ITmfStateSystem ssb2;
79
80 input2 = new CtfKernelStateInput(CtfTmfTestTraces.getTestTrace(TRACE_INDEX));
81 ssb2 = StateSystemManager.loadStateHistory(stateFileBenchmark, input2, true);
82
83 assertEquals(startTime, ssb2.getStartTime());
84 assertEquals(endTime, ssb2.getCurrentEndTime());
85 }
86
87 /**
88 * Test re-opening the existing file.
89 *
90 * @throws TmfTraceException
91 * Fails the test
92 */
93 @Test
94 public void testOpenExistingStateFile() throws TmfTraceException {
95 ITmfStateSystem ssb2;
96
97 /* 'newStateFile' should have already been created */
98 ssb2 = StateSystemManager.loadStateHistory(stateFile, null, true);
99
100 assertNotNull(ssb2);
101 assertEquals(startTime, ssb2.getStartTime());
102 assertEquals(endTime, ssb2.getCurrentEndTime());
103 }
104
105 }
This page took 0.035988 seconds and 5 git commands to generate.