Search in sources :

Example 21 with TmfAnalysisException

use of org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException in project tracecompass by tracecompass.

the class AnalysisModuleTest method testDependentAnalyses.

/**
 * Test the {@link TmfAbstractAnalysisModule} also executes the dependent
 * analyses
 */
@Test
public void testDependentAnalyses() {
    ITmfTrace trace = TmfTestTrace.A_TEST_10K.getTrace();
    int paramAndResult = 5;
    /* Setup the dependent module */
    final String suffix = " dep";
    final TestAnalysis depModule = new TestAnalysis() {

        @Override
        protected boolean executeAnalysis(IProgressMonitor monitor) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                return false;
            }
            return super.executeAnalysis(monitor);
        }
    };
    depModule.setName(MODULE_GENERIC_NAME + suffix);
    depModule.setId(MODULE_GENERIC_ID + suffix);
    depModule.addParameter(TestAnalysis.PARAM_TEST);
    depModule.setParameter(TestAnalysis.PARAM_TEST, paramAndResult);
    /* Prepare the main analysis with a dependent analysis */
    TestAnalysis module = new TestAnalysis() {

        @Override
        protected Iterable<IAnalysisModule> getDependentAnalyses() {
            Set<IAnalysisModule> modules = new HashSet<>();
            modules.add(depModule);
            return modules;
        }
    };
    module.setName(MODULE_GENERIC_NAME);
    module.setId(MODULE_GENERIC_ID);
    module.addParameter(TestAnalysis.PARAM_TEST);
    module.setParameter(TestAnalysis.PARAM_TEST, paramAndResult);
    try {
        assertTrue(depModule.setTrace(trace));
        assertTrue(module.setTrace(trace));
    } catch (TmfAnalysisException e) {
        fail(e.getMessage());
    }
    /* Verify none of the module has run */
    assertEquals(0, module.getAnalysisOutput());
    assertEquals(0, depModule.getAnalysisOutput());
    module.schedule();
    assertTrue(module.waitForCompletion());
    assertEquals(paramAndResult, module.getAnalysisOutput());
    /* Make sure the dependent analysis has run and completed */
    assertEquals(paramAndResult, depModule.getAnalysisOutput());
    /* Check the dependency level of both analyses */
    assertEquals(0, depModule.getDependencyLevel());
    assertEquals(1, module.getDependencyLevel());
    module.dispose();
    depModule.dispose();
    trace.dispose();
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TestAnalysis(org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestAnalysis) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IAnalysisModule(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule) TmfAnalysisException(org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with TmfAnalysisException

use of org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException in project tracecompass by tracecompass.

the class AnalysisModuleTest method testSetTraceTwice.

/**
 * Test the {@link TmfAbstractAnalysisModule#setTrace(ITmfTrace)} method
 * with wrong trace
 */
@Test
public void testSetTraceTwice() {
    IAnalysisModule module = new TestAnalysis();
    module.setName(MODULE_GENERIC_NAME);
    module.setId(MODULE_GENERIC_ID);
    try {
        assertTrue(module.setTrace(TmfTestTrace.A_TEST_10K.getTrace()));
    } catch (TmfAnalysisException e) {
        fail();
    }
    TmfAnalysisException exception = null;
    try {
        module.setTrace(TmfTestTrace.A_TEST_10K.getTrace());
    } catch (TmfAnalysisException e) {
        exception = e;
    }
    assertNotNull(exception);
    module.dispose();
}
Also used : TestAnalysis(org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestAnalysis) IAnalysisModule(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule) TmfAnalysisException(org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException) Test(org.junit.Test)

Example 23 with TmfAnalysisException

use of org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException in project tracecompass by tracecompass.

the class AnalysisModuleTest method testMultipleDependencies.

/**
 * Test that the dependency level is consistent with a case where
 * B depends on A, and C depends on A and B
 */
@Test
public void testMultipleDependencies() {
    ITmfTrace trace = TmfTestTrace.A_TEST_10K.getTrace();
    /* Prepare module A with no dependency */
    IAnalysisModule moduleA = new TestAnalysis();
    moduleA.setName(MODULE_GENERIC_NAME);
    moduleA.setId(MODULE_GENERIC_ID);
    moduleA.addParameter(TestAnalysis.PARAM_TEST);
    moduleA.setParameter(TestAnalysis.PARAM_TEST, 1);
    /* Prepare module B depending on A */
    String suffix = " B";
    IAnalysisModule moduleB = new TestAnalysis() {

        @Override
        protected Iterable<IAnalysisModule> getDependentAnalyses() {
            return ImmutableSet.of(moduleA);
        }
    };
    moduleB.setName(MODULE_GENERIC_NAME + suffix);
    moduleB.setId(MODULE_GENERIC_ID + suffix);
    moduleB.addParameter(TestAnalysis.PARAM_TEST);
    moduleB.setParameter(TestAnalysis.PARAM_TEST, 1);
    /* Prepare module C depending on A and B */
    suffix = " C";
    IAnalysisModule moduleC = new TestAnalysis() {

        @Override
        protected Iterable<IAnalysisModule> getDependentAnalyses() {
            return ImmutableSet.of(moduleA, moduleB);
        }
    };
    moduleC.setName(MODULE_GENERIC_NAME + suffix);
    moduleC.setId(MODULE_GENERIC_ID + suffix);
    moduleC.addParameter(TestAnalysis.PARAM_TEST);
    moduleC.setParameter(TestAnalysis.PARAM_TEST, 1);
    try {
        assertTrue(moduleA.setTrace(trace));
        assertTrue(moduleB.setTrace(trace));
        assertTrue(moduleC.setTrace(trace));
    } catch (TmfAnalysisException e) {
        fail(e.getMessage());
    }
    moduleC.schedule();
    assertTrue(moduleC.waitForCompletion());
    /* Check the dependency level of the analyses */
    assertEquals(0, moduleA.getDependencyLevel());
    assertEquals(1, moduleB.getDependencyLevel());
    assertEquals(3, moduleC.getDependencyLevel());
    moduleA.dispose();
    moduleB.dispose();
    moduleC.dispose();
    trace.dispose();
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TestAnalysis(org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestAnalysis) IAnalysisModule(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule) TmfAnalysisException(org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException) Test(org.junit.Test)

Example 24 with TmfAnalysisException

use of org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException in project tracecompass by tracecompass.

the class AnalysisModuleTest method testHelper.

/**
 * Test the {@link TmfTestHelper#executeAnalysis(IAnalysisModule)} method
 */
@Test
public void testHelper() {
    TestAnalysis module = setUpAnalysis();
    try {
        assertTrue(module.setTrace(TmfTestTrace.A_TEST_10K.getTrace()));
    } catch (TmfAnalysisException e) {
        fail(e.getMessage());
    }
    module.setParameter(TestAnalysis.PARAM_TEST, 1);
    boolean res = TmfTestHelper.executeAnalysis(module);
    assertTrue(res);
    module.setParameter(TestAnalysis.PARAM_TEST, 0);
    res = TmfTestHelper.executeAnalysis(module);
    assertFalse(res);
    module.dispose();
}
Also used : TestAnalysis(org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestAnalysis) TmfAnalysisException(org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException) Test(org.junit.Test)

Example 25 with TmfAnalysisException

use of org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException in project tracecompass by tracecompass.

the class AnalysisParameterProviderTest method testProviderTmfTrace.

/**
 * Test that the provider's value is used
 */
@Test
public void testProviderTmfTrace() {
    ITmfTrace trace = TmfTestTrace.A_TEST_10K.getTrace();
    /* Make sure the value is set to null */
    IAnalysisModuleHelper helper = getModuleHelper(MODULE_ID);
    assertNotNull(helper);
    IAnalysisModule module = null;
    IAnalysisModule module2 = null;
    try {
        module = helper.newModule(trace);
        assertNotNull(module);
        assertEquals(10, module.getParameter(TestAnalysis.PARAM_TEST));
        /* Change the value of the parameter in the provider */
        Set<IAnalysisParameterProvider> providers = TmfAnalysisManager.getParameterProvidersForModule(module, trace);
        assertEquals(1, providers.size());
        TestAnalysisParameterProvider provider = (TestAnalysisParameterProvider) providers.iterator().next();
        provider.setValue(5);
        assertEquals(5, module.getParameter(TestAnalysis.PARAM_TEST));
        /* Make sure the parameter provider is the same instance for another module */
        module2 = helper.newModule(trace);
        assertNotNull(module2);
        assertTrue(module != module2);
        providers = TmfAnalysisManager.getParameterProvidersForModule(module2, trace);
        assertEquals(1, providers.size());
        TestAnalysisParameterProvider provider2 = (TestAnalysisParameterProvider) providers.iterator().next();
        assertTrue(provider == provider2);
    } catch (TmfAnalysisException e) {
        fail(e.getMessage());
    } finally {
        if (module != null) {
            module.dispose();
        }
        if (module2 != null) {
            module2.dispose();
        }
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TestAnalysisParameterProvider(org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestAnalysisParameterProvider) IAnalysisParameterProvider(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisParameterProvider) IAnalysisModule(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule) TmfAnalysisException(org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException) IAnalysisModuleHelper(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper) Test(org.junit.Test)

Aggregations

TmfAnalysisException (org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException)44 Test (org.junit.Test)21 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)15 IAnalysisModule (org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule)14 TestAnalysis (org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestAnalysis)9 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)8 TmfTraceException (org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException)8 File (java.io.File)7 LttngKernelTrace (org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace)6 IStatus (org.eclipse.core.runtime.IStatus)5 Performance (org.eclipse.test.performance.Performance)5 PerformanceMeter (org.eclipse.test.performance.PerformanceMeter)5 BeforeClass (org.junit.BeforeClass)5 CtfTmfTrace (org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace)4 Nullable (org.eclipse.jdt.annotation.Nullable)3 DataDrivenAnalysisModule (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule)3 XmlUtilsTest (org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest)3 IAnalysisModuleHelper (org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2