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
.linuxtools
.lttng2
.kernel
.core
.tests
.stateprovider
;
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
;
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
;
38 * State system tests using a full history back-end and the LTTng kernel state
41 * @author Alexandre Montplaisir
43 public class StateSystemFullHistoryTest
extends StateSystemTest
{
45 private static final @NonNull String TEST_FILE_NAME
= "test.ht";
46 private static final @NonNull String BENCHMARK_FILE_NAME
= "test.benchmark.ht";
48 private File stateFile
;
49 private File stateFileBenchmark
;
50 private TestLttngKernelAnalysisModule module
;
53 protected ITmfStateSystem
initialize() {
54 stateFile
= createStateFile(TEST_FILE_NAME
);
55 stateFileBenchmark
= createStateFile(BENCHMARK_FILE_NAME
);
57 module
= new TestLttngKernelAnalysisModule(TEST_FILE_NAME
);
59 module
.setTrace(testTrace
.getTrace());
60 } catch (TmfAnalysisException e
) {
64 assertTrue(module
.waitForCompletion());
65 return module
.getStateSystem();
72 public void cleanup() {
76 if (stateFile
!= null) {
79 if (stateFileBenchmark
!= null) {
80 stateFileBenchmark
.delete();
84 // ------------------------------------------------------------------------
85 // Tests specific to a full-history
86 // ------------------------------------------------------------------------
89 * Rebuild independently so we can benchmark it. Too bad JUnit doesn't allow
90 * us to @Test the @BeforeClass...
93 public void testBuild() {
94 try (TestLttngKernelAnalysisModule module2
=
95 new TestLttngKernelAnalysisModule(BENCHMARK_FILE_NAME
);) {
97 module2
.setTrace(testTrace
.getTrace());
98 } catch (TmfAnalysisException e
) {
102 assertTrue(module2
.waitForCompletion());
103 ITmfStateSystem ssb2
= module2
.getStateSystem();
106 assertEquals(startTime
, ssb2
.getStartTime());
107 assertEquals(endTime
, ssb2
.getCurrentEndTime());
112 * Test re-opening the existing file.
115 public void testOpenExistingStateFile() {
116 /* 'newStateFile' should have already been created */
117 try (TestLttngKernelAnalysisModule module2
= new TestLttngKernelAnalysisModule(TEST_FILE_NAME
);) {
119 module2
.setTrace(testTrace
.getTrace());
120 } catch (TmfAnalysisException e
) {
124 assertTrue(module2
.waitForCompletion());
125 ITmfStateSystem ssb2
= module2
.getStateSystem();
128 assertEquals(startTime
, ssb2
.getStartTime());
129 assertEquals(endTime
, ssb2
.getCurrentEndTime());
134 private static class TestLttngKernelAnalysisModule
extends TmfStateSystemAnalysisModule
{
136 private final String htFileName
;
139 * Constructor adding the views to the analysis
141 * The History File Name
143 public TestLttngKernelAnalysisModule(String htFileName
) {
145 this.htFileName
= htFileName
;
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$
153 super.setTrace(trace
);
157 protected ITmfStateProvider
createStateProvider() {
158 return new LttngKernelStateProvider(getTrace());
162 protected StateSystemBackendType
getBackendType() {
163 return StateSystemBackendType
.FULL
;
167 protected String
getSsFileName() {
172 private static File
createStateFile(String name
) {
173 File file
= new File(TmfTraceManager
.getSupplementaryFileDir(testTrace
.getTrace()) + name
);