aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathieu Rail2014-03-30 19:03:32 (EDT)
committerGenevieve Bastien2014-04-30 10:38:47 (EDT)
commit11f869fcb7e7e86b1f441513d02dad86990991b6 (patch)
treed1b298640b31bda6aa179b87d195827ab6667283
parent33fd02d5b7047bedf174413126371b124af39fe7 (diff)
downloadorg.eclipse.linuxtools-11f869fcb7e7e86b1f441513d02dad86990991b6.zip
org.eclipse.linuxtools-11f869fcb7e7e86b1f441513d02dad86990991b6.tar.gz
org.eclipse.linuxtools-11f869fcb7e7e86b1f441513d02dad86990991b6.tar.bz2
TMF: Implement analysis requirements for config element helpersrefs/changes/86/24286/4
Change-Id: I4c467ecba03c9fa5ef886cf328d60ec9249b8841 Signed-off-by: Mathieu Rail <contact@mathieurail.com> Reviewed-on: https://git.eclipse.org/r/24286 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net> Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/plugin.xml8
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisManagerTest.java2
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisModuleHelperTest.java75
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/analysis/TestRequirementAnalysis.java81
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisModuleHelperConfigElement.java32
5 files changed, 195 insertions, 3 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/plugin.xml b/lttng/org.eclipse.linuxtools.tmf.core.tests/plugin.xml
index 5859eb9..686156a 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core.tests/plugin.xml
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/plugin.xml
@@ -55,6 +55,14 @@
class="org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub">
</tracetype>
</module>
+ <module
+ analysis_module="org.eclipse.linuxtools.tmf.tests.stubs.analysis.TestRequirementAnalysis"
+ id="org.eclipse.linuxtools.tmf.core.tests.analysis.reqtest"
+ name="Test analysis requirements">
+ <tracetype
+ class="org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub">
+ </tracetype>
+ </module>
</extension>
<extension
point="org.eclipse.linuxtools.tmf.core.tracetype">
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisManagerTest.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisManagerTest.java
index 3ced4f7..da3af39 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisManagerTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisManagerTest.java
@@ -39,6 +39,8 @@ public class AnalysisManagerTest {
public static final String MODULE_PARAM_DEFAULT = "org.eclipse.linuxtools.tmf.core.tests.analysis.test2";
/** ID of analysis module for trace 2 classes only */
public static final String MODULE_SECOND = "org.eclipse.linuxtools.tmf.core.tests.analysis.testother";
+ /** Id of analysis module with requirements */
+ public static final String MODULE_REQ = "org.eclipse.linuxtools.tmf.core.tests.analysis.reqtest";
private ITmfTrace fTrace;
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisModuleHelperTest.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisModuleHelperTest.java
index 609b340..b803dd7 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisModuleHelperTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisModuleHelperTest.java
@@ -8,6 +8,7 @@
*
* Contributors:
* Geneviève Bastien - Initial API and implementation
+ * Mathieu Rail - Added tests for getting a module's requirements
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.tests.analysis;
@@ -19,18 +20,26 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
import org.eclipse.core.runtime.Platform;
import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule;
import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleHelper;
import org.eclipse.linuxtools.tmf.core.analysis.Messages;
import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisManager;
import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisModuleHelperConfigElement;
+import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType;
+import org.eclipse.linuxtools.tmf.core.project.model.TraceTypeHelper;
import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestTrace;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
import org.eclipse.linuxtools.tmf.tests.stubs.analysis.TestAnalysis;
import org.eclipse.linuxtools.tmf.tests.stubs.analysis.TestAnalysis2;
+import org.eclipse.linuxtools.tmf.tests.stubs.analysis.TestRequirementAnalysis;
import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub2;
import org.eclipse.osgi.util.NLS;
@@ -46,8 +55,11 @@ import org.osgi.framework.Bundle;
*/
public class AnalysisModuleHelperTest {
+ private static final String VALID_TRACE_TYPE = "org.eclipse.linuxtools.tmf.core.tests.tracetype";
+
private IAnalysisModuleHelper fModule;
private IAnalysisModuleHelper fModuleOther;
+ private IAnalysisModuleHelper fReqModule;
private ITmfTrace fTrace;
/**
@@ -61,6 +73,9 @@ public class AnalysisModuleHelperTest {
fModuleOther = TmfAnalysisManager.getAnalysisModule(AnalysisManagerTest.MODULE_SECOND);
assertNotNull(fModuleOther);
assertTrue(fModuleOther instanceof TmfAnalysisModuleHelperConfigElement);
+ fReqModule = TmfAnalysisManager.getAnalysisModule(AnalysisManagerTest.MODULE_REQ);
+ assertNotNull(fReqModule);
+ assertTrue(fReqModule instanceof TmfAnalysisModuleHelperConfigElement);
fTrace = TmfTestTrace.A_TEST_10K2.getTraceAsStub2();
}
@@ -95,7 +110,8 @@ public class AnalysisModuleHelperTest {
}
/**
- * Test the {@link TmfAnalysisModuleHelperConfigElement#appliesToTraceType(Class)}
+ * Test the
+ * {@link TmfAnalysisModuleHelperConfigElement#appliesToTraceType(Class)}
* method for the 2 modules
*/
@Test
@@ -112,7 +128,8 @@ public class AnalysisModuleHelperTest {
}
/**
- * Test the {@link TmfAnalysisModuleHelperConfigElement#newModule(ITmfTrace)} method
+ * Test the
+ * {@link TmfAnalysisModuleHelperConfigElement#newModule(ITmfTrace)} method
* for the 2 modules
*/
@Test
@@ -208,4 +225,58 @@ public class AnalysisModuleHelperTest {
}
assertNotNull(exception);
}
+
+ /**
+ * Test for the
+ * {@link TmfAnalysisModuleHelperConfigElement#getValidTraceTypes} method
+ */
+ @Test
+ public void testGetValidTraceTypes() {
+ TraceTypeHelper traceTypeHelper = TmfTraceType.getInstance().getTraceType(VALID_TRACE_TYPE);
+ int traceTypeCount = 0;
+ Iterable<Class<? extends ITmfTrace>> traceTypes = fReqModule.getValidTraceTypes();
+ for (Class<? extends ITmfTrace> traceType : traceTypes) {
+ assertTrue(fReqModule.appliesToTraceType(traceType));
+ assertEquals(traceTypeHelper.getTraceClass(), traceType);
+ traceTypeCount++;
+ }
+ assertEquals(1, traceTypeCount);
+ }
+
+ /**
+ * Test for the
+ * {@link TmfAnalysisModuleHelperConfigElement#getAnalysisRequirements}
+ * method
+ */
+ @Test
+ public void testGetRequirements() {
+ Iterable<TmfAnalysisRequirement> requirements = fReqModule.getAnalysisRequirements();
+ assertNotNull(requirements);
+
+ Map<String, TmfAnalysisRequirement> rMap = new HashMap<>();
+
+ for (TmfAnalysisRequirement req : requirements) {
+ assertFalse(rMap.containsKey(req.getType()));
+ rMap.put(req.getType(), req);
+ }
+ assertEquals(2, rMap.size());
+
+ /* Test if all types and values have been obtained */
+ TmfAnalysisRequirement req = rMap.get(TestRequirementAnalysis.EVENT_TYPE);
+ assertNotNull(req);
+
+ Set<String> values = req.getValues();
+ assertEquals(3, values.size());
+ assertTrue(values.contains(TestRequirementAnalysis.EXIT_SYSCALL));
+ assertTrue(values.contains(TestRequirementAnalysis.SCHED_SWITCH));
+ assertTrue(values.contains(TestRequirementAnalysis.SCHED_WAKEUP));
+
+ req = rMap.get(TestRequirementAnalysis.FIELD_TYPE);
+ assertNotNull(req);
+
+ values = req.getValues();
+ assertEquals(2, values.size());
+ assertTrue(values.contains(TestRequirementAnalysis.PID));
+ assertTrue(values.contains(TestRequirementAnalysis.TID));
+ }
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/analysis/TestRequirementAnalysis.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/analysis/TestRequirementAnalysis.java
new file mode 100644
index 0000000..08f2e68
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/analysis/TestRequirementAnalysis.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * 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:
+ * Mathieu Rail - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.tests.stubs.analysis;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.linuxtools.tmf.core.analysis.TmfAbstractAnalysisModule;
+import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement;
+import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement.ValuePriorityLevel;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
+
+/**
+ * Analysis type to test requirements acquisition
+ */
+@SuppressWarnings({ "javadoc", "nls" })
+public class TestRequirementAnalysis extends TmfAbstractAnalysisModule {
+ /* Test requirement types */
+ public static final String EVENT_TYPE = "event";
+ public static final String FIELD_TYPE = "field";
+
+ /* A few event names */
+ public static final String EXIT_SYSCALL = "exit_syscall";
+ public static final String SCHED_SWITCH = "sched_switch";
+ public static final String SCHED_WAKEUP = "sched_wakeup";
+
+ /* A few fields */
+ public static final String PID = "pid";
+ public static final String TID = "tid";
+
+ @Override
+ public boolean canExecute(ITmfTrace trace) {
+ /* This just makes sure the trace is a ctf stub trace */
+ return (TmfTraceStub.class.isAssignableFrom(trace.getClass()));
+ }
+
+ @Override
+ protected void canceling() {
+
+ }
+
+ @Override
+ protected boolean executeAnalysis(final IProgressMonitor monitor) {
+ return true;
+ }
+
+ @Override
+ public void setTrace(ITmfTrace trace) throws TmfAnalysisException {
+ }
+
+ @Override
+ public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() {
+ Map<String, TmfAnalysisRequirement> requirements = new HashMap<>();
+
+ /* Event type requirement and values */
+ requirements.put(EVENT_TYPE, new TmfAnalysisRequirement(EVENT_TYPE));
+ requirements.get(EVENT_TYPE).addValue(EXIT_SYSCALL, ValuePriorityLevel.MANDATORY);
+ requirements.get(EVENT_TYPE).addValue(SCHED_SWITCH, ValuePriorityLevel.MANDATORY);
+ requirements.get(EVENT_TYPE).addValue(SCHED_WAKEUP, ValuePriorityLevel.MANDATORY);
+
+ /* Field type requirement and values */
+ requirements.put(FIELD_TYPE, new TmfAnalysisRequirement(FIELD_TYPE));
+ requirements.get(FIELD_TYPE).addValue(PID, ValuePriorityLevel.MANDATORY);
+ requirements.get(FIELD_TYPE).addValue(TID, ValuePriorityLevel.MANDATORY);
+
+ return requirements.values();
+ }
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisModuleHelperConfigElement.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisModuleHelperConfigElement.java
index 8558cfb..cc6116f 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisModuleHelperConfigElement.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisModuleHelperConfigElement.java
@@ -8,11 +8,14 @@
*
* Contributors:
* Geneviève Bastien - Initial API and implementation
+ * Mathieu Rail - Added functionality for getting a module's requirements
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.analysis;
import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
import org.eclipse.core.runtime.ContributorFactoryOSGi;
import org.eclipse.core.runtime.CoreException;
@@ -21,6 +24,8 @@ import org.eclipse.core.runtime.InvalidRegistryObjectException;
import org.eclipse.linuxtools.internal.tmf.core.Activator;
import org.eclipse.linuxtools.internal.tmf.core.analysis.TmfAnalysisModuleSourceConfigElement;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType;
+import org.eclipse.linuxtools.tmf.core.project.model.TraceTypeHelper;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Bundle;
@@ -115,11 +120,36 @@ public class TmfAnalysisModuleHelperConfigElement implements IAnalysisModuleHelp
@Override
public Iterable<Class<? extends ITmfTrace>> getValidTraceTypes() {
- return Collections.EMPTY_SET;
+ Set<Class<? extends ITmfTrace>> traceTypes = new HashSet<>();
+
+ for (TraceTypeHelper tth : TmfTraceType.getInstance().getTraceTypeHelpers()) {
+ if (appliesToTraceType(tth.getTraceClass())) {
+ traceTypes.add(tth.getTraceClass());
+ }
+ }
+
+ return traceTypes;
}
@Override
public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() {
+ /**
+ * TODO: This method returns only the requirement of the first
+ * applicable tracetype. We may assume that requirements will be the
+ * same no matter the trace type, the trace generator will know how to
+ * handle those. But this will have to be confirmed when the situation
+ * happens.
+ */
+ for (TraceTypeHelper helper : TmfTraceType.getInstance().getTraceTypeHelpers()) {
+ if (appliesToTraceType(helper.getTraceClass())) {
+ try {
+ return newModule(helper.getTrace()).getAnalysisRequirements();
+ } catch (TmfAnalysisException e) {
+ Activator.logError("Error in get analysis requirements", e); //$NON-NLS-1$
+ }
+ }
+ }
+
return Collections.EMPTY_SET;
}