1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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
;
20 import static org
.junit
.Assume
.assumeTrue
;
24 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.core
.stateprovider
.LttngKernelStateProvider
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfAnalysisException
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateProvider
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystem
;
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
.junit
.AfterClass
;
34 import org
.junit
.BeforeClass
;
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 File stateFile
;
46 private static File stateFileBenchmark
;
48 private static final String TEST_FILE_NAME
= "test.ht";
49 private static final String BENCHMARK_FILE_NAME
= "test.benchmark.ht";
52 * Initialize the test cases (build the history file once for all tests).
55 public static void initialize() {
56 assumeTrue(testTrace
.exists());
57 stateFile
= createStateFile(TEST_FILE_NAME
);
58 stateFileBenchmark
= createStateFile(BENCHMARK_FILE_NAME
);
60 TestLttngKernelAnalysisModule module
= new TestLttngKernelAnalysisModule(TEST_FILE_NAME
);
62 module
.setTrace(testTrace
.getTrace());
63 } catch (TmfAnalysisException e
) {
67 assertTrue(module
.waitForCompletion(new NullProgressMonitor()));
68 ssq
= module
.getStateSystem();
77 public static void tearDownClass() {
79 stateFileBenchmark
.delete();
82 // ------------------------------------------------------------------------
83 // Tests specific to a full-history
84 // ------------------------------------------------------------------------
87 * Rebuild independently so we can benchmark it. Too bad JUnit doesn't allow
88 * us to @Test the @BeforeClass...
91 public void testBuild() {
92 TestLttngKernelAnalysisModule module2
= new TestLttngKernelAnalysisModule(BENCHMARK_FILE_NAME
);
94 module2
.setTrace(testTrace
.getTrace());
95 } catch (TmfAnalysisException e
) {
99 assertTrue(module2
.waitForCompletion(new NullProgressMonitor()));
100 ITmfStateSystem ssb2
= module2
.getStateSystem();
103 assertEquals(startTime
, ssb2
.getStartTime());
104 assertEquals(endTime
, ssb2
.getCurrentEndTime());
108 * Test re-opening the existing file.
111 public void testOpenExistingStateFile() {
112 /* 'newStateFile' should have already been created */
113 TestLttngKernelAnalysisModule module2
= new TestLttngKernelAnalysisModule(TEST_FILE_NAME
);
115 module2
.setTrace(testTrace
.getTrace());
116 } catch (TmfAnalysisException e
) {
120 assertTrue(module2
.waitForCompletion(new NullProgressMonitor()));
121 ITmfStateSystem ssb2
= module2
.getStateSystem();
124 assertEquals(startTime
, ssb2
.getStartTime());
125 assertEquals(endTime
, ssb2
.getCurrentEndTime());
128 private static class TestLttngKernelAnalysisModule
extends TmfStateSystemAnalysisModule
{
130 private final String htFileName
;
133 * Constructor adding the views to the analysis
135 * The History File Name
137 public TestLttngKernelAnalysisModule(String htFileName
) {
139 this.htFileName
= htFileName
;
143 public void setTrace(ITmfTrace trace
) throws TmfAnalysisException
{
144 if (!(trace
instanceof CtfTmfTrace
)) {
145 throw new IllegalStateException("TestLttngKernelAnalysisModule: trace should be of type CtfTmfTrace"); //$NON-NLS-1$
147 super.setTrace(trace
);
151 protected ITmfStateProvider
createStateProvider() {
152 return new LttngKernelStateProvider((CtfTmfTrace
) getTrace());
156 protected StateSystemBackendType
getBackendType() {
157 return StateSystemBackendType
.FULL
;
161 protected String
getSsFileName() {
166 private static File
createStateFile(String name
) {
167 File file
= new File(TmfTraceManager
.getSupplementaryFileDir(testTrace
.getTrace()) + name
);