Search in sources :

Example 16 with DataDrivenAnalysisModule

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

the class XmlDataProviderManagerTest method testExperiment.

/**
 * Test getting the XML data provider for an experiment, with an analysis that
 * applies to an experiment
 */
@Test
public void testExperiment() {
    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.EXPERIMENT.getPath().toOSString(), TmfXmlStrings.TIME_GRAPH_VIEW, EXPERIMENT_VIEW_ID);
        assertNotNull(viewElement);
        ITimeGraphDataProvider<@NonNull TimeGraphEntryModel> timeGraphProvider = XmlDataProviderManager.getInstance().getTimeGraphProvider(experiment, viewElement);
        assertNotNull(timeGraphProvider);
        assertFalse(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 17 with DataDrivenAnalysisModule

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

the class TmfXmlDoubleTest method testConditionsValidation.

/**
 * Test the state system on a double
 *
 * @throws TmfAnalysisException
 *             if it happens, we fail
 * @throws StateSystemDisposedException
 *             if it happens, we fail
 */
@Test
public void testConditionsValidation() throws TmfAnalysisException, StateSystemDisposedException {
    ITmfTrace trace = XmlUtilsTest.initializeTrace(testTrace3);
    DataDrivenAnalysisModule module = XmlUtilsTest.initializeModule(TmfXmlTestFiles.DOUBLES_FILE);
    module.setTrace(trace);
    module.schedule();
    module.waitForCompletion();
    ITmfStateSystem ss = module.getStateSystem();
    assertNotNull(ss);
    List<ITmfStateInterval> val = ss.queryFullState(2);
    assertEquals(3.141592, val.get(0).getStateValue().unboxDouble(), Double.MIN_VALUE);
    val = ss.queryFullState(4);
    assertEquals(2.71828, val.get(0).getStateValue().unboxDouble(), Double.MIN_VALUE);
    val = ss.queryFullState(6);
    assertEquals(1.41421, val.get(0).getStateValue().unboxDouble(), Double.MIN_VALUE);
    trace.dispose();
    module.dispose();
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) 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 18 with DataDrivenAnalysisModule

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

the class XmlProviderTestBase method setupTest.

/**
 * Setup the test fields
 */
@Before
public void setupTest() {
    /* Initialize the trace */
    ITmfTrace trace = CtfTmfTestTraceUtils.getTrace(getTestTrace());
    fTrace = trace;
    /* Initialize the state provider module */
    Document doc = getXmlFile().getXmlDocument();
    assertNotNull(doc);
    /* get State Providers modules */
    NodeList analysisNodes = doc.getElementsByTagName(getAnalysisNodeName());
    Element node = (Element) analysisNodes.item(0);
    String analysisId = node.getAttribute(TmfXmlStrings.ID);
    switch(getAnalysisNodeName()) {
        case TmfXmlStrings.PATTERN:
            TmfXmlPatternCu patternCu = TmfXmlPatternCu.compile(node);
            assertNotNull(patternCu);
            fModule = new XmlPatternAnalysis(analysisId, patternCu);
            break;
        case TmfXmlStrings.STATE_PROVIDER:
            TmfXmlStateProviderCu compile = TmfXmlStateProviderCu.compile(getXmlFile().getFile().toPath(), analysisId);
            assertNotNull(compile);
            fModule = new DataDrivenAnalysisModule(analysisId, compile);
            break;
        default:
            fail();
    }
    String moduleId = node.getAttribute(TmfXmlStrings.ID);
    assertNotNull(moduleId);
    fModule.setId(moduleId);
    try {
        fModule.setTrace(trace);
        fModule.schedule();
        fModule.waitForCompletion();
    } catch (TmfAnalysisException e) {
        fail("Cannot set trace " + e.getMessage());
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfXmlPatternCu(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlPatternCu) TmfXmlStateProviderCu(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateProviderCu) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) TmfAnalysisException(org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException) XmlPatternAnalysis(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternAnalysis) Document(org.w3c.dom.Document) DataDrivenAnalysisModule(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule) Before(org.junit.Before)

Example 19 with DataDrivenAnalysisModule

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

the class StateProviderModelTest method testEventName.

/**
 * Test an increment of one, for an event name attribute
 */
@Test
public void testEventName() {
    ITmfTrace trace = XmlUtilsTest.initializeTrace(testTrace1);
    DataDrivenAnalysisModule module = XmlUtilsTest.initializeModule(TmfXmlTestFiles.ATTRIBUTE_FILE);
    try {
        module.setTrace(trace);
        module.schedule();
        module.waitForCompletion();
        ITmfStateSystem ss = module.getStateSystem();
        assertNotNull(ss);
        List<Integer> quarks = ss.getQuarks("*");
        assertEquals(2, quarks.size());
        for (Integer quark : quarks) {
            String name = ss.getAttributeName(quark);
            switch(name) {
                case "test":
                    {
                        final int[] expectedStarts = { 1, 5, 7 };
                        ITmfStateValue[] expectedValues = { TmfStateValue.newValueInt(1), TmfStateValue.newValueInt(2) };
                        XmlUtilsTest.verifyStateIntervals("test", ss, quark, expectedStarts, expectedValues);
                    }
                    break;
                case "test1":
                    {
                        final int[] expectedStarts = { 1, 3, 7, 7 };
                        ITmfStateValue[] expectedValues = { TmfStateValue.nullValue(), TmfStateValue.newValueInt(1), TmfStateValue.newValueInt(2) };
                        XmlUtilsTest.verifyStateIntervals("test1", 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)

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