ctf: Move plugins to their own sub-directory
[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, 2015 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.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.analysis.os.linux.core.kernelanalysis.KernelAnalysisModule;
27 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
28 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
29 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
30 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
31 import org.eclipse.tracecompass.tmf.ctf.core.trace.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 final @NonNull String TEST_FILE_NAME = "test.ht";
45 private static final @NonNull String BENCHMARK_FILE_NAME = "test.benchmark.ht";
46
47 private static File stateFile;
48 private static File stateFileBenchmark;
49 private static TestLttngKernelAnalysisModule module;
50
51 /**
52 * Test class setup
53 */
54 @BeforeClass
55 public static void initialize() {
56 if (!testTrace.exists()) {
57 traceIsPresent = false;
58 return;
59 }
60 traceIsPresent = true;
61
62 stateFile = createStateFile(TEST_FILE_NAME);
63 stateFileBenchmark = createStateFile(BENCHMARK_FILE_NAME);
64
65 module = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);
66 try {
67 assertTrue(module.setTrace(testTrace.getTrace()));
68 } catch (TmfAnalysisException e) {
69 fail();
70 }
71 module.schedule();
72 assertTrue(module.waitForCompletion());
73
74 fixture = module.getStateSystem();
75 }
76
77 /**
78 * Clean-up
79 */
80 @AfterClass
81 public static void cleanup() {
82 if (module != null) {
83 module.dispose();
84 }
85 if (stateFile != null) {
86 stateFile.delete();
87 }
88 if (stateFileBenchmark != null) {
89 stateFileBenchmark.delete();
90 }
91 if (fixture != null) {
92 fixture.dispose();
93 }
94 module = null;
95 fixture = null;
96 }
97
98 // ------------------------------------------------------------------------
99 // Tests specific to a full-history
100 // ------------------------------------------------------------------------
101
102 /**
103 * Rebuild independently so we can benchmark it. Too bad JUnit doesn't allow
104 * us to @Test the @BeforeClass...
105 */
106 @Test
107 public void testBuild() {
108 TestLttngKernelAnalysisModule module2 = new TestLttngKernelAnalysisModule(BENCHMARK_FILE_NAME);
109 try {
110 assertTrue(module2.setTrace(testTrace.getTrace()));
111 } catch (TmfAnalysisException e) {
112 module2.dispose();
113 fail();
114 }
115 module2.schedule();
116 assertTrue(module2.waitForCompletion());
117 ITmfStateSystem ssb2 = module2.getStateSystem();
118
119 assertNotNull(ssb2);
120 assertEquals(startTime, ssb2.getStartTime());
121 assertEquals(endTime, ssb2.getCurrentEndTime());
122
123 module2.dispose();
124 }
125
126 /**
127 * Test re-opening the existing file.
128 */
129 @Test
130 public void testOpenExistingStateFile() {
131 /* 'newStateFile' should have already been created */
132 TestLttngKernelAnalysisModule module2 = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);
133 try {
134 assertTrue(module2.setTrace(testTrace.getTrace()));
135 } catch (TmfAnalysisException e) {
136 module2.dispose();
137 fail();
138 }
139 module2.schedule();
140 assertTrue(module2.waitForCompletion());
141 ITmfStateSystem ssb2 = module2.getStateSystem();
142
143 assertNotNull(ssb2);
144 assertEquals(startTime, ssb2.getStartTime());
145 assertEquals(endTime, ssb2.getCurrentEndTime());
146
147 module2.dispose();
148 }
149
150 @NonNullByDefault
151 private static class TestLttngKernelAnalysisModule extends KernelAnalysisModule {
152
153 private final String htFileName;
154
155 /**
156 * Constructor adding the views to the analysis
157 * @param htFileName
158 * The History File Name
159 */
160 public TestLttngKernelAnalysisModule(String htFileName) {
161 super();
162 this.htFileName = htFileName;
163 }
164
165 @Override
166 public boolean setTrace(@Nullable ITmfTrace trace) throws TmfAnalysisException {
167 if (!(trace instanceof CtfTmfTrace)) {
168 return false;
169 }
170 return super.setTrace(trace);
171 }
172
173 @Override
174 protected StateSystemBackendType getBackendType() {
175 return StateSystemBackendType.FULL;
176 }
177
178 @Override
179 protected String getSsFileName() {
180 return htFileName;
181 }
182 }
183
184 private static File createStateFile(String name) {
185 File file = new File(TmfTraceManager.getSupplementaryFileDir(testTrace.getTrace()) + name);
186 if (file.exists()) {
187 file.delete();
188 }
189 return file;
190 }
191
192 }
This page took 0.035879 seconds and 5 git commands to generate.