os.linux: Rename the "kernelanalysis" package to just "kernel"
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core.tests / src / org / eclipse / tracecompass / lttng2 / kernel / core / tests / analysis / kernel / statesystem / StateSystemFullHistoryTest.java
CommitLineData
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 14package org.eclipse.tracecompass.lttng2.kernel.core.tests.analysis.kernel.statesystem;
efc403bb 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;
0f7a12d3 26import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule;
e894a508 27import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
2bdf0193 28import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
2bdf0193
AM
29import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
30import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
c4d57ac1 31import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
9722e5d7 32import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
392bf486
AM
33import org.junit.AfterClass;
34import org.junit.BeforeClass;
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
c4d57ac1 48 private static CtfTmfTrace trace;
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() {
c4d57ac1 58 trace = CtfTmfTestTraceUtils.getTrace(testTrace);
efc403bb 59
6a769f6a
BH
60 stateFile = createStateFile(TEST_FILE_NAME);
61 stateFileBenchmark = createStateFile(BENCHMARK_FILE_NAME);
f9a76cac 62
bd64ee73 63 module = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);
6a769f6a 64 try {
c4d57ac1 65 assertTrue(module.setTrace(trace));
6a769f6a 66 } catch (TmfAnalysisException e) {
947504fa 67 fail();
ebd67b34 68 }
6a769f6a 69 module.schedule();
7d6122fc 70 assertTrue(module.waitForCompletion());
392bf486
AM
71
72 fixture = module.getStateSystem();
efc403bb
AM
73 }
74
947504fa
AM
75 /**
76 * Clean-up
77 */
392bf486
AM
78 @AfterClass
79 public static void cleanup() {
edbdb7ea 80 if (module != null) {
03f0b0b1 81 module.dispose();
edbdb7ea
AM
82 }
83 if (stateFile != null) {
84 stateFile.delete();
85 }
86 if (stateFileBenchmark != null) {
87 stateFileBenchmark.delete();
88 }
392bf486
AM
89 if (fixture != null) {
90 fixture.dispose();
91 }
c4d57ac1
AM
92 if (trace != null) {
93 trace.dispose();
94 }
392bf486
AM
95 module = null;
96 fixture = null;
c4d57ac1 97 trace = 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 {
c4d57ac1 112 assertTrue(module2.setTrace(trace));
03f0b0b1
AM
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 {
c4d57ac1 136 assertTrue(module2.setTrace(trace));
03f0b0b1
AM
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
6d16f5a9 153 private static class TestLttngKernelAnalysisModule extends KernelAnalysisModule {
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
f479550c 168 public boolean setTrace(@Nullable ITmfTrace trace) throws TmfAnalysisException {
6a769f6a 169 if (!(trace instanceof CtfTmfTrace)) {
f479550c 170 return false;
6a769f6a 171 }
f479550c 172 return super.setTrace(trace);
6a769f6a
BH
173 }
174
6a769f6a
BH
175 @Override
176 protected StateSystemBackendType getBackendType() {
177 return StateSystemBackendType.FULL;
178 }
179
180 @Override
181 protected String getSsFileName() {
182 return htFileName;
183 }
184 }
185
186 private static File createStateFile(String name) {
c4d57ac1 187 File file = new File(TmfTraceManager.getSupplementaryFileDir(trace) + name);
6a769f6a
BH
188 if (file.exists()) {
189 file.delete();
190 }
191 return file;
efc403bb
AM
192 }
193
efc403bb 194}
This page took 0.091008 seconds and 5 git commands to generate.