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
;
20 import static org
.junit
.Assume
.assumeTrue
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.core
.stateprovider
.LttngKernelStateProvider
;
25 import org
.eclipse
.linuxtools
.statesystem
.core
.ITmfStateSystem
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfAnalysisException
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateProvider
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTraceManager
;
31 import org
.eclipse
.linuxtools
.tmf
.ctf
.core
.CtfTmfTrace
;
32 import org
.junit
.AfterClass
;
33 import org
.junit
.BeforeClass
;
34 import org
.junit
.Test
;
37 * State system tests using a full history back-end and the LTTng kernel state
40 * @author Alexandre Montplaisir
42 public class StateSystemFullHistoryTest
extends StateSystemTest
{
44 private static File stateFile
;
45 private static File stateFileBenchmark
;
47 private static final String TEST_FILE_NAME
= "test.ht";
48 private static final String BENCHMARK_FILE_NAME
= "test.benchmark.ht";
51 * Initialize the test cases (build the history file once for all tests).
54 public static void initialize() {
55 assumeTrue(testTrace
.exists());
56 stateFile
= createStateFile(TEST_FILE_NAME
);
57 stateFileBenchmark
= createStateFile(BENCHMARK_FILE_NAME
);
59 TestLttngKernelAnalysisModule module
= new TestLttngKernelAnalysisModule(TEST_FILE_NAME
);
61 module
.setTrace(testTrace
.getTrace());
62 } catch (TmfAnalysisException e
) {
66 assertTrue(module
.waitForCompletion());
67 ssq
= module
.getStateSystem();
76 public static void tearDownClass() {
78 stateFileBenchmark
.delete();
81 // ------------------------------------------------------------------------
82 // Tests specific to a full-history
83 // ------------------------------------------------------------------------
86 * Rebuild independently so we can benchmark it. Too bad JUnit doesn't allow
87 * us to @Test the @BeforeClass...
90 public void testBuild() {
91 TestLttngKernelAnalysisModule module2
= new TestLttngKernelAnalysisModule(BENCHMARK_FILE_NAME
);
93 module2
.setTrace(testTrace
.getTrace());
94 } catch (TmfAnalysisException e
) {
98 assertTrue(module2
.waitForCompletion());
99 ITmfStateSystem ssb2
= module2
.getStateSystem();
102 assertEquals(startTime
, ssb2
.getStartTime());
103 assertEquals(endTime
, ssb2
.getCurrentEndTime());
107 * Test re-opening the existing file.
110 public void testOpenExistingStateFile() {
111 /* 'newStateFile' should have already been created */
112 TestLttngKernelAnalysisModule module2
= new TestLttngKernelAnalysisModule(TEST_FILE_NAME
);
114 module2
.setTrace(testTrace
.getTrace());
115 } catch (TmfAnalysisException e
) {
119 assertTrue(module2
.waitForCompletion());
120 ITmfStateSystem ssb2
= module2
.getStateSystem();
123 assertEquals(startTime
, ssb2
.getStartTime());
124 assertEquals(endTime
, ssb2
.getCurrentEndTime());
127 private static class TestLttngKernelAnalysisModule
extends TmfStateSystemAnalysisModule
{
129 private final String htFileName
;
132 * Constructor adding the views to the analysis
134 * The History File Name
136 public TestLttngKernelAnalysisModule(String htFileName
) {
138 this.htFileName
= htFileName
;
142 public void setTrace(ITmfTrace trace
) throws TmfAnalysisException
{
143 if (!(trace
instanceof CtfTmfTrace
)) {
144 throw new IllegalStateException("TestLttngKernelAnalysisModule: trace should be of type CtfTmfTrace"); //$NON-NLS-1$
146 super.setTrace(trace
);
150 protected ITmfStateProvider
createStateProvider() {
151 return new LttngKernelStateProvider((CtfTmfTrace
) getTrace());
155 protected StateSystemBackendType
getBackendType() {
156 return StateSystemBackendType
.FULL
;
160 protected String
getSsFileName() {
165 private static File
createStateFile(String name
) {
166 File file
= new File(TmfTraceManager
.getSupplementaryFileDir(testTrace
.getTrace()) + name
);