1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 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
.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
.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
;
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 final @NonNull String TEST_FILE_NAME
= "test.ht";
45 private static final @NonNull String BENCHMARK_FILE_NAME
= "test.benchmark.ht";
47 private static File stateFile
;
48 private static File stateFileBenchmark
;
49 private static TestLttngKernelAnalysisModule module
;
55 public static void initialize() {
56 if (!testTrace
.exists()) {
57 traceIsPresent
= false;
60 traceIsPresent
= true;
62 stateFile
= createStateFile(TEST_FILE_NAME
);
63 stateFileBenchmark
= createStateFile(BENCHMARK_FILE_NAME
);
65 module
= new TestLttngKernelAnalysisModule(TEST_FILE_NAME
);
67 assertTrue(module
.setTrace(testTrace
.getTrace()));
68 } catch (TmfAnalysisException e
) {
72 assertTrue(module
.waitForCompletion());
74 fixture
= module
.getStateSystem();
81 public static void cleanup() {
85 if (stateFile
!= null) {
88 if (stateFileBenchmark
!= null) {
89 stateFileBenchmark
.delete();
91 if (fixture
!= null) {
98 // ------------------------------------------------------------------------
99 // Tests specific to a full-history
100 // ------------------------------------------------------------------------
103 * Rebuild independently so we can benchmark it. Too bad JUnit doesn't allow
104 * us to @Test the @BeforeClass...
107 public void testBuild() {
108 TestLttngKernelAnalysisModule module2
= new TestLttngKernelAnalysisModule(BENCHMARK_FILE_NAME
);
110 assertTrue(module2
.setTrace(testTrace
.getTrace()));
111 } catch (TmfAnalysisException e
) {
116 assertTrue(module2
.waitForCompletion());
117 ITmfStateSystem ssb2
= module2
.getStateSystem();
120 assertEquals(startTime
, ssb2
.getStartTime());
121 assertEquals(endTime
, ssb2
.getCurrentEndTime());
127 * Test re-opening the existing file.
130 public void testOpenExistingStateFile() {
131 /* 'newStateFile' should have already been created */
132 TestLttngKernelAnalysisModule module2
= new TestLttngKernelAnalysisModule(TEST_FILE_NAME
);
134 assertTrue(module2
.setTrace(testTrace
.getTrace()));
135 } catch (TmfAnalysisException e
) {
140 assertTrue(module2
.waitForCompletion());
141 ITmfStateSystem ssb2
= module2
.getStateSystem();
144 assertEquals(startTime
, ssb2
.getStartTime());
145 assertEquals(endTime
, ssb2
.getCurrentEndTime());
151 private static class TestLttngKernelAnalysisModule
extends KernelAnalysisModule
{
153 private final String htFileName
;
156 * Constructor adding the views to the analysis
158 * The History File Name
160 public TestLttngKernelAnalysisModule(String htFileName
) {
162 this.htFileName
= htFileName
;
166 public boolean setTrace(@Nullable ITmfTrace trace
) throws TmfAnalysisException
{
167 if (!(trace
instanceof CtfTmfTrace
)) {
170 return super.setTrace(trace
);
174 protected StateSystemBackendType
getBackendType() {
175 return StateSystemBackendType
.FULL
;
179 protected String
getSsFileName() {
184 private static File
createStateFile(String name
) {
185 File file
= new File(TmfTraceManager
.getSupplementaryFileDir(testTrace
.getTrace()) + name
);