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