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