Search in sources :

Example 1 with DataDrivenValue

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValue in project tracecompass by tracecompass.

the class TmfXmlStateAttributeAndLocationCuTest method testValidStateAttributeCompilation.

/**
 * Test the compilation of a valid state attribute strings, except locations
 *
 * @throws SAXException
 *             Exception thrown by parser
 * @throws IOException
 *             Exception thrown by parser
 * @throws ParserConfigurationException
 *             Exception thrown by parser
 */
@Test
public void testValidStateAttributeCompilation() throws SAXException, IOException, ParserConfigurationException {
    String[] validStrings = { "<stateAttribute type=\"null\" />", "<stateAttribute type=\"constant\" value=\"42\" />", "<stateAttribute type=\"eventField\" value=\"myfield\" />", "<stateAttribute type=\"eventName\" />", "<stateAttribute type=\"eventName\" value=\"ignored\" />", "<stateAttribute type=\"query\" ><stateAttribute type=\"constant\" value=\"queryPath\"/></stateAttribute>", "<stateAttribute type=\"self\" />", "<stateAttribute type=\"pool\" />" };
    DataDrivenValue[] generated = { TmfXmlTestUtils.NULL_VALUE, new DataDrivenValueConstant(null, ITmfStateValue.Type.NULL, "42"), new DataDrivenValueEventField(null, ITmfStateValue.Type.NULL, "myfield"), new DataDrivenValueEventName(null), new DataDrivenValueEventName(null), new DataDrivenValueQuery(null, ITmfStateValue.Type.NULL, new DataDrivenStateSystemPath(ImmutableList.of(new DataDrivenValueConstant(null, ITmfStateValue.Type.NULL, "queryPath")), IBaseQuarkProvider.IDENTITY_BASE_QUARK)), new DataDrivenValueSelf(ITmfStateValue.Type.NULL), DataDrivenValuePool.getInstance() };
    for (int i = 0; i < validStrings.length; i++) {
        String validString = validStrings[i];
        DataDrivenValue runtimeObj = generated[i];
        Element xmlElement = TmfXmlTestUtils.getXmlElement(TmfXmlStrings.STATE_ATTRIBUTE, validString);
        assertNotNull(xmlElement);
        List<@NonNull TmfXmlStateValueCu> compileAttribute = TmfXmlStateValueCu.compileAttribute(ANALYSIS_DATA, xmlElement);
        assertNotNull(validString, compileAttribute);
        assertEquals("Number of attributes", 1, compileAttribute.size());
        TmfXmlStateValueCu value = compileAttribute.get(0);
        assertEquals("Expected attribute", runtimeObj, value.generate());
    }
}
Also used : DataDrivenValueQuery(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueQuery) TmfXmlStateValueCu(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateValueCu) DataDrivenValueSelf(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueSelf) DataDrivenValue(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValue) Element(org.w3c.dom.Element) DataDrivenStateSystemPath(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath) DataDrivenValueEventField(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueEventField) DataDrivenValueConstant(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueConstant) DataDrivenValueEventName(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueEventName) Test(org.junit.Test)

Example 2 with DataDrivenValue

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValue in project tracecompass by tracecompass.

the class DataDrivenActionSegment method eventHandle.

@Override
public void eventHandle(ITmfEvent event, DataDrivenScenarioInfo scenarioInfo, IAnalysisDataContainer container) {
    if (!(container instanceof DataDrivenPattern)) {
        // This action should only be run with pattern state provider
        return;
    }
    DataDrivenPattern provider = (DataDrivenPattern) container;
    // Get the default timestamp
    long start = provider.getExecutionData().getHistoryBuilder().getStartTime(container, scenarioInfo, event);
    long end = event.getTimestamp().toNanos();
    Object segmentName = fType.getValue(event, ITmfStateSystem.ROOT_ATTRIBUTE, scenarioInfo, container);
    Map<String, Object> fields = new HashMap<>();
    for (Entry<String, DataDrivenValue> field : fFields.entrySet()) {
        Object value = field.getValue().getValue(event, ITmfStateSystem.ROOT_ATTRIBUTE, scenarioInfo, container);
        // Segment content does not support null values
        if (value != null) {
            if (value instanceof ITmfStateValue) {
                if (!((ITmfStateValue) value).isNull()) {
                    fields.put(field.getKey(), Objects.requireNonNull(((ITmfStateValue) value).unboxValue()));
                }
            } else {
                fields.put(field.getKey(), value);
            }
        }
    }
    // Set the start time
    if (fStart != null) {
        Object startVal = fStart.getValue(event, ITmfStateSystem.ROOT_ATTRIBUTE, scenarioInfo, container);
        if (startVal instanceof Number) {
            start = ((Number) startVal).longValue();
        }
    }
    // Set the end time
    if (fEnd != null) {
        Object endVal = fEnd.getValue(event, ITmfStateSystem.ROOT_ATTRIBUTE, scenarioInfo, container);
        if (endVal instanceof Number) {
            long endL = ((Number) endVal).longValue();
            end = endL >= start ? endL : end;
        }
    } else if (fDuration != null) {
        Object durationVal = fDuration.getValue(event, ITmfStateSystem.ROOT_ATTRIBUTE, scenarioInfo, container);
        if (durationVal instanceof Number) {
            long durationL = ((Number) durationVal).longValue();
            long endL = start + durationL;
            end = endL >= start ? endL : end;
        }
    }
    TmfXmlPatternSegment segment = new TmfXmlPatternSegment(start, end, String.valueOf(segmentName), fields);
    provider.getListener().onNewSegment(segment);
}
Also used : TmfXmlPatternSegment(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment.TmfXmlPatternSegment) HashMap(java.util.HashMap) DataDrivenValue(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValue) ITmfStateValue(org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue) DataDrivenPattern(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.pattern.DataDrivenPattern)

Example 3 with DataDrivenValue

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValue in project tracecompass by tracecompass.

the class DataDrivenStateSystemPath method getQuark.

/**
 * Get the quark in the system for this path by resolving each value along
 * the path
 *
 * @param event
 *            The event to use, it can be null if called outside an event
 *            request.
 * @param baseQuark
 *            The original base quark, as obtained by the caller
 * @param scenarioInfo
 *            The scenario data information. It will be null if the event is
 *            null
 * @param container
 *            The analysis data container
 * @return The quark when the path is resolved.
 */
public int getQuark(@Nullable ITmfEvent event, int baseQuark, @Nullable DataDrivenScenarioInfo scenarioInfo, IAnalysisDataContainer container) {
    int quark = fQuarkProvider.getBaseQuark(baseQuark, scenarioInfo);
    for (DataDrivenValue val : fAttributes) {
        Object value = val.getValue(event, quark, scenarioInfo, container);
        if (value == null) {
            // $NON-NLS-1$
            Activator.logWarning("StateChange.handleEvent: A value is null: " + val);
            return ITmfStateSystem.INVALID_ATTRIBUTE;
        }
        quark = container.getQuarkRelativeAndAdd(quark, String.valueOf(value));
        if (quark < 0) {
            // $NON-NLS-1$//$NON-NLS-2$
            Activator.logWarning("The attribute quark is invalid for event " + event + ": " + fAttributes);
            break;
        }
    }
    return quark;
}
Also used : DataDrivenValue(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValue)

Example 4 with DataDrivenValue

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValue in project tracecompass by tracecompass.

the class DataDrivenStateSystemPath method getQuark.

/**
 * Get the quark in the system for this path by resolving each value along
 * the path
 *
 * @param baseQuark
 *            The original base quark, as obtained by the caller
 * @param container
 *            The analysis data container
 * @return The quark when the path is resolved.
 */
public int getQuark(int baseQuark, IAnalysisDataContainer container) {
    int quark = fQuarkProvider.getBaseQuark(baseQuark, null);
    for (DataDrivenValue val : fAttributes) {
        Object value = val.getValue(null, quark, null, container);
        if (value == null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            Activator.logWarning("State system path, a value is null for " + val + " from quark " + quark);
            return ITmfStateSystem.INVALID_ATTRIBUTE;
        }
        ITmfStateSystem stateSystem = container.getStateSystem();
        quark = stateSystem.optQuarkRelative(quark, String.valueOf(value));
        if (quark < 0) {
            // $NON-NLS-1$
            Activator.logWarning("The attribute quark is invalid: " + fAttributes);
            break;
        }
    }
    return quark;
}
Also used : DataDrivenValue(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValue) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 5 with DataDrivenValue

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValue in project tracecompass by tracecompass.

the class TmfXmlStateAttributeAndLocationCuTest method testValidLocationCompilation.

/**
 * Test the compilation of a valid state location strings, and states
 * attributes that use it
 *
 * @throws SAXException
 *             Exception thrown by parser
 * @throws IOException
 *             Exception thrown by parser
 * @throws ParserConfigurationException
 *             Exception thrown by parser
 */
@Test
public void testValidLocationCompilation() throws SAXException, IOException, ParserConfigurationException {
    String locName = "loc";
    String location = "<location id=\"" + locName + "\">" + "<stateAttribute type=\"constant\" value=\"abc\" />" + "<stateAttribute type=\"eventField\" value=\"myField\" />" + "</location>";
    AnalysisCompilationData data = new AnalysisCompilationData();
    Element xmlElement = TmfXmlTestUtils.getXmlElement(TmfXmlStrings.LOCATION, location);
    assertNotNull(xmlElement);
    TmfXmlLocationCu locationCu = TmfXmlLocationCu.compile(data, xmlElement);
    assertNotNull("location", locationCu);
    // Add the location to the compilation data
    data.addLocation(locName, locationCu);
    // Compile a location state attribute
    String attributeXml = "<stateAttribute type=\"location\" value=\"" + locName + "\" />";
    xmlElement = TmfXmlTestUtils.getXmlElement(TmfXmlStrings.STATE_ATTRIBUTE, attributeXml);
    assertNotNull(xmlElement);
    List<@NonNull TmfXmlStateValueCu> attribute = TmfXmlStateValueCu.compileAttribute(data, xmlElement);
    assertNotNull("Location attribute compilation", attribute);
    assertEquals("Attribute count", 2, attribute.size());
    List<DataDrivenValue> expected = ImmutableList.of(new DataDrivenValueConstant(null, ITmfStateValue.Type.NULL, "abc"), new DataDrivenValueEventField(null, ITmfStateValue.Type.NULL, "myField"));
    List<DataDrivenValue> actual = attribute.stream().map(a -> a.generate()).collect(Collectors.toList());
    assertEquals("Location generated", expected, actual);
}
Also used : Arrays(java.util.Arrays) TmfXmlStateValueCu(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateValueCu) Parameters(org.junit.runners.Parameterized.Parameters) TmfXmlTestUtils(org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestUtils) DataDrivenValuePool(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValuePool) TmfXmlLocationCu(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlLocationCu) ImmutableList(com.google.common.collect.ImmutableList) AnalysisCompilationData(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.AnalysisCompilationData) DataDrivenStateSystemPath(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath) DataDrivenValueQuery(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueQuery) DataDrivenValueConstant(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueConstant) TmfXmlStrings(org.eclipse.tracecompass.tmf.analysis.xml.core.module.TmfXmlStrings) DataDrivenValue(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValue) IBaseQuarkProvider(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.IBaseQuarkProvider) DataDrivenValueEventName(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueEventName) ITmfStateValue(org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue) DataDrivenValueSelf(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueSelf) Assert.assertNotNull(org.junit.Assert.assertNotNull) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) DataDrivenValueEventField(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueEventField) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) NonNull(org.eclipse.jdt.annotation.NonNull) Assert.assertEquals(org.junit.Assert.assertEquals) TmfXmlStateValueCu(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateValueCu) Element(org.w3c.dom.Element) DataDrivenValue(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValue) TmfXmlLocationCu(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlLocationCu) DataDrivenValueEventField(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueEventField) AnalysisCompilationData(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.AnalysisCompilationData) DataDrivenValueConstant(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueConstant) Test(org.junit.Test)

Aggregations

DataDrivenValue (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValue)5 TmfXmlStateValueCu (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateValueCu)2 DataDrivenStateSystemPath (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath)2 DataDrivenValueConstant (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueConstant)2 DataDrivenValueEventField (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueEventField)2 DataDrivenValueEventName (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueEventName)2 DataDrivenValueQuery (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueQuery)2 DataDrivenValueSelf (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueSelf)2 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)2 Test (org.junit.Test)2 Element (org.w3c.dom.Element)2 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 AnalysisCompilationData (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.AnalysisCompilationData)1