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();
}
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();
}
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();
}
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();
}
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();
}
}
}
Aggregations