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