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