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