</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="common"/>
+ <classpathentry kind="src" path="stubs"/>
<classpathentry kind="output" path="bin"/>
</classpath>
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",
# Ericsson - Initial API and implementation
###############################################################################
source.. = src/,\
- common/
+ common/,\
+ stubs/
output.. = bin/
bin.includes = META-INF/,\
.,\
/** 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;
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;
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;
}
}
+ /**
+ * 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));
+ }
+ }
+
}
--- /dev/null
+/*******************************************************************************
+ * 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>
+ * -field1 : 5
+ * </p>
+ * <p>
+ * -field2 : "test"
+ * </p>
+ * <p>
+ * -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);
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * 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);
+}
--- /dev/null
+/*******************************************************************************
+ * 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<>();
+ }
+}
--- /dev/null
+<?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