ss: Rename packages to org.eclipse.tracecompass.*
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.kernel.core.tests / src / org / eclipse / linuxtools / 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
AM
13
14package org.eclipse.linuxtools.lttng2.kernel.core.tests.stateprovider;
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;
d3ba47d4 26import org.eclipse.linuxtools.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;
33import org.eclipse.tracecompass.tmf.ctf.core.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) {
74 module.close();
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() {
bd64ee73
AM
94 try (TestLttngKernelAnalysisModule module2 =
95 new TestLttngKernelAnalysisModule(BENCHMARK_FILE_NAME);) {
96 try {
97 module2.setTrace(testTrace.getTrace());
98 } catch (TmfAnalysisException e) {
99 fail();
100 }
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());
c4d139aa 108 }
efc403bb
AM
109 }
110
f9a76cac
AM
111 /**
112 * Test re-opening the existing file.
f9a76cac 113 */
efc403bb 114 @Test
c4d139aa 115 public void testOpenExistingStateFile() {
6a769f6a 116 /* 'newStateFile' should have already been created */
bd64ee73
AM
117 try (TestLttngKernelAnalysisModule module2 = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);) {
118 try {
119 module2.setTrace(testTrace.getTrace());
120 } catch (TmfAnalysisException e) {
121 fail();
122 }
123 module2.schedule();
124 assertTrue(module2.waitForCompletion());
125 ITmfStateSystem ssb2 = module2.getStateSystem();
126
127 assertNotNull(ssb2);
128 assertEquals(startTime, ssb2.getStartTime());
129 assertEquals(endTime, ssb2.getCurrentEndTime());
6a769f6a 130 }
6a769f6a
BH
131 }
132
c1831960 133 @NonNullByDefault
6a769f6a 134 private static class TestLttngKernelAnalysisModule extends TmfStateSystemAnalysisModule {
1e4bb526 135
6a769f6a 136 private final String htFileName;
1e4bb526 137
6a769f6a
BH
138 /**
139 * Constructor adding the views to the analysis
140 * @param htFileName
141 * The History File Name
142 */
143 public TestLttngKernelAnalysisModule(String htFileName) {
144 super();
145 this.htFileName = htFileName;
146 }
147
148 @Override
c1831960 149 public void setTrace(@Nullable ITmfTrace trace) throws TmfAnalysisException {
6a769f6a
BH
150 if (!(trace instanceof CtfTmfTrace)) {
151 throw new IllegalStateException("TestLttngKernelAnalysisModule: trace should be of type CtfTmfTrace"); //$NON-NLS-1$
152 }
153 super.setTrace(trace);
154 }
155
156 @Override
157 protected ITmfStateProvider createStateProvider() {
1887c91b 158 return new LttngKernelStateProvider(getTrace());
6a769f6a
BH
159 }
160
161 @Override
162 protected StateSystemBackendType getBackendType() {
163 return StateSystemBackendType.FULL;
164 }
165
166 @Override
167 protected String getSsFileName() {
168 return htFileName;
169 }
170 }
171
172 private static File createStateFile(String name) {
173 File file = new File(TmfTraceManager.getSupplementaryFileDir(testTrace.getTrace()) + name);
174 if (file.exists()) {
175 file.delete();
176 }
177 return file;
efc403bb
AM
178 }
179
efc403bb 180}
This page took 0.059348 seconds and 5 git commands to generate.