From 6a769f6a75dfc625d21d7b56f587fde8b49dfe9c Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Mon, 16 Dec 2013 10:31:45 -0500 Subject: [PATCH] lttng: Use state system analysis module instead of factory in tests Change-Id: I2bb988f4476b71a48bedc71d8c3c4a8f87a61ea9 Signed-off-by: Bernd Hufmann Reviewed-on: https://git.eclipse.org/r/19867 Tested-by: Hudson CI Reviewed-by: Alexandre Montplaisir IP-Clean: Alexandre Montplaisir --- .../.settings/org.eclipse.jdt.core.prefs | 2 +- .../stateprovider/PartialStateSystemTest.java | 74 +++++++++-- .../StateSystemFullHistoryTest.java | 115 ++++++++++++++---- .../StateSystemInMemoryTest.java | 52 +++++++- .../tests/stateprovider/StateSystemTest.java | 2 - 5 files changed, 203 insertions(+), 42 deletions(-) diff --git a/org.eclipse.linuxtools.lttng2.kernel.core.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.lttng2.kernel.core.tests/.settings/org.eclipse.jdt.core.prefs index 8cf4cd486e..dccc332b24 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core.tests/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.linuxtools.lttng2.kernel.core.tests/.settings/org.eclipse.jdt.core.prefs @@ -4,7 +4,7 @@ org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignor org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable -org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled +org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve diff --git a/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/PartialStateSystemTest.java b/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/PartialStateSystemTest.java index e731477a5b..cb6dd02c4f 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/PartialStateSystemTest.java +++ b/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/PartialStateSystemTest.java @@ -7,20 +7,27 @@ * * 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.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; import java.io.File; -import java.io.IOException; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.LttngKernelStateProvider; +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; -import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; -import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemFactory; +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.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -33,6 +40,8 @@ import org.junit.Test; public class PartialStateSystemTest extends StateSystemTest { private static File stateFile; + private static final String TEST_FILE_NAME = "test-partial"; + /** * Initialization @@ -40,16 +49,22 @@ public class PartialStateSystemTest extends StateSystemTest { @BeforeClass public static void initialize() { assumeTrue(testTrace.exists()); - try { - stateFile = File.createTempFile("test-partial", ".ht"); + stateFile = new File(TmfTraceManager.getSupplementaryFileDir(testTrace.getTrace()) + TEST_FILE_NAME); + if (stateFile.exists()) { + stateFile.delete(); + } - input = new LttngKernelStateProvider(testTrace.getTrace()); - ssq = TmfStateSystemFactory.newPartialHistory(stateFile, input, true); - } catch (IOException e) { - fail(); - } catch (TmfTraceException e) { + TestLttngKernelAnalysisModule module = new TestLttngKernelAnalysisModule(TEST_FILE_NAME); + try { + module.setTrace(testTrace.getTrace()); + } catch (TmfAnalysisException e) { fail(); } + module.schedule(); + assertTrue(module.waitForCompletion(new NullProgressMonitor())); + ssq = module.getStateSystem(); + + assertNotNull(ssq); } /** @@ -121,4 +136,43 @@ public class PartialStateSystemTest extends StateSystemTest { public void testRangeQueryInvalidTime2() throws TimeRangeException { super.testRangeQueryInvalidTime2(); } + + private static class TestLttngKernelAnalysisModule extends TmfStateSystemAnalysisModule { + + 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(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((CtfTmfTrace) getTrace()); + } + + @Override + protected StateSystemBackendType getBackendType() { + return StateSystemBackendType.PARTIAL; + } + + @Override + protected String getSsFileName() { + return htFileName; + } + + } } diff --git a/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullHistoryTest.java b/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullHistoryTest.java index 801500d039..61058f7bba 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullHistoryTest.java +++ b/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullHistoryTest.java @@ -8,23 +8,28 @@ * * 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 static org.junit.Assume.assumeTrue; import java.io.File; -import java.io.IOException; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.LttngKernelStateProvider; -import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; +import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException; import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider; import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; -import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemFactory; +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.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -40,23 +45,29 @@ public class StateSystemFullHistoryTest extends StateSystemTest { private static File stateFile; private static File stateFileBenchmark; + private static final String TEST_FILE_NAME = "test.ht"; + private static final String BENCHMARK_FILE_NAME = "test.benchmark.ht"; + /** * Initialize the test cases (build the history file once for all tests). */ @BeforeClass public static void initialize() { assumeTrue(testTrace.exists()); - try { - stateFile = File.createTempFile("test", ".ht"); - stateFileBenchmark = File.createTempFile("test", ".ht.benchmark"); + stateFile = createStateFile(TEST_FILE_NAME); + stateFileBenchmark = createStateFile(BENCHMARK_FILE_NAME); - input = new LttngKernelStateProvider(testTrace.getTrace()); - ssq = TmfStateSystemFactory.newFullHistory(stateFile, input, true); - } catch (IOException e) { - fail(); - } catch (TmfTraceException e) { + TestLttngKernelAnalysisModule module = new TestLttngKernelAnalysisModule(TEST_FILE_NAME); + try { + module.setTrace(testTrace.getTrace()); + } catch (TmfAnalysisException e) { fail(); } + module.schedule(); + assertTrue(module.waitForCompletion(new NullProgressMonitor())); + ssq = module.getStateSystem(); + + assertNotNull(ssq); } /** @@ -78,16 +89,19 @@ public class StateSystemFullHistoryTest extends StateSystemTest { */ @Test public void testBuild() { + TestLttngKernelAnalysisModule module2 = new TestLttngKernelAnalysisModule(BENCHMARK_FILE_NAME); try { - ITmfStateProvider input2 = new LttngKernelStateProvider(testTrace.getTrace()); - ITmfStateSystem ssb2 = TmfStateSystemFactory.newFullHistory(stateFileBenchmark, input2, true); - - assertEquals(startTime, ssb2.getStartTime()); - assertEquals(endTime, ssb2.getCurrentEndTime()); - - } catch (TmfTraceException e) { + module2.setTrace(testTrace.getTrace()); + } catch (TmfAnalysisException e) { fail(); } + module2.schedule(); + assertTrue(module2.waitForCompletion(new NullProgressMonitor())); + ITmfStateSystem ssb2 = module2.getStateSystem(); + + assertNotNull(ssb2); + assertEquals(startTime, ssb2.getStartTime()); + assertEquals(endTime, ssb2.getCurrentEndTime()); } /** @@ -95,17 +109,66 @@ public class StateSystemFullHistoryTest extends StateSystemTest { */ @Test public void testOpenExistingStateFile() { + /* 'newStateFile' should have already been created */ + TestLttngKernelAnalysisModule module2 = new TestLttngKernelAnalysisModule(TEST_FILE_NAME); try { - /* 'newStateFile' should have already been created */ - ITmfStateSystem ssb2 = TmfStateSystemFactory.newFullHistory(stateFile, null, true); + module2.setTrace(testTrace.getTrace()); + } catch (TmfAnalysisException e) { + fail(); + } + module2.schedule(); + assertTrue(module2.waitForCompletion(new NullProgressMonitor())); + ITmfStateSystem ssb2 = module2.getStateSystem(); + + assertNotNull(ssb2); + assertEquals(startTime, ssb2.getStartTime()); + assertEquals(endTime, ssb2.getCurrentEndTime()); + } + + private static class TestLttngKernelAnalysisModule extends TmfStateSystemAnalysisModule { - assertNotNull(ssb2); - assertEquals(startTime, ssb2.getStartTime()); - assertEquals(endTime, ssb2.getCurrentEndTime()); + private final String htFileName; - } catch (TmfTraceException e) { - fail(); - } + /** + * 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(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((CtfTmfTrace) 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; } } diff --git a/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemInMemoryTest.java b/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemInMemoryTest.java index b4bff2f31d..6de147ced8 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemInMemoryTest.java +++ b/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemInMemoryTest.java @@ -8,14 +8,23 @@ * * 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.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.LttngKernelStateProvider; -import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemFactory; +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; +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.junit.BeforeClass; /** @@ -31,7 +40,44 @@ public class StateSystemInMemoryTest extends StateSystemTest { @BeforeClass public static void initialize() { assumeTrue(testTrace.exists()); - input = new LttngKernelStateProvider(testTrace.getTrace()); - ssq = TmfStateSystemFactory.newInMemHistory(input, true); + + TestLttngKernelAnalysisModule module = new TestLttngKernelAnalysisModule(); + try { + module.setTrace(testTrace.getTrace()); + } catch (TmfAnalysisException e) { + fail(); + } + module.schedule(); + assertTrue(module.waitForCompletion(new NullProgressMonitor())); + ssq = module.getStateSystem(); + assertNotNull(ssq); + } + + private static class TestLttngKernelAnalysisModule extends TmfStateSystemAnalysisModule { + + /** + * Constructor adding the views to the analysis + */ + public TestLttngKernelAnalysisModule() { + super(); + } + + @Override + public void setTrace(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((CtfTmfTrace) getTrace()); + } + + @Override + protected StateSystemBackendType getBackendType() { + return StateSystemBackendType.FULL; + } } } diff --git a/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemTest.java b/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemTest.java index a55729bceb..a9fb2ebf91 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemTest.java +++ b/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemTest.java @@ -24,7 +24,6 @@ import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException; import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; -import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider; import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue; import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace; @@ -51,7 +50,6 @@ public abstract class StateSystemTest { /** Number of nanoseconds in one second */ private static final long NANOSECS_PER_SEC = 1000000000L; - protected static ITmfStateProvider input; protected static ITmfStateSystem ssq; /* Offset in the trace + start time of the trace */ -- 2.34.1