tmf: Add a new package for state history backends
[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 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
18 import java.io.File;
19
20 import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput;
21 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
22 import org.eclipse.linuxtools.tmf.core.statesystem.IStateChangeInput;
23 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
24 import org.eclipse.linuxtools.tmf.core.statesystem.StateSystemManager;
25 import org.junit.AfterClass;
26 import org.junit.BeforeClass;
27 import org.junit.Test;
28
29 /**
30 * State system tests using a full history back-end and the LTTng kernel state
31 * input.
32 *
33 * @author Alexandre Montplaisir
34 */
35 public class StateSystemFullHistoryTest extends StateSystemTest {
36
37 private static File stateFile;
38 private static File stateFileBenchmark;
39
40 /**
41 * Initialize the test cases (build the history file once for all tests).
42 */
43 @BeforeClass
44 public static void initialize() {
45 try {
46 stateFile = File.createTempFile("test", ".ht"); //$NON-NLS-1$ //$NON-NLS-2$
47 stateFileBenchmark = File.createTempFile("test", ".ht.benchmark"); //$NON-NLS-1$ //$NON-NLS-2$
48
49 input = new CtfKernelStateInput(CtfTestFiles.getTestTrace());
50 ssq = StateSystemManager.loadStateHistory(stateFile, input, true);
51 } catch (Exception e) {
52 e.printStackTrace();
53 }
54 }
55
56 /**
57 * Delete the temp files after we're done
58 */
59 @AfterClass
60 public static void cleanup() {
61 boolean ret1, ret2;
62 ret1 = stateFile.delete();
63 ret2 = stateFileBenchmark.delete();
64 if ( !(ret1 && ret2) ) {
65 System.err.println("Error cleaning up during unit testing, " + //$NON-NLS-1$
66 "you might have leftovers state history files in /tmp"); //$NON-NLS-1$
67 }
68 }
69
70 // ------------------------------------------------------------------------
71 // Tests specific to a full-history
72 // ------------------------------------------------------------------------
73
74 /**
75 * Rebuild independently so we can benchmark it. Too bad JUnit doesn't allow
76 * us to @Test the @BeforeClass...
77 *
78 * @throws TmfTraceException
79 * Fails the test
80 */
81 @Test
82 public void testBuild() throws TmfTraceException {
83 IStateChangeInput input2;
84 ITmfStateSystem ssb2;
85
86 input2 = new CtfKernelStateInput(CtfTestFiles.getTestTrace());
87 ssb2 = StateSystemManager.loadStateHistory(stateFileBenchmark, input2, true);
88
89 assertEquals(CtfTestFiles.startTime, ssb2.getStartTime());
90 assertEquals(CtfTestFiles.endTime, ssb2.getCurrentEndTime());
91 }
92
93 /**
94 * Test re-opening the existing file.
95 *
96 * @throws TmfTraceException
97 * Fails the test
98 */
99 @Test
100 public void testOpenExistingStateFile() throws TmfTraceException {
101 ITmfStateSystem ssb2;
102
103 /* 'newStateFile' should have already been created */
104 ssb2 = StateSystemManager.loadStateHistory(stateFile, null, true);
105
106 assertNotNull(ssb2);
107 assertEquals(CtfTestFiles.startTime, ssb2.getStartTime());
108 assertEquals(CtfTestFiles.endTime, ssb2.getCurrentEndTime());
109 }
110
111 }
This page took 0.036076 seconds and 6 git commands to generate.