From 8ab1a9651c237d2dc9ae30b629c00aeb5b321855 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Genevi=C3=A8ve=20Bastien?= Date: Fri, 22 Jul 2016 15:52:24 -0400 Subject: [PATCH] xml: bug 497959 add the possibility to update the current state MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-on: https://git.eclipse.org/r/77797 Reviewed-by: Hudson CI Reviewed-by: Jean-Christian Kouame Tested-by: Jean-Christian Kouame --- .../core/tests/common/TmfXmlTestFiles.java | 2 + .../core/tests/model/TmfStateValueTest.java | 120 ++++++++++++++++++ .../test_traces/testTrace4.xml | 27 ++++ .../test_valid/test_state_values.xml | 49 +++++++ .../xml/core/model/TmfXmlStateValue.java | 15 +++ .../readwrite/TmfXmlReadWriteStateValue.java | 8 +- .../xml/core/module/xmlStateProvider.xsd | 3 + .../xml/core/stateprovider/TmfXmlStrings.java | 1 + 8 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/model/TmfStateValueTest.java create mode 100644 tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_traces/testTrace4.xml create mode 100644 tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_xml_files/test_valid/test_state_values.xml diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/common/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/common/TmfXmlTestFiles.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/common/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/common/TmfXmlTestFiles.java index 384b5c2789..ef4b538a87 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/common/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/common/TmfXmlTestFiles.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/common/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/common/TmfXmlTestFiles.java @@ -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 index 0000000000..d6489d51b6 --- /dev/null +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/model/TmfStateValueTest.java @@ -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 index 0000000000..e71e032e82 --- /dev/null +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_traces/testTrace4.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + \ 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 index 0000000000..2326f6ce23 --- /dev/null +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_xml_files/test_valid/test_state_values.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateValue.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateValue.java index 35a2d0143c..827dc77d6e 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateValue.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateValue.java @@ -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 true 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 diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateValue.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateValue.java index 920e0858d0..5192cf79cc 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateValue.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateValue.java @@ -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: { diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlStateProvider.xsd b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlStateProvider.xsd index 87038570e4..b8a31bdaa9 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlStateProvider.xsd +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlStateProvider.xsd @@ -284,6 +284,9 @@ Indicate that the current value will be added to any previously available value. + + + Indicate that this value will replace the previous value for the attribute instead of changing its state. Indicate that a stack operation will be performed with the value diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java index b730c2dd90..6c0ac7e438 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java @@ -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"; -- 2.34.1