tmf: Add test suite for pattern analysis module
authorJean-Christian Kouame <jean-christian.kouame@ericsson.com>
Tue, 10 May 2016 08:35:00 +0000 (04:35 -0400)
committerJean-Christian Kouame <jean-christian.kouame@ericsson.com>
Fri, 13 May 2016 17:01:09 +0000 (13:01 -0400)
Change-Id: I2ae1eb7276b626c0623cdb322ddd47f7efd72c75
Signed-off-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/72373
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/PatternModuleTest.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/StateProviderModuleTest.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/XmlModuleTestBase.java [new file with mode: 0644]

diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/PatternModuleTest.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/PatternModuleTest.java
new file mode 100644 (file)
index 0000000..89d0c7a
--- /dev/null
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson
+ *
+ * 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
+ *******************************************************************************/
+package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stateprovider;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
+
+/**
+ * Test the pattern analysis module
+ *
+ * @author Jean-Christian Kouame
+ */
+public class PatternModuleTest extends XmlModuleTestBase {
+
+    @Override
+    protected String getAnalysisId() {
+        return "syscall.analysis";
+    }
+
+    @Override
+    protected String getAnalysisName() {
+        return "XML system call analysis";
+    }
+
+    @Override
+    protected TmfXmlTestFiles getXmlFile() {
+        return TmfXmlTestFiles.VALID_PATTERN_FILE;
+    }
+
+    @Override
+    protected @NonNull String getAnalysisNodeName() {
+        return TmfXmlStrings.PATTERN;
+    }
+
+    @Override
+    protected @NonNull CtfTestTrace getTrace() {
+        return CtfTestTrace.ARM_64_BIT_HEADER;
+    }
+
+}
index 31ee3244ceb803a777dc00756e0c8223e91866f5..5860106408eb6ee19a1b60e0137f3fdda9f29c6a 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013, 2014 École Polytechnique de Montréal
+ * Copyright (c) 2013, 2016 É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
 
 package org.eclipse.tracecompass.tmf.analysis.xml.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 org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
-import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
-import org.junit.Test;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
 
 /**
  * Test suite for the XmlStateSystemModule Test. It tests the reading of the
@@ -37,68 +24,31 @@ import org.w3c.dom.NodeList;
  *
  * @author Geneviève Bastien
  */
-public class StateProviderModuleTest {
-
-    private static String ANALYSIS_ID = "kernel.linux.sp";
-    private static String ANALYSIS_NAME = "Xml kernel State System";
-
-    private XmlStateSystemModule fModule;
-
-    /**
-     * Test the module construction
-     */
-    @Test
-    public void testModuleConstruction() {
-
-        Document doc = TmfXmlTestFiles.VALID_FILE.getXmlDocument();
-        assertNotNull(doc);
-
-        /* get State Providers modules */
-        NodeList stateproviderNodes = doc.getElementsByTagName(TmfXmlStrings.STATE_PROVIDER);
-        assertTrue(stateproviderNodes.getLength() > 0);
-
-        Element node = (Element) stateproviderNodes.item(0);
-        fModule = new XmlStateSystemModule();
-        String moduleId = node.getAttribute(TmfXmlStrings.ID);
-        assertNotNull(moduleId);
-        fModule.setId(moduleId);
-        assertEquals(ANALYSIS_ID, fModule.getId());
-
-        fModule.setXmlFile(TmfXmlTestFiles.VALID_FILE.getPath());
+public class StateProviderModuleTest extends XmlModuleTestBase {
 
-        assertEquals(ANALYSIS_NAME, fModule.getName());
+    @Override
+    protected String getAnalysisId() {
+        return "kernel.linux.sp";
     }
 
-    /**
-     * Test the module executes correctly
-     */
-    @Test
-    public void testModuleExecution() {
-        Document doc = TmfXmlTestFiles.VALID_FILE.getXmlDocument();
-        assertNotNull(doc);
-
-        /* get State Providers modules */
-        NodeList stateproviderNodes = doc.getElementsByTagName(TmfXmlStrings.STATE_PROVIDER);
-
-        Element node = (Element) stateproviderNodes.item(0);
-        fModule = new XmlStateSystemModule();
-        String moduleId = node.getAttribute(TmfXmlStrings.ID);
-        assertNotNull(moduleId);
-        fModule.setId(moduleId);
-
-        fModule.setXmlFile(TmfXmlTestFiles.VALID_FILE.getPath());
+    @Override
+    protected String getAnalysisName() {
+        return "Xml kernel State System";
+    }
 
-        CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.KERNEL);
-        try {
-            fModule.setTrace(trace);
-            fModule.schedule();
-            assertTrue(fModule.waitForCompletion(new NullProgressMonitor()));
+    @Override
+    protected TmfXmlTestFiles getXmlFile() {
+        return TmfXmlTestFiles.VALID_FILE;
+    }
 
-        } catch (TmfAnalysisException e) {
-            fail("Cannot set trace " + e.getMessage());
-        } finally {
-            trace.dispose();
-        }
+    @Override
+    protected @NonNull String getAnalysisNodeName() {
+        return TmfXmlStrings.STATE_PROVIDER;
+    }
 
+    @Override
+    protected @NonNull CtfTestTrace getTrace() {
+        return CtfTestTrace.KERNEL;
     }
+
 }
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/XmlModuleTestBase.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/XmlModuleTestBase.java
new file mode 100644 (file)
index 0000000..8aeb911
--- /dev/null
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson
+ *
+ * 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
+ *******************************************************************************/
+package org.eclipse.tracecompass.tmf.analysis.xml.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.util.List;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternAnalysis;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
+import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
+import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * Base test for XML analysis module
+ *
+ * @author Jean-Christian Kouame
+ */
+public abstract class XmlModuleTestBase {
+
+    private TmfAbstractAnalysisModule fModule;
+
+    /**
+     * Test the module construction
+     */
+    @Test
+    public void testModuleConstruction() {
+
+        Document doc = getXmlFile().getXmlDocument();
+        assertNotNull(doc);
+
+        /* get analysis modules */
+        NodeList analysisNodes = doc.getElementsByTagName(getAnalysisNodeName());
+        assertTrue(analysisNodes.getLength() > 0);
+
+        final Element node = (Element) analysisNodes.item(0);
+        assertNotNull(node);
+
+        createModule(node);
+
+        String moduleId = node.getAttribute(TmfXmlStrings.ID);
+        assertNotNull(moduleId);
+        fModule.setId(moduleId);
+        assertEquals(getAnalysisId(), fModule.getId());
+
+        assertEquals(getAnalysisName(), fModule.getName());
+    }
+
+    private void createModule(@NonNull Element element) {
+        switch (getAnalysisNodeName()) {
+        case TmfXmlStrings.PATTERN:
+            fModule = new XmlPatternAnalysis();
+            ((XmlPatternAnalysis) fModule).setXmlFile(new Path(getXmlFile().getFile().getAbsolutePath()));
+            fModule.setName(getName(element));
+            break;
+        case TmfXmlStrings.STATE_PROVIDER:
+            fModule = new XmlStateSystemModule();
+            ((XmlStateSystemModule) fModule).setXmlFile(new Path(getXmlFile().getFile().getAbsolutePath()));
+            break;
+
+        default:
+            fail();
+        }
+    }
+
+    /**
+     * Get the analysis XML node name
+     *
+     * @return The name
+     */
+    protected abstract @NonNull String getAnalysisNodeName();
+
+    /**
+     * Get the XML file this test use
+     *
+     * @return The file
+     */
+    protected abstract TmfXmlTestFiles getXmlFile();
+
+    /**
+     * Get the analysis name
+     *
+     * @return The name
+     */
+    protected abstract String getAnalysisName();
+
+    /**
+     * Get the id of the analysis
+     *
+     * @return The id
+     */
+    protected abstract String getAnalysisId();
+
+    /**
+     * Get the trace this test use
+     *
+     * @return The trace
+     */
+    protected abstract @NonNull CtfTestTrace getTrace();
+
+    /**
+     * Get the name of the analysis
+     *
+     * @param element
+     *            The analysis element
+     * @return The name
+     */
+    public @NonNull String getName(Element element) {
+        String name = null;
+        List<Element> head = XmlUtils.getChildElements(element, TmfXmlStrings.HEAD);
+        if (head.size() == 1) {
+            List<Element> labels = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.LABEL);
+            if (!labels.isEmpty()) {
+                name = labels.get(0).getAttribute(TmfXmlStrings.VALUE);
+            }
+        }
+        assertNotNull("analysis name", name);
+        return name;
+    }
+
+    /**
+     * Test the module executes correctly
+     */
+    @Test
+    public void testModuleExecution() {
+        Document doc = getXmlFile().getXmlDocument();
+        assertNotNull(doc);
+
+        /* get State Providers modules */
+        NodeList stateproviderNodes = doc.getElementsByTagName(getAnalysisNodeName());
+
+        Element node = (Element) stateproviderNodes.item(0);
+        assertNotNull(node);
+
+        createModule(node);
+
+        String moduleId = node.getAttribute(TmfXmlStrings.ID);
+        assertNotNull(moduleId);
+        fModule.setId(moduleId);
+
+        CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(getTrace());
+        try {
+            fModule.setTrace(trace);
+            fModule.schedule();
+            assertTrue(fModule.waitForCompletion(new NullProgressMonitor()));
+
+        } catch (TmfAnalysisException e) {
+            fail("Cannot set trace " + e.getMessage());
+        } finally {
+            trace.dispose();
+        }
+
+    }
+}
This page took 0.031124 seconds and 5 git commands to generate.