a8a0f62db7a5805bd7fa397460588c19c3683ffa
[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
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.linuxtools.internal.lttng2.kernel.core.stateprovider.LttngKernelStateProvider;
27 import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem;
28 import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
29 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
30 import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
31 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
32 import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
33 import org.eclipse.linuxtools.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.close();
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 try (TestLttngKernelAnalysisModule module2 =
95 new TestLttngKernelAnalysisModule(BENCHMARK_FILE_NAME);) {
96 try {
97 module2.setTrace(testTrace.getTrace());
98 } catch (TmfAnalysisException e) {
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 }
110
111 /**
112 * Test re-opening the existing file.
113 */
114 @Test
115 public void testOpenExistingStateFile() {
116 /* 'newStateFile' should have already been created */
117 try (TestLttngKernelAnalysisModule module2 = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);) {
118 try {
119 module2.setTrace(testTrace.getTrace());
120 } catch (TmfAnalysisException e) {
121 fail();
122 }
123 module2.schedule();
124 assertTrue(module2.waitForCompletion());
125 ITmfStateSystem ssb2 = module2.getStateSystem();
126
127 assertNotNull(ssb2);
128 assertEquals(startTime, ssb2.getStartTime());
129 assertEquals(endTime, ssb2.getCurrentEndTime());
130 }
131 }
132
133 @NonNullByDefault
134 private static class TestLttngKernelAnalysisModule extends TmfStateSystemAnalysisModule {
135
136 private final String htFileName;
137
138 /**
139 * Constructor adding the views to the analysis
140 * @param htFileName
141 * The History File Name
142 */
143 public TestLttngKernelAnalysisModule(String htFileName) {
144 super();
145 this.htFileName = htFileName;
146 }
147
148 @Override
149 public void setTrace(@Nullable ITmfTrace trace) throws TmfAnalysisException {
150 if (!(trace instanceof CtfTmfTrace)) {
151 throw new IllegalStateException("TestLttngKernelAnalysisModule: trace should be of type CtfTmfTrace"); //$NON-NLS-1$
152 }
153 super.setTrace(trace);
154 }
155
156 @Override
157 protected ITmfStateProvider createStateProvider() {
158 return new LttngKernelStateProvider(getTrace());
159 }
160
161 @Override
162 protected StateSystemBackendType getBackendType() {
163 return StateSystemBackendType.FULL;
164 }
165
166 @Override
167 protected String getSsFileName() {
168 return htFileName;
169 }
170 }
171
172 private static File createStateFile(String name) {
173 File file = new File(TmfTraceManager.getSupplementaryFileDir(testTrace.getTrace()) + name);
174 if (file.exists()) {
175 file.delete();
176 }
177 return file;
178 }
179
180 }
This page took 0.036166 seconds and 4 git commands to generate.