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