Search in sources :

Example 6 with DataDrivenAnalysisModule

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule in project tracecompass by tracecompass.

the class TmfStateValueTest method testStateValueFuture.

/**
 * Test that a future state value changes the state at the appropriate time
 *
 * @throws StateSystemDisposedException
 *             Exceptions thrown during state system verification
 * @throws AttributeNotFoundException
 *             Exceptions thrown during state system verification
 */
@Test
public void testStateValueFuture() throws AttributeNotFoundException, StateSystemDisposedException {
    DataDrivenAnalysisModule module = fModule;
    assertNotNull(module);
    ITmfStateSystem ss = module.getStateSystem();
    assertNotNull(ss);
    int quark = ss.getQuarkAbsolute("future");
    final int[] expectedStarts = { 1, 3, 5, 7, 10, 12, 20 };
    ITmfStateValue[] expectedValues = { TmfStateValue.newValueInt(100), TmfStateValue.newValueInt(101), TmfStateValue.newValueInt(100), TmfStateValue.newValueInt(101), TmfStateValue.newValueInt(100), TmfStateValue.newValueInt(101) };
    XmlUtilsTest.verifyStateIntervals("future value modification", ss, quark, expectedStarts, expectedValues);
    // Verify also future time as strings
    quark = ss.getQuarkAbsolute("futureStr");
    XmlUtilsTest.verifyStateIntervals("future time as string", ss, quark, expectedStarts, expectedValues);
    // Test the future stack of CPU 0
    quark = ss.getQuarkAbsolute("futureStack", "0", "1");
    final int[] expected01Starts = { 1, 2, 11, 20 };
    ITmfStateValue[] expected01Values = { TmfStateValue.nullValue(), TmfStateValue.newValueString("op1"), TmfStateValue.nullValue() };
    XmlUtilsTest.verifyStateIntervals("future stack CPU 0, level 1", ss, quark, expected01Starts, expected01Values);
    quark = ss.getQuarkAbsolute("futureStack", "0", "2");
    final int[] expected02Starts = { 1, 6, 7, 20 };
    ITmfStateValue[] expected02Values = { TmfStateValue.nullValue(), TmfStateValue.newValueString("op1"), TmfStateValue.nullValue() };
    XmlUtilsTest.verifyStateIntervals("future stack CPU 0, level 2", ss, quark, expected02Starts, expected02Values);
    // Test the future stack of CPU 1
    quark = ss.getQuarkAbsolute("futureStack", "1", "1");
    final int[] expected11Starts = { 1, 3, 8, 11, 16, 20 };
    ITmfStateValue[] expected11Values = { TmfStateValue.nullValue(), TmfStateValue.newValueString("op1"), TmfStateValue.nullValue(), TmfStateValue.newValueString("op1"), TmfStateValue.nullValue() };
    XmlUtilsTest.verifyStateIntervals("future stack CPU 1, level 1", ss, quark, expected11Starts, expected11Values);
}
Also used : DataDrivenAnalysisModule(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule) ITmfStateValue(org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test) XmlUtilsTest(org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest)

Example 7 with DataDrivenAnalysisModule

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule in project tracecompass by tracecompass.

the class XmlDataProviderManagerTest method testExperimentWithTraceAnalysis.

/**
 * Test getting the XML data provider for an experiment, with an analysis that
 * applies to a trace
 */
@Test
public void testExperimentWithTraceAnalysis() {
    ITmfTrace trace = null;
    ITmfTrace trace2 = null;
    ITmfTrace experiment = null;
    try {
        // Initialize the trace and module
        trace = XmlUtilsTest.initializeTrace(TEST_TRACE);
        trace2 = XmlUtilsTest.initializeTrace(TEST_TRACE2);
        ITmfTrace[] traces = { trace, trace2 };
        experiment = new TmfExperiment(ITmfEvent.class, "Xml Experiment", traces, TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, null);
        TmfTraceOpenedSignal signal = new TmfTraceOpenedSignal(this, experiment, null);
        ((TmfTrace) trace).traceOpened(signal);
        ((TmfTrace) trace2).traceOpened(signal);
        ((TmfTrace) experiment).traceOpened(signal);
        // The data provider manager uses opened traces from the manager
        TmfTraceManager.getInstance().traceOpened(signal);
        Iterable<@NonNull DataDrivenAnalysisModule> modules = TmfTraceUtils.getAnalysisModulesOfClass(experiment, DataDrivenAnalysisModule.class);
        modules.forEach(module -> {
            module.schedule();
            assertTrue(module.waitForCompletion());
        });
        // Get the view element from the file
        Element viewElement = TmfXmlUtils.getElementInFile(TmfXmlTestFiles.STATE_VALUE_FILE.getPath().toOSString(), TmfXmlStrings.TIME_GRAPH_VIEW, TRACE_VIEW_ID);
        assertNotNull(viewElement);
        ITimeGraphDataProvider<@NonNull TimeGraphEntryModel> timeGraphProvider = XmlDataProviderManager.getInstance().getTimeGraphProvider(experiment, viewElement);
        assertNotNull(timeGraphProvider);
        assertTrue(timeGraphProvider instanceof TmfTimeGraphCompositeDataProvider);
    } finally {
        if (trace != null) {
            trace.dispose();
        }
        if (trace2 != null) {
            trace2.dispose();
        }
        if (experiment != null) {
            experiment.dispose();
            TmfTraceManager.getInstance().traceClosed(new TmfTraceClosedSignal(this, experiment));
        }
    }
}
Also used : Element(org.w3c.dom.Element) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfTraceClosedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfTimeGraphCompositeDataProvider(org.eclipse.tracecompass.internal.tmf.core.model.timegraph.TmfTimeGraphCompositeDataProvider) TmfTrace(org.eclipse.tracecompass.tmf.core.trace.TmfTrace) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) TmfTraceOpenedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal) DataDrivenAnalysisModule(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule) Test(org.junit.Test)

Example 8 with DataDrivenAnalysisModule

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule in project tracecompass by tracecompass.

the class XmlUtilsTest method initializeModule.

/**
 * Initialize a new module using the xml file
 *
 * @param xmlAnalysisFile
 *            The xml file used to initialize the module
 * @return The module
 */
@NonNull
public static DataDrivenAnalysisModule initializeModule(TmfXmlTestFiles xmlAnalysisFile) {
    /* Initialize the state provider module */
    Document doc = xmlAnalysisFile.getXmlDocument();
    assertNotNull(doc);
    List<@NonNull Element> childElements = TmfXmlUtils.getChildElements(doc.getDocumentElement(), TmfXmlStrings.STATE_PROVIDER);
    assertFalse(childElements.isEmpty());
    Element element = childElements.get(0);
    String moduleId = element.getAttribute(TmfXmlStrings.ID);
    TmfXmlStateProviderCu compile = TmfXmlStateProviderCu.compile(xmlAnalysisFile.getFile().toPath(), moduleId);
    assertNotNull(compile);
    DataDrivenAnalysisModule module = new DataDrivenAnalysisModule(moduleId, compile);
    return module;
}
Also used : TmfXmlStateProviderCu(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateProviderCu) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) DataDrivenAnalysisModule(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 9 with DataDrivenAnalysisModule

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule in project tracecompass by tracecompass.

the class TmfXmlConditionTest method testConditionsValidation.

/**
 * Test basic conditions on a state provider analysis
 */
@Test
public void testConditionsValidation() {
    ITmfTrace trace = XmlUtilsTest.initializeTrace(testTrace2);
    DataDrivenAnalysisModule module = XmlUtilsTest.initializeModule(TmfXmlTestFiles.CONDITION_FILE);
    try {
        module.setTrace(trace);
        module.schedule();
        module.waitForCompletion();
        ITmfStateSystem ss = module.getStateSystem();
        assertNotNull(ss);
        List<Integer> quarks = ss.getQuarks("*");
        assertEquals(5, quarks.size());
        for (Integer quark : quarks) {
            String name = ss.getAttributeName(quark);
            switch(name) {
                case "test":
                    {
                        final int[] expectedStarts = { 1, 5, 7 };
                        ITmfStateValue[] expectedValues = { TmfStateValue.newValueLong(1), TmfStateValue.newValueLong(0) };
                        XmlUtilsTest.verifyStateIntervals("test", ss, quark, expectedStarts, expectedValues);
                    }
                    break;
                case "test1":
                    {
                        final int[] expectedStarts = { 1, 3, 7, 7 };
                        ITmfStateValue[] expectedValues = { TmfStateValue.nullValue(), TmfStateValue.newValueLong(0), TmfStateValue.newValueLong(1) };
                        XmlUtilsTest.verifyStateIntervals("test1", ss, quark, expectedStarts, expectedValues);
                    }
                    break;
                case "checkpoint":
                    {
                        final int[] expectedStarts = { 1, 5, 7, 7 };
                        ITmfStateValue[] expectedValues = { TmfStateValue.newValueLong(0), TmfStateValue.newValueLong(1), TmfStateValue.newValueLong(0) };
                        XmlUtilsTest.verifyStateIntervals("checkpoint", ss, quark, expectedStarts, expectedValues);
                    }
                    break;
                case "and_three_operands":
                    {
                        final int[] expectedStarts = { 1, 5, 7, 7 };
                        ITmfStateValue[] expectedValues = { TmfStateValue.newValueLong(1), TmfStateValue.newValueLong(0), TmfStateValue.newValueLong(1) };
                        XmlUtilsTest.verifyStateIntervals("and_three_operands", ss, quark, expectedStarts, expectedValues);
                    }
                    break;
                case "not_operand":
                    {
                        final int[] expectedStarts = { 1, 5, 7, 7 };
                        ITmfStateValue[] expectedValues = { TmfStateValue.newValueLong(0), TmfStateValue.newValueLong(1), TmfStateValue.newValueLong(0) };
                        XmlUtilsTest.verifyStateIntervals("not_operand", ss, quark, expectedStarts, expectedValues);
                    }
                    break;
                default:
                    fail("Wrong attribute name " + name);
                    break;
            }
        }
    } catch (TmfAnalysisException | AttributeNotFoundException | StateSystemDisposedException e) {
        fail(e.getMessage());
    } finally {
        module.dispose();
        trace.dispose();
    }
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) TmfAnalysisException(org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException) DataDrivenAnalysisModule(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test) XmlUtilsTest(org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest)

Example 10 with DataDrivenAnalysisModule

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule in project tracecompass by tracecompass.

the class XmlModuleTestBase method createModule.

private void createModule(@NonNull Element element) {
    String analysisId = element.getAttribute(TmfXmlStrings.ID);
    switch(getAnalysisNodeName()) {
        case TmfXmlStrings.PATTERN:
            TmfXmlPatternCu patternCu = TmfXmlPatternCu.compile(element);
            assertNotNull(patternCu);
            fModule = new XmlPatternAnalysis(analysisId, patternCu);
            fModule.setName(getName(element));
            break;
        case TmfXmlStrings.STATE_PROVIDER:
            TmfXmlStateProviderCu compile = TmfXmlStateProviderCu.compile(getXmlFile().getFile().toPath(), analysisId);
            assertNotNull(compile);
            fModule = new DataDrivenAnalysisModule(analysisId, compile);
            fModule.setName(getName(element));
            break;
        default:
            fail();
    }
}
Also used : TmfXmlPatternCu(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlPatternCu) TmfXmlStateProviderCu(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateProviderCu) XmlPatternAnalysis(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternAnalysis) DataDrivenAnalysisModule(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule)

Aggregations

DataDrivenAnalysisModule (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule)19 Test (org.junit.Test)12 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)10 XmlUtilsTest (org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest)10 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)8 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)7 TmfXmlStateProviderCu (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateProviderCu)5 Element (org.w3c.dom.Element)5 TmfXmlPatternCu (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlPatternCu)4 XmlPatternAnalysis (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternAnalysis)4 TmfAnalysisException (org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException)3 TmfTimeGraphCompositeDataProvider (org.eclipse.tracecompass.internal.tmf.core.model.timegraph.TmfTimeGraphCompositeDataProvider)2 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)2 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)2 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)2 TimeGraphEntryModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel)2 TmfTraceClosedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal)2 TmfTraceOpenedSignal (org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal)2 TmfTrace (org.eclipse.tracecompass.tmf.core.trace.TmfTrace)2 TmfExperiment (org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment)2