TMF: Allow state systems to be built for experiments
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Fri, 11 Apr 2014 02:39:00 +0000 (22:39 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Wed, 18 Jun 2014 13:30:29 +0000 (09:30 -0400)
Add the support of experiments to the state system build requests

Change-Id: I03b59eade2a9d719bff29359f777b8a21bacf979
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/24879
Tested-by: Hudson CI
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/AllTests.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/ExperimentStateSystemModuleTest.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/analysis/TestExperimentAnalysis.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemAnalysisModule.java

index e46f7fe81aa8dbd555a216694415d28dfd2a6a8c..b51108aa40287482cfa8ba1bb3fcc3307f6bd5ca 100644 (file)
@@ -20,6 +20,7 @@ import org.junit.runners.Suite;
  */
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
+    ExperimentStateSystemModuleTest.class,
     StateSystemAnalysisModuleTest.class
 })
 public class AllTests {
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/ExperimentStateSystemModuleTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/ExperimentStateSystemModuleTest.java
new file mode 100644 (file)
index 0000000..93fbf0b
--- /dev/null
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.statesystem;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem;
+import org.eclipse.linuxtools.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.linuxtools.statesystem.core.exceptions.StateSystemDisposedException;
+import org.eclipse.linuxtools.statesystem.core.interval.ITmfStateInterval;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
+import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
+import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestTrace;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
+import org.eclipse.linuxtools.tmf.tests.stubs.analysis.TestExperimentAnalysis;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestRule;
+import org.junit.rules.Timeout;
+
+/**
+ * Test the {@link TmfStateSystemAnalysisModule} class for an experiment
+ *
+ * @author Geneviève Bastien
+ */
+public class ExperimentStateSystemModuleTest {
+
+    /** Time-out tests after some time */
+    @Rule
+    public TestRule globalTimeout = new Timeout(60000);
+
+    /** ID of the test state system analysis module */
+    public static final String MODULE_SS = "org.eclipse.linuxtools.tmf.core.tests.experiment";
+
+    private TmfStateSystemAnalysisModule fModule;
+    private TmfExperiment fExperiment;
+
+    /**
+     * Setup test trace
+     */
+    @Before
+    public void setupTraces() {
+        ITmfTrace trace = TmfTestTrace.A_TEST_10K.getTrace();
+        TmfSignalManager.deregister(trace);
+        ITmfTrace trace2 = TmfTestTrace.A_TEST_10K2.getTrace();
+        TmfSignalManager.deregister(trace2);
+        ITmfTrace[] traces = { trace, trace2 };
+        fExperiment = new TmfExperimentStub("Test", traces, 1000);
+        fExperiment.traceOpened(new TmfTraceOpenedSignal(this, fExperiment, null));
+
+        fModule = (TmfStateSystemAnalysisModule) fExperiment.getAnalysisModule(MODULE_SS);
+        assertNotNull(fModule);
+    }
+
+    /**
+     * Some tests use traces, let's clean them here
+     */
+    @After
+    public void cleanupTraces() {
+        fExperiment.dispose();
+    }
+
+    /**
+     * Test the state system module execution and result
+     */
+    @Test
+    public void testSsModule() {
+        ITmfStateSystem ss = fModule.getStateSystem();
+        assertNull(ss);
+        fModule.schedule();
+        if (fModule.waitForCompletion()) {
+            ss = fModule.getStateSystem();
+            assertNotNull(ss);
+            try {
+                int quark = ss.getQuarkAbsolute(TestExperimentAnalysis.TRACE_QUARK_NAME);
+                ITmfStateInterval interval = ss.querySingleState(ss.getCurrentEndTime(), quark);
+                assertEquals(2, interval.getStateValue().unboxInt());
+            } catch (AttributeNotFoundException e) {
+                fail("The quark for number of traces does not exist");
+            } catch (StateSystemDisposedException e) {
+                fail("Error: state system disposed");
+            }
+        } else {
+            fail("Module did not complete properly");
+        }
+    }
+
+    /**
+     * Make sure that the state system is initialized after calling 
+     * {@link TmfStateSystemAnalysisModule#waitForInitialization()}.
+     */
+    @Test
+    public void testInitialization() {
+        assertNull(fModule.getStateSystem());
+        fModule.schedule();
+
+        fModule.waitForInitialization();
+        assertNotNull(fModule.getStateSystem());
+    }
+
+}
index 7d00a835dc857b26de8839d87f67cf4f21239415..dad0024376c03d3c4f60598a91830b86d0c9838c 100644 (file)
 
 package org.eclipse.linuxtools.tmf.tests.stubs.analysis;
 
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.linuxtools.tmf.core.analysis.TmfAbstractAnalysisModule;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.linuxtools.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.linuxtools.statesystem.core.exceptions.StateValueTypeException;
+import org.eclipse.linuxtools.statesystem.core.exceptions.TimeRangeException;
+import org.eclipse.linuxtools.statesystem.core.statevalue.TmfStateValue;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
+import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 
 /**
- * Stubs for experiment analysis
+ * Stubs for experiment analysis. This analysis is a state system analysis that
+ * simply counts the number of traces for which events were received. The number
+ * of traces is the value of attribute
+ * {@link TestExperimentAnalysis#TRACE_QUARK_NAME}.
  *
  * @author Geneviève Bastien
  */
-public class TestExperimentAnalysis extends TmfAbstractAnalysisModule {
+public class TestExperimentAnalysis extends TmfStateSystemAnalysisModule {
+
+    /**
+     * The quark counting the number of traces
+     */
+    public static final String TRACE_QUARK_NAME = "Traces";
 
     @Override
-    protected boolean executeAnalysis(IProgressMonitor monitor) throws TmfAnalysisException {
-        return false;
+    protected ITmfStateProvider createStateProvider() {
+        return new TestExpStateSystemProvider(getTrace());
     }
 
     @Override
-    protected void canceling() {
-
+    protected StateSystemBackendType getBackendType() {
+        return StateSystemBackendType.INMEM;
     }
 
+    private class TestExpStateSystemProvider extends AbstractTmfStateProvider {
+
+        private static final int VERSION = 1;
+        private final Set<ITmfTrace> fTraces = new HashSet<>();
+        private int fCount = 0;
+
+        /**
+         * Constructor
+         *
+         * @param trace
+         *            The LTTng 2.0 kernel trace directory
+         */
+        public TestExpStateSystemProvider(ITmfTrace trace) {
+            super(trace, TmfEvent.class, "Stub State System for Experiment");
+        }
+
+        @Override
+        public int getVersion() {
+            return VERSION;
+        }
+
+        @Override
+        public ITmfStateProvider getNewInstance() {
+            return new TestExpStateSystemProvider(this.getTrace());
+        }
+
+        @Override
+        protected void eventHandle(ITmfEvent event) {
+            if (!fTraces.contains(event.getTrace())) {
+                try {
+                    int quarkId = ss.getQuarkAbsoluteAndAdd(TRACE_QUARK_NAME);
+                    ss.modifyAttribute(event.getTimestamp().getValue(), TmfStateValue.newValueInt(++fCount), quarkId);
+                    fTraces.add(event.getTrace());
+                } catch (TimeRangeException | AttributeNotFoundException | StateValueTypeException e) {
+
+                }
+            }
+        }
+    }
 }
index 1259601a48dc6199c5c516c11e6d85fec80327e5..516fb134b139bb5bda01d6bd59cdce2050efa7df 100644 (file)
@@ -40,6 +40,7 @@ import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
 import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
 import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
 
 /**
@@ -406,8 +407,8 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
             // sci.getTrace() will eventually return a @NonNull
             @SuppressWarnings("null")
             @NonNull ITmfTrace tr = sci.getTrace();
+            trace = tr;
 
-            this.trace = tr;
         }
 
         @Override
@@ -415,6 +416,16 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
             super.handleData(event);
             if (event.getTrace() == trace) {
                 sci.processEvent(event);
+            } else if (trace instanceof TmfExperiment) {
+                /*
+                 * If the request is for an experiment, check if the event is
+                 * from one of the child trace
+                 */
+                for (ITmfTrace childTrace : ((TmfExperiment) trace).getTraces()) {
+                    if (childTrace == event.getTrace()) {
+                        sci.processEvent(event);
+                    }
+                }
             }
         }
 
This page took 0.040374 seconds and 5 git commands to generate.