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