/*******************************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 2014 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
*
* Contributors:
* Alexandre Montplaisir - Initial API and implementation
+ * Bernd Hufmann - Use state system analysis module instead of factory
******************************************************************************/
package org.eclipse.linuxtools.lttng2.kernel.core.tests.stateprovider;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
-import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.statesystem.IStateChangeInput;
-import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
-import org.eclipse.linuxtools.tmf.core.statesystem.StateSystemManager;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.LttngKernelStateProvider;
+import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
+import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
+import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
+import org.junit.After;
import org.junit.Test;
/**
*/
public class StateSystemFullHistoryTest extends StateSystemTest {
- private static File stateFile;
- private static File stateFileBenchmark;
+ private static final @NonNull String TEST_FILE_NAME = "test.ht";
+ private static final @NonNull String BENCHMARK_FILE_NAME = "test.benchmark.ht";
- /**
- * Initialize the test cases (build the history file once for all tests).
- */
- @BeforeClass
- public static void initialize() {
- try {
- stateFile = File.createTempFile("test", ".ht"); //$NON-NLS-1$ //$NON-NLS-2$
- stateFileBenchmark = File.createTempFile("test", ".ht.benchmark"); //$NON-NLS-1$ //$NON-NLS-2$
+ private File stateFile;
+ private File stateFileBenchmark;
+ private TestLttngKernelAnalysisModule module;
+
+ @Override
+ protected ITmfStateSystem initialize() {
+ stateFile = createStateFile(TEST_FILE_NAME);
+ stateFileBenchmark = createStateFile(BENCHMARK_FILE_NAME);
- input = new CtfKernelStateInput(CtfTestFiles.getTestTrace());
- ssq = StateSystemManager.loadStateHistory(stateFile, input, true);
- } catch (Exception e) {
- e.printStackTrace();
+ module = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);
+ try {
+ module.setTrace(testTrace.getTrace());
+ } catch (TmfAnalysisException e) {
+ fail();
}
+ module.schedule();
+ assertTrue(module.waitForCompletion());
+ return module.getStateSystem();
}
/**
- * Delete the temp files after we're done
+ * Clean-up
*/
- @AfterClass
- public static void cleanup() {
- boolean ret1, ret2;
- ret1 = stateFile.delete();
- ret2 = stateFileBenchmark.delete();
- if ( !(ret1 && ret2) ) {
- System.err.println("Error cleaning up during unit testing, " + //$NON-NLS-1$
- "you might have leftovers state history files in /tmp"); //$NON-NLS-1$
+ @After
+ public void cleanup() {
+ if (module != null) {
+ module.close();
+ }
+ if (stateFile != null) {
+ stateFile.delete();
+ }
+ if (stateFileBenchmark != null) {
+ stateFileBenchmark.delete();
}
}
/**
* Rebuild independently so we can benchmark it. Too bad JUnit doesn't allow
* us to @Test the @BeforeClass...
- *
- * @throws TmfTraceException
- * Fails the test
*/
@Test
- public void testBuild() throws TmfTraceException {
- IStateChangeInput input2;
- ITmfStateSystem ssb2;
-
- input2 = new CtfKernelStateInput(CtfTestFiles.getTestTrace());
- ssb2 = StateSystemManager.loadStateHistory(stateFileBenchmark, input2, true);
-
- assertEquals(CtfTestFiles.startTime, ssb2.getStartTime());
- assertEquals(CtfTestFiles.endTime, ssb2.getCurrentEndTime());
+ public void testBuild() {
+ try (TestLttngKernelAnalysisModule module2 =
+ new TestLttngKernelAnalysisModule(BENCHMARK_FILE_NAME);) {
+ try {
+ module2.setTrace(testTrace.getTrace());
+ } catch (TmfAnalysisException e) {
+ fail();
+ }
+ module2.schedule();
+ assertTrue(module2.waitForCompletion());
+ ITmfStateSystem ssb2 = module2.getStateSystem();
+
+ assertNotNull(ssb2);
+ assertEquals(startTime, ssb2.getStartTime());
+ assertEquals(endTime, ssb2.getCurrentEndTime());
+ }
}
/**
* Test re-opening the existing file.
- *
- * @throws TmfTraceException
- * Fails the test
*/
@Test
- public void testOpenExistingStateFile() throws TmfTraceException {
- ITmfStateSystem ssb2;
-
+ public void testOpenExistingStateFile() {
/* 'newStateFile' should have already been created */
- ssb2 = StateSystemManager.loadStateHistory(stateFile, null, true);
+ try (TestLttngKernelAnalysisModule module2 = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);) {
+ try {
+ module2.setTrace(testTrace.getTrace());
+ } catch (TmfAnalysisException e) {
+ fail();
+ }
+ module2.schedule();
+ assertTrue(module2.waitForCompletion());
+ ITmfStateSystem ssb2 = module2.getStateSystem();
+
+ assertNotNull(ssb2);
+ assertEquals(startTime, ssb2.getStartTime());
+ assertEquals(endTime, ssb2.getCurrentEndTime());
+ }
+ }
+
+ @NonNullByDefault
+ private static class TestLttngKernelAnalysisModule extends TmfStateSystemAnalysisModule {
- assertNotNull(ssb2);
- assertEquals(CtfTestFiles.startTime, ssb2.getStartTime());
- assertEquals(CtfTestFiles.endTime, ssb2.getCurrentEndTime());
+ private final String htFileName;
+
+ /**
+ * Constructor adding the views to the analysis
+ * @param htFileName
+ * The History File Name
+ */
+ public TestLttngKernelAnalysisModule(String htFileName) {
+ super();
+ this.htFileName = htFileName;
+ }
+
+ @Override
+ public void setTrace(@Nullable ITmfTrace trace) throws TmfAnalysisException {
+ if (!(trace instanceof CtfTmfTrace)) {
+ throw new IllegalStateException("TestLttngKernelAnalysisModule: trace should be of type CtfTmfTrace"); //$NON-NLS-1$
+ }
+ super.setTrace(trace);
+ }
+
+ @Override
+ protected ITmfStateProvider createStateProvider() {
+ return new LttngKernelStateProvider(getTrace());
+ }
+
+ @Override
+ protected StateSystemBackendType getBackendType() {
+ return StateSystemBackendType.FULL;
+ }
+
+ @Override
+ protected String getSsFileName() {
+ return htFileName;
+ }
+ }
+
+ private static File createStateFile(String name) {
+ File file = new File(TmfTraceManager.getSupplementaryFileDir(testTrace.getTrace()) + name);
+ if (file.exists()) {
+ file.delete();
+ }
+ return file;
}
}