tmf : Add test suite for the pattern segment builder
authorJean-Christian Kouame <jean-christian.kouame@ericsson.com>
Wed, 16 Dec 2015 21:19:20 +0000 (16:19 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 17 Feb 2016 15:38:17 +0000 (10:38 -0500)
Change-Id: I2ff10d945ce398c943d25a795925a4fc37b0f7b5
Signed-off-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/62874
Reviewed-by: Hudson CI
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/.classpath
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/META-INF/MANIFEST.MF
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/build.properties
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/common/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/common/TmfXmlTestFiles.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/module/XmlUtilsTest.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/TmfXmlPatternSegmentBuilderTest.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/stubs/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stubs/PatternSegmentFactoryStub.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/stubs/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stubs/StateSystemContainerStub.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_xml_files/test_valid/test_pattern_segment.xml [new file with mode: 0644]

index 44d08d17ee60085daee841babaa443392078c8f9..1861ed9c8154a3f98600bdf2bc3cbabe02da70ee 100644 (file)
@@ -12,5 +12,6 @@
        </classpathentry>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="src" path="common"/>
+       <classpathentry kind="src" path="stubs"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
index 758960e7e3ea34a136139dfd48307c9d8bc1c258..33fa99c19721d7d5c61246c0b87e36766a94fd2f 100644 (file)
@@ -13,7 +13,8 @@ Require-Bundle: org.junit,
  org.eclipse.tracecompass.tmf.core.tests,
  org.eclipse.tracecompass.tmf.ctf.core,
  org.eclipse.tracecompass.tmf.ctf.core.tests,
- org.eclipse.tracecompass.statesystem.core
+ org.eclipse.tracecompass.statesystem.core,
+ org.eclipse.tracecompass.segmentstore.core
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-ActivationPolicy: lazy
 Import-Package: com.google.common.collect;version="10.0.1",
index 02557ecde05192df0d21ca4ac28aeb930b8ef5a0..84e7c9cde0aee807c935d1a0869eb258daf32f39 100644 (file)
@@ -10,7 +10,8 @@
 #    Ericsson - Initial API and implementation
 ###############################################################################
 source.. = src/,\
-           common/
+           common/,\
+           stubs/
 output.. = bin/
 bin.includes = META-INF/,\
                .,\
index 810f6def56dfcb657ced98eaec273542a5227057..5aa363d10fa79de3aa3332e9083873adef15a5a0 100644 (file)
@@ -42,7 +42,9 @@ public enum TmfXmlTestFiles {
     /** A valid file for conditions tests */
     CONDITION_FILE("test_xml_files/test_valid/test_conditions.xml"),
     /** A valid file for pattern tests */
-    VALID_PATTERN_FILE("test_xml_files/test_valid/test_valid_pattern.xml");
+    VALID_PATTERN_FILE("test_xml_files/test_valid/test_valid_pattern.xml"),
+    /** A valid pattern file to test the pattern segment **/
+    VALID_PATTERN_SEGMENT("test_xml_files/test_valid/test_pattern_segment.xml");
 
     private final String fPath;
 
index 851674af913c090829ea6a2ceb02aa2799c4f6da..ffbbe7cd190dac3995045d197fb3fdedd0ab3a02 100644 (file)
@@ -19,7 +19,9 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.File;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import org.eclipse.core.resources.IWorkspace;
 import org.eclipse.core.resources.ResourcesPlugin;
@@ -34,6 +36,7 @@ import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedE
 import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.segment.TmfXmlPatternSegment;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.Activator;
@@ -290,4 +293,30 @@ public class XmlUtilsTest {
         }
     }
 
+    /**
+     * Test a pattern segment against what is expected
+     *
+     * @param expected
+     *            The expected pattern segment
+     * @param actual
+     *            The actual pattern segment
+     */
+    public static void testPatternSegmentData(TmfXmlPatternSegment expected, TmfXmlPatternSegment actual) {
+        assertEquals("getStart", expected.getStart(), actual.getStart());
+        assertEquals("getEnd", expected.getEnd(), actual.getEnd());
+        assertEquals("getScale", expected.getScale(), actual.getScale());
+        assertEquals("getName", expected.getName(), actual.getName());
+        assertNotNull("getContent", actual.getContent());
+
+        // Test the content of the pattern segment
+        assertEquals("content size", expected.getContent().size(), actual.getContent().size());
+        Iterator<Map.Entry<String, @NonNull ITmfStateValue>> it2 = expected.getContent().entrySet().iterator();
+        for (int i = 0; i < expected.getContent().size(); i++) {
+            Map.Entry<String, @NonNull ITmfStateValue> expectedContent = it2.next();
+            ITmfStateValue actualValue = actual.getContent().get(expectedContent.getKey());
+            assertNotNull("Content " + expectedContent.getKey() + " exists", actualValue);
+            assertEquals("Content value comparison " + i, 0, expectedContent.getValue().compareTo(actualValue));
+        }
+    }
+
 }
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/TmfXmlPatternSegmentBuilderTest.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/TmfXmlPatternSegmentBuilderTest.java
new file mode 100644 (file)
index 0000000..c67794a
--- /dev/null
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * 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.fail;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlPatternSegmentBuilder;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.model.readwrite.TmfXmlReadWriteModelFactory;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.segment.TmfXmlPatternSegment;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stubs.PatternSegmentFactoryStub;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stubs.StateSystemContainerStub;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Test suite for the XML pattern segment builder. The builder should create the
+ * corresponding pattern segment :
+ *
+ * <p>
+ * -name : "test"
+ * </p>
+ * <p>
+ * -content :
+ * </p>
+ * <p>
+ * &nbsp;&nbsp;&nbsp;&nbsp;-field1 : 5
+ * </p>
+ * <p>
+ * &nbsp;&nbsp;&nbsp;&nbsp;-field2 : "test"
+ * </p>
+ * <p>
+ * &nbsp;&nbsp;&nbsp;&nbsp;-field3 : 1
+ * </p>
+ *
+ * @author Jean-Christian Kouame
+ */
+public class TmfXmlPatternSegmentBuilderTest {
+
+    private static final @NonNull String ANALYSIS_ID = "xml test pattern segment";
+    private final @NonNull StateSystemContainerStub fContainer = new StateSystemContainerStub();
+    private final @NonNull ITmfXmlModelFactory fModelFactory = TmfXmlReadWriteModelFactory.getInstance();
+    private File fTestXmlFile;
+
+    /**
+     * test the {@link XmlUtils#xmlValidate(File)} method
+     */
+    @Before
+    public void testXmlValidate() {
+        fTestXmlFile = TmfXmlTestFiles.VALID_PATTERN_SEGMENT.getFile();
+        if ((fTestXmlFile == null) || !fTestXmlFile.exists()) {
+            fail("XML pattern test file does not exist");
+        }
+        IStatus status = XmlUtils.xmlValidate(fTestXmlFile);
+        if (!status.isOK()) {
+            fail(status.getMessage());
+        }
+    }
+
+    /**
+     * Create a pattern segment builder that will generate a pattern segment.
+     * This method test the data of the pattern segment created.
+     */
+    @Test
+    public void testBuilder() {
+        Element doc = XmlUtils.getElementInFile(fTestXmlFile.getPath(), TmfXmlStrings.PATTERN, ANALYSIS_ID);
+        NodeList patternSegments = doc.getElementsByTagName(TmfXmlStrings.SEGMENT);
+        assertEquals("Number of pattern segments", 2, patternSegments.getLength());
+
+        final Node item2 = patternSegments.item(1);
+        assertNotNull("pattern segment 2", item2);
+        // create a pattern segment builder using the second pattern segment description in the XML pattern file
+        TmfXmlPatternSegmentBuilder builder = new TmfXmlPatternSegmentBuilder(fModelFactory, (Element) item2, fContainer);
+        assertNotNull("builder", builder);
+
+        //Create a pattern segment and test its content
+        TmfXmlPatternSegment segment = builder.generatePatternSegment(PatternSegmentFactoryStub.TEST_2_END_EVENT,
+                PatternSegmentFactoryStub.TEST_2_START_EVENT.getTimestamp(),
+                PatternSegmentFactoryStub.TEST_2_END_EVENT.getTimestamp());
+        XmlUtilsTest.testPatternSegmentData(PatternSegmentFactoryStub.TEST_2, segment);
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/stubs/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stubs/PatternSegmentFactoryStub.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/stubs/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stubs/PatternSegmentFactoryStub.java
new file mode 100644 (file)
index 0000000..ee5922c
--- /dev/null
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * 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.stubs;
+
+import java.util.Map;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.segment.TmfXmlPatternSegment;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
+
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Factory generating various pattern segments and data used for tests
+ *
+ * @author Jean-Christian Kouame
+ *
+ */
+public class PatternSegmentFactoryStub {
+
+    private static final @NonNull String NAME_FIELD_1 = "field1";
+    private static final @NonNull String NAME_FIELD_2 = "field2";
+    private static final @NonNull String NAME_FIELD_3 = "field3";
+    /**
+     * The content for the segment TEST_2
+     */
+    private static final @NonNull Map<@NonNull String, @NonNull ITmfStateValue> TEST_2_CONTENT = ImmutableMap
+            .of(NAME_FIELD_1, TmfStateValue.newValueLong(5l),
+            NAME_FIELD_2, TmfStateValue.newValueString("test"),
+            NAME_FIELD_3, TmfStateValue.newValueInt(1));
+
+    /**
+     * Start event for pattern segment TEST_2
+     */
+    public static final @NonNull ITmfEvent TEST_2_START_EVENT = new TmfEvent(null, ITmfContext.UNKNOWN_RANK, new TmfTimestamp(1, ITmfTimestamp.NANOSECOND_SCALE), null, null);
+    /**
+     * end event for pattern segment TEST_2
+     */
+    public static final @NonNull ITmfEvent TEST_2_END_EVENT = new TmfEvent(null, ITmfContext.UNKNOWN_RANK, new TmfTimestamp(10, ITmfTimestamp.NANOSECOND_SCALE), null, null);
+
+    /**
+     * The pattern segment TEST_2
+     */
+    public static final @NonNull TmfXmlPatternSegment TEST_2 = new TmfXmlPatternSegment(TEST_2_START_EVENT.getTimestamp().getValue(), TEST_2_END_EVENT.getTimestamp().getValue(), ITmfTimestamp.NANOSECOND_SCALE, "seg_test2", TEST_2_CONTENT);
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/stubs/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stubs/StateSystemContainerStub.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/stubs/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stubs/StateSystemContainerStub.java
new file mode 100644 (file)
index 0000000..b9f0555
--- /dev/null
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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.stubs;
+
+import java.util.HashSet;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlLocation;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+
+/**
+ * This class is a stub for State system Container.
+ *
+ * @author Jean-Christian Kouame
+ *
+ */
+public class StateSystemContainerStub implements IXmlStateSystemContainer {
+
+    @Override
+    public String getAttributeValue(String name) {
+        return null;
+    }
+
+    @Override
+    public ITmfStateSystem getStateSystem() {
+        return null;
+    }
+
+    @Override
+    public @NonNull Iterable<@NonNull TmfXmlLocation> getLocations() {
+        return new HashSet<>();
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_xml_files/test_valid/test_pattern_segment.xml b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_xml_files/test_valid/test_pattern_segment.xml
new file mode 100644 (file)
index 0000000..83b7c91
--- /dev/null
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tmfxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:noNamespaceSchemaLocation="xmlDefinition.xsd">
+<!-- ***************************************************************************
+* Copyright (c) 2015 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
+*
+* Contributors:
+*   Jean-Christian Kouame - Initial API and implementation
+*************************************************************************** -->
+<pattern version="0" id="xml test pattern segment">
+       <head>
+               <traceType id="org.eclipse.linuxtools.lttng2.kernel.tracetype" />
+               <label value="xml test pattern segment" />
+       </head>
+
+<!--           the pattern handler specifies the FSM that will be instanciated at the beginning of the analysis -->
+       <patternHandler initial="test">
+
+<!--           CONDITIONS -->
+
+<!--           ACTIONS -->
+<!--           Generate two segments -->
+               <action id="pattern segment test 1">
+<!--                   Generate a pattern segment with the name 'test1'-->
+                       <segment>
+                               <segType segName="test1" />
+                       </segment>
+               </action>
+               <action id="pattern segment test 2">
+<!--                   Generate a pattern segment with the name 'test2' and with three fields 'field1', 'field2' and 'field2'-->
+                       <segment>
+                               <segType segName="test2" />
+                               <segContent>
+                                       <segField name="field1" type="long" value="5"/>
+                                       <segField name="field2" type="string" value="test"/>
+                                       <segField name="field3" type="int" value="1"/>
+                               </segContent>
+                       </segment>
+               </action>
+
+<!--           FSMs -->
+
+<!--   test fsm
+               Declare a test FSM that that will generate two segments for each event received
+-->
+               <fsm id="test" multiple="false" initial="state">
+                       <state id="state">
+<!--                                   The state will stay here forever-->
+                               <transition target="state" action="pattern segment test 1:pattern segment test 2" />
+                       </state>
+               </fsm>
+       </patternHandler>
+</pattern>
+</tmfxml>
\ No newline at end of file
This page took 0.029862 seconds and 5 git commands to generate.