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 AM |
13 | |
14 | package org.eclipse.linuxtools.lttng2.kernel.core.tests.stateprovider; | |
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; |
92ba8466 | 20 | import static org.junit.Assume.assumeTrue; |
efc403bb AM |
21 | |
22 | import java.io.File; | |
efc403bb | 23 | |
d3ba47d4 | 24 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.LttngKernelStateProvider; |
bcec0116 | 25 | import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem; |
6a769f6a | 26 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException; |
0fe46f2a | 27 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider; |
6a769f6a BH |
28 | import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule; |
29 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
30 | import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; | |
91e7f946 | 31 | import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace; |
947504fa | 32 | import org.junit.AfterClass; |
6e71ce46 AM |
33 | import org.junit.BeforeClass; |
34 | import org.junit.Test; | |
efc403bb AM |
35 | |
36 | /** | |
f9a76cac AM |
37 | * State system tests using a full history back-end and the LTTng kernel state |
38 | * input. | |
e743c3b8 | 39 | * |
f9a76cac | 40 | * @author Alexandre Montplaisir |
efc403bb | 41 | */ |
f9a76cac | 42 | public class StateSystemFullHistoryTest extends StateSystemTest { |
2359ecca | 43 | |
bd64ee73 AM |
44 | private static final String TEST_FILE_NAME = "test.ht"; |
45 | private static final String BENCHMARK_FILE_NAME = "test.benchmark.ht"; | |
46 | ||
f9a76cac AM |
47 | private static File stateFile; |
48 | private static File stateFileBenchmark; | |
bd64ee73 | 49 | private static TestLttngKernelAnalysisModule module; |
efc403bb | 50 | |
6a769f6a | 51 | |
f9a76cac AM |
52 | /** |
53 | * Initialize the test cases (build the history file once for all tests). | |
54 | */ | |
efc403bb AM |
55 | @BeforeClass |
56 | public static void initialize() { | |
9ac63b5b | 57 | assumeTrue(testTrace.exists()); |
6a769f6a BH |
58 | stateFile = createStateFile(TEST_FILE_NAME); |
59 | stateFileBenchmark = createStateFile(BENCHMARK_FILE_NAME); | |
f9a76cac | 60 | |
bd64ee73 | 61 | module = new TestLttngKernelAnalysisModule(TEST_FILE_NAME); |
6a769f6a BH |
62 | try { |
63 | module.setTrace(testTrace.getTrace()); | |
64 | } catch (TmfAnalysisException e) { | |
947504fa | 65 | fail(); |
ebd67b34 | 66 | } |
6a769f6a | 67 | module.schedule(); |
7d6122fc | 68 | assertTrue(module.waitForCompletion()); |
6a769f6a BH |
69 | ssq = module.getStateSystem(); |
70 | ||
71 | assertNotNull(ssq); | |
efc403bb AM |
72 | } |
73 | ||
947504fa AM |
74 | /** |
75 | * Clean-up | |
76 | */ | |
77 | @AfterClass | |
78 | public static void tearDownClass() { | |
bd64ee73 | 79 | module.close(); |
947504fa AM |
80 | stateFile.delete(); |
81 | stateFileBenchmark.delete(); | |
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 | ||
133 | private static class TestLttngKernelAnalysisModule extends TmfStateSystemAnalysisModule { | |
1e4bb526 | 134 | |
6a769f6a | 135 | private final String htFileName; |
1e4bb526 | 136 | |
6a769f6a BH |
137 | /** |
138 | * Constructor adding the views to the analysis | |
139 | * @param htFileName | |
140 | * The History File Name | |
141 | */ | |
142 | public TestLttngKernelAnalysisModule(String htFileName) { | |
143 | super(); | |
144 | this.htFileName = htFileName; | |
145 | } | |
146 | ||
147 | @Override | |
148 | public void setTrace(ITmfTrace trace) throws TmfAnalysisException { | |
149 | if (!(trace instanceof CtfTmfTrace)) { | |
150 | throw new IllegalStateException("TestLttngKernelAnalysisModule: trace should be of type CtfTmfTrace"); //$NON-NLS-1$ | |
151 | } | |
152 | super.setTrace(trace); | |
153 | } | |
154 | ||
155 | @Override | |
156 | protected ITmfStateProvider createStateProvider() { | |
1887c91b | 157 | return new LttngKernelStateProvider(getTrace()); |
6a769f6a BH |
158 | } |
159 | ||
160 | @Override | |
161 | protected StateSystemBackendType getBackendType() { | |
162 | return StateSystemBackendType.FULL; | |
163 | } | |
164 | ||
165 | @Override | |
166 | protected String getSsFileName() { | |
167 | return htFileName; | |
168 | } | |
169 | } | |
170 | ||
171 | private static File createStateFile(String name) { | |
172 | File file = new File(TmfTraceManager.getSupplementaryFileDir(testTrace.getTrace()) + name); | |
173 | if (file.exists()) { | |
174 | file.delete(); | |
175 | } | |
176 | return file; | |
efc403bb AM |
177 | } |
178 | ||
efc403bb | 179 | } |