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 */
--- /dev/null
+/*******************************************************************************
+ * 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);
+
+ }
+}
--- /dev/null
+<!-- ***************************************************************************
+* 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
--- /dev/null
+<?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
/* 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 */
/* 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);
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
case NULL:
case PEEK:
default:
- ss.modifyAttribute(timestamp, value, quark);
+ if (isUpdate()) {
+ ss.updateOngoingState(value, quark);
+ } else {
+ ss.modifyAttribute(timestamp, value, quark);
+ }
break;
}
}
}
}
- 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: {
<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>
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";