1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
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
10 * Alexandre Montplaisir - Initial API and implementation
11 * Bernd Hufmann - Use state system analysis module instead of factory
12 ******************************************************************************/
14 package org
.eclipse
.tracecompass
.lttng2
.kernel
.core
.tests
.analysis
.kernel
.statesystem
;
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
;
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
.internal
.lttng2
.kernel
.core
.trace
.layout
.LttngEventLayout
;
28 import org
.eclipse
.tracecompass
.lttng2
.kernel
.core
.analysis
.kernel
.LttngKernelStateProvider
;
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
;
41 * State system tests using a full history back-end and the LTTng kernel state
44 * @author Alexandre Montplaisir
46 public class StateSystemFullHistoryTest
extends StateSystemTest
{
48 private static final @NonNull String TEST_FILE_NAME
= "test.ht";
49 private static final @NonNull String BENCHMARK_FILE_NAME
= "test.benchmark.ht";
51 private static File stateFile
;
52 private static File stateFileBenchmark
;
53 private static TestLttngKernelAnalysisModule module
;
59 public static void initialize() {
60 if (!testTrace
.exists()) {
61 traceIsPresent
= false;
64 traceIsPresent
= true;
66 stateFile
= createStateFile(TEST_FILE_NAME
);
67 stateFileBenchmark
= createStateFile(BENCHMARK_FILE_NAME
);
69 module
= new TestLttngKernelAnalysisModule(TEST_FILE_NAME
);
71 module
.setTrace(testTrace
.getTrace());
72 } catch (TmfAnalysisException e
) {
76 assertTrue(module
.waitForCompletion());
78 fixture
= module
.getStateSystem();
85 public static void cleanup() {
89 if (stateFile
!= null) {
92 if (stateFileBenchmark
!= null) {
93 stateFileBenchmark
.delete();
95 if (fixture
!= null) {
102 // ------------------------------------------------------------------------
103 // Tests specific to a full-history
104 // ------------------------------------------------------------------------
107 * Rebuild independently so we can benchmark it. Too bad JUnit doesn't allow
108 * us to @Test the @BeforeClass...
111 public void testBuild() {
112 TestLttngKernelAnalysisModule module2
= new TestLttngKernelAnalysisModule(BENCHMARK_FILE_NAME
);
114 module2
.setTrace(testTrace
.getTrace());
115 } catch (TmfAnalysisException e
) {
120 assertTrue(module2
.waitForCompletion());
121 ITmfStateSystem ssb2
= module2
.getStateSystem();
124 assertEquals(startTime
, ssb2
.getStartTime());
125 assertEquals(endTime
, ssb2
.getCurrentEndTime());
131 * Test re-opening the existing file.
134 public void testOpenExistingStateFile() {
135 /* 'newStateFile' should have already been created */
136 TestLttngKernelAnalysisModule module2
= new TestLttngKernelAnalysisModule(TEST_FILE_NAME
);
138 module2
.setTrace(testTrace
.getTrace());
139 } catch (TmfAnalysisException e
) {
144 assertTrue(module2
.waitForCompletion());
145 ITmfStateSystem ssb2
= module2
.getStateSystem();
148 assertEquals(startTime
, ssb2
.getStartTime());
149 assertEquals(endTime
, ssb2
.getCurrentEndTime());
155 private static class TestLttngKernelAnalysisModule
extends TmfStateSystemAnalysisModule
{
157 private final String htFileName
;
160 * Constructor adding the views to the analysis
162 * The History File Name
164 public TestLttngKernelAnalysisModule(String htFileName
) {
166 this.htFileName
= htFileName
;
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$
174 super.setTrace(trace
);
178 protected ITmfStateProvider
createStateProvider() {
179 return new LttngKernelStateProvider(checkNotNull(getTrace()), LttngEventLayout
.getInstance());
183 protected StateSystemBackendType
getBackendType() {
184 return StateSystemBackendType
.FULL
;
188 protected String
getSsFileName() {
193 private static File
createStateFile(String name
) {
194 File file
= new File(TmfTraceManager
.getSupplementaryFileDir(testTrace
.getTrace()) + name
);