tmf.ctf: Split the classes into proper packages
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.kernel.core.tests / src / org / eclipse / tracecompass / lttng2 / kernel / core / tests / stateprovider / StateSystemFullHistoryTest.java
CommitLineData
efc403bb 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2012, 2014 Ericsson
e743c3b8 3 *
efc403bb
AM
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
e743c3b8 8 *
f9a76cac
AM
9 * Contributors:
10 * Alexandre Montplaisir - Initial API and implementation
6a769f6a 11 * Bernd Hufmann - Use state system analysis module instead of factory
f9a76cac 12 ******************************************************************************/
efc403bb 13
9bc60be7 14package org.eclipse.tracecompass.lttng2.kernel.core.tests.stateprovider;
efc403bb 15
6e71ce46
AM
16import static org.junit.Assert.assertEquals;
17import static org.junit.Assert.assertNotNull;
6a769f6a 18import static org.junit.Assert.assertTrue;
c4d139aa 19import static org.junit.Assert.fail;
efc403bb
AM
20
21import java.io.File;
efc403bb 22
c1831960
AM
23import org.eclipse.jdt.annotation.NonNull;
24import org.eclipse.jdt.annotation.NonNullByDefault;
25import org.eclipse.jdt.annotation.Nullable;
9bc60be7 26import org.eclipse.tracecompass.internal.lttng2.kernel.core.stateprovider.LttngKernelStateProvider;
e894a508 27import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
2bdf0193
AM
28import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
29import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
30import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
31import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
32import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
9722e5d7 33import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
58ba027e 34import org.junit.After;
6e71ce46 35import org.junit.Test;
efc403bb
AM
36
37/**
f9a76cac
AM
38 * State system tests using a full history back-end and the LTTng kernel state
39 * input.
e743c3b8 40 *
f9a76cac 41 * @author Alexandre Montplaisir
efc403bb 42 */
f9a76cac 43public class StateSystemFullHistoryTest extends StateSystemTest {
2359ecca 44
c1831960
AM
45 private static final @NonNull String TEST_FILE_NAME = "test.ht";
46 private static final @NonNull String BENCHMARK_FILE_NAME = "test.benchmark.ht";
bd64ee73 47
58ba027e
AM
48 private File stateFile;
49 private File stateFileBenchmark;
50 private TestLttngKernelAnalysisModule module;
efc403bb 51
edbdb7ea
AM
52 @Override
53 protected ITmfStateSystem initialize() {
6a769f6a
BH
54 stateFile = createStateFile(TEST_FILE_NAME);
55 stateFileBenchmark = createStateFile(BENCHMARK_FILE_NAME);
f9a76cac 56
bd64ee73 57 module = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);
6a769f6a
BH
58 try {
59 module.setTrace(testTrace.getTrace());
60 } catch (TmfAnalysisException e) {
947504fa 61 fail();
ebd67b34 62 }
6a769f6a 63 module.schedule();
7d6122fc 64 assertTrue(module.waitForCompletion());
edbdb7ea 65 return module.getStateSystem();
efc403bb
AM
66 }
67
947504fa
AM
68 /**
69 * Clean-up
70 */
58ba027e 71 @After
edbdb7ea
AM
72 public void cleanup() {
73 if (module != null) {
03f0b0b1 74 module.dispose();
edbdb7ea
AM
75 }
76 if (stateFile != null) {
77 stateFile.delete();
78 }
79 if (stateFileBenchmark != null) {
80 stateFileBenchmark.delete();
81 }
947504fa
AM
82 }
83
f9a76cac
AM
84 // ------------------------------------------------------------------------
85 // Tests specific to a full-history
86 // ------------------------------------------------------------------------
87
efc403bb
AM
88 /**
89 * Rebuild independently so we can benchmark it. Too bad JUnit doesn't allow
90 * us to @Test the @BeforeClass...
91 */
92 @Test
c4d139aa 93 public void testBuild() {
03f0b0b1
AM
94 TestLttngKernelAnalysisModule module2 = new TestLttngKernelAnalysisModule(BENCHMARK_FILE_NAME);
95 try {
96 module2.setTrace(testTrace.getTrace());
97 } catch (TmfAnalysisException e) {
98 module2.dispose();
99 fail();
c4d139aa 100 }
03f0b0b1
AM
101 module2.schedule();
102 assertTrue(module2.waitForCompletion());
103 ITmfStateSystem ssb2 = module2.getStateSystem();
104
105 assertNotNull(ssb2);
106 assertEquals(startTime, ssb2.getStartTime());
107 assertEquals(endTime, ssb2.getCurrentEndTime());
108
109 module2.dispose();
efc403bb
AM
110 }
111
f9a76cac
AM
112 /**
113 * Test re-opening the existing file.
f9a76cac 114 */
efc403bb 115 @Test
c4d139aa 116 public void testOpenExistingStateFile() {
6a769f6a 117 /* 'newStateFile' should have already been created */
03f0b0b1
AM
118 TestLttngKernelAnalysisModule module2 = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);
119 try {
120 module2.setTrace(testTrace.getTrace());
121 } catch (TmfAnalysisException e) {
122 module2.dispose();
123 fail();
6a769f6a 124 }
03f0b0b1
AM
125 module2.schedule();
126 assertTrue(module2.waitForCompletion());
127 ITmfStateSystem ssb2 = module2.getStateSystem();
128
129 assertNotNull(ssb2);
130 assertEquals(startTime, ssb2.getStartTime());
131 assertEquals(endTime, ssb2.getCurrentEndTime());
132
133 module2.dispose();
6a769f6a
BH
134 }
135
c1831960 136 @NonNullByDefault
6a769f6a 137 private static class TestLttngKernelAnalysisModule extends TmfStateSystemAnalysisModule {
1e4bb526 138
6a769f6a 139 private final String htFileName;
1e4bb526 140
6a769f6a
BH
141 /**
142 * Constructor adding the views to the analysis
143 * @param htFileName
144 * The History File Name
145 */
146 public TestLttngKernelAnalysisModule(String htFileName) {
147 super();
148 this.htFileName = htFileName;
149 }
150
151 @Override
c1831960 152 public void setTrace(@Nullable ITmfTrace trace) throws TmfAnalysisException {
6a769f6a
BH
153 if (!(trace instanceof CtfTmfTrace)) {
154 throw new IllegalStateException("TestLttngKernelAnalysisModule: trace should be of type CtfTmfTrace"); //$NON-NLS-1$
155 }
156 super.setTrace(trace);
157 }
158
159 @Override
160 protected ITmfStateProvider createStateProvider() {
1887c91b 161 return new LttngKernelStateProvider(getTrace());
6a769f6a
BH
162 }
163
164 @Override
165 protected StateSystemBackendType getBackendType() {
166 return StateSystemBackendType.FULL;
167 }
168
169 @Override
170 protected String getSsFileName() {
171 return htFileName;
172 }
173 }
174
175 private static File createStateFile(String name) {
176 File file = new File(TmfTraceManager.getSupplementaryFileDir(testTrace.getTrace()) + name);
177 if (file.exists()) {
178 file.delete();
179 }
180 return file;
efc403bb
AM
181 }
182
efc403bb 183}
This page took 0.066109 seconds and 5 git commands to generate.