974dec74df2a041e9e4533c8942a696a6e825ca9
[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, 2014 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 * Bernd Hufmann - Use state system analysis module instead of factory
12 ******************************************************************************/
13
14 package org.eclipse.linuxtools.lttng2.kernel.core.tests.stateprovider;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertNotNull;
18 import static org.junit.Assert.assertTrue;
19 import static org.junit.Assert.fail;
20 import static org.junit.Assume.assumeTrue;
21
22 import java.io.File;
23
24 import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.LttngKernelStateProvider;
25 import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
26 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
27 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
28 import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
29 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
30 import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
31 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
32 import org.junit.AfterClass;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35
36 /**
37 * State system tests using a full history back-end and the LTTng kernel state
38 * input.
39 *
40 * @author Alexandre Montplaisir
41 */
42 public class StateSystemFullHistoryTest extends StateSystemTest {
43
44 private static File stateFile;
45 private static File stateFileBenchmark;
46
47 private static final String TEST_FILE_NAME = "test.ht";
48 private static final String BENCHMARK_FILE_NAME = "test.benchmark.ht";
49
50 /**
51 * Initialize the test cases (build the history file once for all tests).
52 */
53 @BeforeClass
54 public static void initialize() {
55 assumeTrue(testTrace.exists());
56 stateFile = createStateFile(TEST_FILE_NAME);
57 stateFileBenchmark = createStateFile(BENCHMARK_FILE_NAME);
58
59 TestLttngKernelAnalysisModule module = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);
60 try {
61 module.setTrace(testTrace.getTrace());
62 } catch (TmfAnalysisException e) {
63 fail();
64 }
65 module.schedule();
66 assertTrue(module.waitForCompletion());
67 ssq = module.getStateSystem();
68
69 assertNotNull(ssq);
70 }
71
72 /**
73 * Clean-up
74 */
75 @AfterClass
76 public static void tearDownClass() {
77 stateFile.delete();
78 stateFileBenchmark.delete();
79 }
80
81 // ------------------------------------------------------------------------
82 // Tests specific to a full-history
83 // ------------------------------------------------------------------------
84
85 /**
86 * Rebuild independently so we can benchmark it. Too bad JUnit doesn't allow
87 * us to @Test the @BeforeClass...
88 */
89 @Test
90 public void testBuild() {
91 TestLttngKernelAnalysisModule module2 = new TestLttngKernelAnalysisModule(BENCHMARK_FILE_NAME);
92 try {
93 module2.setTrace(testTrace.getTrace());
94 } catch (TmfAnalysisException e) {
95 fail();
96 }
97 module2.schedule();
98 assertTrue(module2.waitForCompletion());
99 ITmfStateSystem ssb2 = module2.getStateSystem();
100
101 assertNotNull(ssb2);
102 assertEquals(startTime, ssb2.getStartTime());
103 assertEquals(endTime, ssb2.getCurrentEndTime());
104 }
105
106 /**
107 * Test re-opening the existing file.
108 */
109 @Test
110 public void testOpenExistingStateFile() {
111 /* 'newStateFile' should have already been created */
112 TestLttngKernelAnalysisModule module2 = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);
113 try {
114 module2.setTrace(testTrace.getTrace());
115 } catch (TmfAnalysisException e) {
116 fail();
117 }
118 module2.schedule();
119 assertTrue(module2.waitForCompletion());
120 ITmfStateSystem ssb2 = module2.getStateSystem();
121
122 assertNotNull(ssb2);
123 assertEquals(startTime, ssb2.getStartTime());
124 assertEquals(endTime, ssb2.getCurrentEndTime());
125 }
126
127 private static class TestLttngKernelAnalysisModule extends TmfStateSystemAnalysisModule {
128
129 private final String htFileName;
130
131 /**
132 * Constructor adding the views to the analysis
133 * @param htFileName
134 * The History File Name
135 */
136 public TestLttngKernelAnalysisModule(String htFileName) {
137 super();
138 this.htFileName = htFileName;
139 }
140
141 @Override
142 public void setTrace(ITmfTrace trace) throws TmfAnalysisException {
143 if (!(trace instanceof CtfTmfTrace)) {
144 throw new IllegalStateException("TestLttngKernelAnalysisModule: trace should be of type CtfTmfTrace"); //$NON-NLS-1$
145 }
146 super.setTrace(trace);
147 }
148
149 @Override
150 protected ITmfStateProvider createStateProvider() {
151 return new LttngKernelStateProvider((CtfTmfTrace) getTrace());
152 }
153
154 @Override
155 protected StateSystemBackendType getBackendType() {
156 return StateSystemBackendType.FULL;
157 }
158
159 @Override
160 protected String getSsFileName() {
161 return htFileName;
162 }
163 }
164
165 private static File createStateFile(String name) {
166 File file = new File(TmfTraceManager.getSupplementaryFileDir(testTrace.getTrace()) + name);
167 if (file.exists()) {
168 file.delete();
169 }
170 return file;
171 }
172
173 }
This page took 0.035341 seconds and 4 git commands to generate.