xml: bug 497959 add the possibility to update the current state
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Fri, 22 Jul 2016 19:52:24 +0000 (15:52 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Thu, 18 Aug 2016 17:27:17 +0000 (13:27 -0400)
This adds an 'update' attribute to state values, such that it uses the
updateOngoingState method of the state system to change the value of the
current state instead of modifying it.

Change-Id: I44b80c1801b9dbbb4f858ba7e3c05434d84f9003
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/77797
Reviewed-by: Hudson CI
Reviewed-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Tested-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
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/model/TmfStateValueTest.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_traces/testTrace4.xml [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_xml_files/test_valid/test_state_values.xml [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateValue.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateValue.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlStateProvider.xsd
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java

index 384b5c27896904bace7b5cd452543326e321e4d2..ef4b538a877323d1e5920ec4644475b6e66ad76c 100644 (file)
@@ -38,6 +38,8 @@ public enum TmfXmlTestFiles {
     INVALID_FILE("test_xml_files/test_invalid/test_invalid.xml"),
     /** A valid file for state attribute tests */
     ATTRIBUTE_FILE("test_xml_files/test_valid/test_attributes.xml"),
+    /** A valid file for state value tests */
+    STATE_VALUE_FILE("test_xml_files/test_valid/test_state_values.xml"),
     /** A valid file for conditions tests */
     CONDITION_FILE("test_xml_files/test_valid/test_conditions.xml"),
     /** A valid file for doubles tests */
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/model/TmfStateValueTest.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/model/TmfStateValueTest.java
new file mode 100644 (file)
index 0000000..d6489d5
--- /dev/null
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.model;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+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.core.exceptions.TmfAnalysisException;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test the various cases for the state value changes. To add new test cases,
+ * the trace test file and the state value test files can be modified to cover
+ * extra cases.
+ *
+ * @author Geneviève Bastien
+ */
+public class TmfStateValueTest {
+
+    private static final @NonNull String TEST_TRACE = "test_traces/testTrace4.xml";
+
+    ITmfTrace fTrace;
+    XmlStateSystemModule fModule;
+
+    /**
+     * Initializes the trace and the module for the tests
+     *
+     * @throws TmfAnalysisException
+     *             Any exception thrown during module initialization
+     */
+    @Before
+    public void setUp() throws TmfAnalysisException {
+        ITmfTrace trace = XmlUtilsTest.initializeTrace(TEST_TRACE);
+        XmlStateSystemModule module = XmlUtilsTest.initializeModule(TmfXmlTestFiles.STATE_VALUE_FILE);
+
+        module.setTrace(trace);
+
+        module.schedule();
+        module.waitForCompletion();
+
+        fTrace = trace;
+        fModule = module;
+    }
+
+    /**
+     * Dispose the module and the trace
+     */
+    @After
+    public void cleanUp() {
+        fTrace.dispose();
+        fModule.dispose();
+    }
+
+    /**
+     * Test that the ongoing state is updated instead of creating a new state
+     *
+     * @throws StateSystemDisposedException
+     *             Exceptions thrown during state system verification
+     * @throws AttributeNotFoundException
+     *             Exceptions thrown during state system verification
+     */
+    @Test
+    public void testStateValueUpdate() throws AttributeNotFoundException, StateSystemDisposedException {
+        XmlStateSystemModule module = fModule;
+        assertNotNull(module);
+
+        ITmfStateSystem ss = module.getStateSystem();
+        assertNotNull(ss);
+
+        int quark = ss.getQuarkAbsolute("update", "0");
+
+        final int[] expectedStarts = { 1, 3, 5, 7, 7 };
+        ITmfStateValue[] expectedValues = { TmfStateValue.newValueString("GOOD"), TmfStateValue.nullValue(), TmfStateValue.newValueString("BAD"), TmfStateValue.nullValue() };
+        XmlUtilsTest.verifyStateIntervals("testStateValueUpdate", ss, quark, expectedStarts, expectedValues);
+
+    }
+
+    /**
+     * Test that a state change with no update causes the modification of the
+     * state value at the time of the event
+     *
+     * @throws StateSystemDisposedException
+     *             Exceptions thrown during state system verification
+     * @throws AttributeNotFoundException
+     *             Exceptions thrown during state system verification
+     */
+    @Test
+    public void testStateValueModify() throws AttributeNotFoundException, StateSystemDisposedException {
+        XmlStateSystemModule module = fModule;
+        assertNotNull(module);
+
+        ITmfStateSystem ss = module.getStateSystem();
+        assertNotNull(ss);
+
+        int quark = ss.getQuarkAbsolute("modify", "0");
+
+        final int[] expectedStarts = { 1, 3, 5, 7, 7 };
+        ITmfStateValue[] expectedValues = { TmfStateValue.newValueString("UNKNOWN"), TmfStateValue.newValueString("GOOD"), TmfStateValue.newValueString("UNKNOWN"), TmfStateValue.newValueString("BAD") };
+        XmlUtilsTest.verifyStateIntervals("testStateValueModify", ss, quark, expectedStarts, expectedValues);
+
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_traces/testTrace4.xml b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_traces/testTrace4.xml
new file mode 100644 (file)
index 0000000..e71e032
--- /dev/null
@@ -0,0 +1,27 @@
+<!-- ***************************************************************************
+* 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
+*************************************************************************** -->
+<trace>
+<event timestamp="1" name="entry" source="0">
+<field name="cpu" type="int" value="0" />
+</event>
+<event timestamp="3" name="exit" source="0">
+<field name="cpu" type="int" value="0" />
+<field name="curState" type="string" value="GOOD" />
+</event>
+<event timestamp="5" name="entry" source="0">
+<field name="cpu" type="int" value="0" />
+</event>
+<event timestamp="7" name="exit" source="0">
+<field name="cpu" type="int" value="0" />
+<field name="curState" type="string" value="BAD" />
+</event>
+</trace>
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_xml_files/test_valid/test_state_values.xml b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_xml_files/test_valid/test_state_values.xml
new file mode 100644 (file)
index 0000000..2326f6c
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- ***************************************************************************
+* Copyright (c) 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
+* accompanies this distribution, and is available at
+* http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+       * Geneviève Bastien - Initial API and implementation
+*************************************************************************** -->
+<tmfxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:noNamespaceSchemaLocation="xmlDefinition.xsd">
+
+       <stateProvider id="test.xml.attributes" version="1">
+
+               <!-- Test to see that state values are updated or modified depending on the requested state change -->
+               <eventHandler eventName="entry">
+                       <stateChange>
+                               <stateAttribute type="constant" value="update" />
+                               <stateAttribute type="eventField" value="cpu" />
+                               <stateValue type="string" value="UNKNOWN" />
+                       </stateChange>
+                       <stateChange>
+                               <stateAttribute type="constant" value="modify" />
+                               <stateAttribute type="eventField" value="cpu" />
+                               <stateValue type="string" value="UNKNOWN" />
+                       </stateChange>
+               </eventHandler>
+               <eventHandler eventName="exit">
+                       <stateChange>
+                               <stateAttribute type="constant" value="update" />
+                               <stateAttribute type="eventField" value="cpu" />
+                               <stateValue type="eventField" value="curState" update="true" />
+                       </stateChange>
+                       <stateChange>
+                               <stateAttribute type="constant" value="update" />
+                               <stateAttribute type="eventField" value="cpu" />
+                               <stateValue type="null" />
+                       </stateChange>
+                       <stateChange>
+                               <stateAttribute type="constant" value="modify" />
+                               <stateAttribute type="eventField" value="cpu" />
+                               <stateValue type="eventField" value="curState" />
+                       </stateChange>
+               </eventHandler>
+       </stateProvider>
+</tmfxml>
\ No newline at end of file
index 35a2d0143c2ee82c2b8acceea0ba6288da01a11b..827dc77d6ef22d09c4a6abcfbc9c331c0890604e 100644 (file)
@@ -55,6 +55,8 @@ public abstract class TmfXmlStateValue implements ITmfXmlStateValue {
 
     /* Whether this state value is an increment of the previous value */
     private final boolean fIncrement;
+    /* Whether to update the current attribute or create a new state */
+    private final boolean fUpdate;
     /* Stack value */
     private final ValueTypeStack fStackType;
     /* Forced value type */
@@ -121,6 +123,9 @@ public abstract class TmfXmlStateValue implements ITmfXmlStateValue {
         /* Check if there is an increment for the value */
         fIncrement = Boolean.parseBoolean(node.getAttribute(TmfXmlStrings.INCREMENT));
 
+        /* Check if this value is an update of the ongoing state */
+        fUpdate = Boolean.parseBoolean(node.getAttribute(TmfXmlStrings.UPDATE));
+
         /* Process the XML Element state value */
         fStateValue = initializeStateValue(modelFactory, node);
 
@@ -193,6 +198,16 @@ public abstract class TmfXmlStateValue implements ITmfXmlStateValue {
         return fIncrement;
     }
 
+    /**
+     * Return whether this value should replace the current value of the
+     * attribute or if a new state should be created.
+     *
+     * @return <code>true</code> if the value is to replace the current one
+     */
+    protected boolean isUpdate() {
+        return fUpdate;
+    }
+
     /**
      * Get the stack type of this attribute. If the attribute is to be pushed or
      * popped to a stack. The behavior of the stack attribute will depend on the
index 920e0858d0c40e9c29acca077a65f04258efbb5a..5192cf79cc862488db8d7a73db6f0e11f8c1fa55 100644 (file)
@@ -192,7 +192,11 @@ public class TmfXmlReadWriteStateValue extends TmfXmlStateValue {
             case NULL:
             case PEEK:
             default:
-                ss.modifyAttribute(timestamp, value, quark);
+                if (isUpdate()) {
+                    ss.updateOngoingState(value, quark);
+                } else {
+                    ss.modifyAttribute(timestamp, value, quark);
+                }
                 break;
             }
         }
@@ -207,7 +211,7 @@ public class TmfXmlReadWriteStateValue extends TmfXmlStateValue {
         }
     }
 
-    private static @Nullable ITmfStateValue incrementByType(int quark, ITmfStateSystem ss, ITmfStateValue stateValue) throws AttributeNotFoundException {
+    private static @Nullable ITmfStateValue incrementByType(int quark, ITmfStateSystem ss, ITmfStateValue stateValue) {
         ITmfStateValue value = null;
         switch (stateValue.getType()) {
         case LONG: {
index 87038570e435395d2bfe81db61d570376cb3c00c..b8a31bdaa9fc1f93b20e851ef79470359ddf7022 100644 (file)
                <xs:attribute name="increment" type="xs:boolean" >
                        <xs:annotation>
                                <xs:documentation>Indicate that the current value will be added to any previously available value.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="update" type="xs:boolean" >
+                       <xs:annotation>
+                               <xs:documentation>Indicate that this value will replace the previous value for the attribute instead of changing its state.</xs:documentation></xs:annotation></xs:attribute>
                <xs:attribute name="stack">
                        <xs:annotation>
                                <xs:documentation>Indicate that a stack operation will be performed with the value</xs:documentation></xs:annotation>
index b730c2dd9050975ca34d6d8d59046f17bcc38ec5..6c0ac7e438e37e0383127d2f3a2b257120fe321a 100644 (file)
@@ -77,6 +77,7 @@ public interface TmfXmlStrings {
     String TYPE_EVENT_NAME = "eventName";
     String TYPE_DELETE = "delete";
     String INCREMENT = "increment";
+    String UPDATE = "update";
     String FORCED_TYPE = "forcedType";
     String ATTRIBUTE_STACK = "stack";
     String STACK_POP = "pop";
This page took 0.030646 seconds and 5 git commands to generate.