use of org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule in project tracecompass by tracecompass.
the class StateSystemAnalysisModuleTest method testFailBeforeInitialization.
/**
* Test a module that causes an exception before the module is initialized
*
* @throws TmfAnalysisException
* An exception when setting the trace
*/
@Test
public void testFailBeforeInitialization() throws TmfAnalysisException {
ITmfTrace trace = fTrace;
assertNotNull(trace);
/* This module will throw an exception before it is initialized */
TmfStateSystemAnalysisModule module = new TestStateSystemModule() {
@Override
protected boolean executeAnalysis(@Nullable IProgressMonitor monitor) {
throw new IllegalStateException("This exception happens before initialization");
}
};
try {
module.setTrace(trace);
module.schedule();
assertFalse(module.waitForInitialization());
assertFalse(module.waitForCompletion());
} finally {
module.dispose();
}
}
use of org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule in project tracecompass by tracecompass.
the class GenerateTestValues method test.
/**
* Test wrapper to run main properly
*
* @throws IOException
* If a file could not be created
* @throws TmfAnalysisException
* if the trace is not valid for this analysis
* @throws StateSystemDisposedException
* if the state system was disposed
*/
@Test
public void test() throws IOException, TmfAnalysisException, StateSystemDisposedException {
/* Prepare the files */
File logFile = File.createTempFile("TestValues", ".java");
try (PrintWriter writer = new PrintWriter(new FileWriter(logFile), true)) {
/* Build and query the state system */
final CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.TRACE2);
TmfStateSystemAnalysisModule module = new KernelAnalysisModule() {
@Override
protected String getSsFileName() {
return "test-values";
}
};
assertTrue(module.setTrace(trace));
module.setId("test-values");
module.schedule();
module.waitForCompletion();
ITmfStateSystem ssq = module.getStateSystem();
assertNotNull(ssq);
List<ITmfStateInterval> fullState = ssq.queryFullState(TARGET_TIMESTAMP);
/* Start printing the java file's contents */
writer.println("final class TestValues {");
writer.println();
writer.println(INDENT + "static int size = " + fullState.size() + ";");
writer.println();
/* Print the array contents */
writer.println(INDENT + "static long[] startTimes = {");
for (ITmfStateInterval interval : fullState) {
writer.println(INDENT + INDENT + String.valueOf(interval.getStartTime()) + "L,");
}
writer.println(INDENT + "};");
writer.println();
writer.println(INDENT + "static long[] endTimes = {");
for (ITmfStateInterval interval : fullState) {
writer.println(INDENT + INDENT + String.valueOf(interval.getEndTime()) + "L,");
}
writer.println(INDENT + "};");
writer.println();
writer.println(INDENT + "static ITmfStateValue[] values = {");
for (ITmfStateInterval interval : fullState) {
ITmfStateValue val = interval.getStateValue();
writer.print(INDENT + INDENT);
switch(val.getType()) {
case NULL:
writer.println("TmfStateValue.nullValue(),");
break;
case INTEGER:
writer.println("TmfStateValue.newValueInt(" + val.unboxInt() + "),");
break;
case LONG:
writer.println("TmfStateValue.newValueLong(" + val.unboxLong() + "),");
break;
case DOUBLE:
writer.println("TmfStateValue.newValueDouble(" + val.unboxDouble() + "),");
break;
case STRING:
writer.println("TmfStateValue.newValueString(\"" + val.unboxStr() + "\"),");
break;
case CUSTOM:
default:
writer.println(val.toString());
break;
}
}
writer.println(INDENT + "};");
writer.println("}");
writer.println();
module.dispose();
trace.dispose();
}
System.out.println("wrote to: " + logFile.getAbsolutePath());
}
use of org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule in project tracecompass by tracecompass.
the class StateSystemAnalysisModuleTest method testFaultyStateProvider.
/**
* Test the behavior of a state provider that causes a runtime exception at
* different moments of the analysis. The analyses should be marked as
* failed
*
* @throws TmfAnalysisException
* An exception when setting the trace
*/
@Test
public void testFaultyStateProvider() throws TmfAnalysisException {
ITmfTrace trace = fTrace;
assertNotNull(trace);
// Test failure on the last event
TmfStateSystemAnalysisModule module = new TestStateSystemModule() {
@Override
@NonNull
protected ITmfStateProvider createStateProvider() {
return new BreakingTest(trace, 7, "Expected exception: should be caught by the analysis itself");
}
};
try {
module.setTrace(trace);
module.schedule();
assertFalse(module.waitForCompletion());
} finally {
module.dispose();
}
// Test failure when the analysis the request finishes before the queue
// is full
module = new TestStateSystemModule() {
@Override
@NonNull
protected ITmfStateProvider createStateProvider() {
return new BreakingTest(trace, 5, "Expected exception: should be caught by either the analysis or the event request");
}
};
try {
module.setTrace(trace);
module.schedule();
assertFalse(module.waitForCompletion());
} finally {
module.dispose();
}
// Test failure when the queue should be full
module = new TestStateSystemModule() {
@Override
@NonNull
protected ITmfStateProvider createStateProvider() {
return new BreakingTest(trace, 1, "Expected exception: should be caught by the event request thread");
}
};
try {
module.setTrace(trace);
module.schedule();
assertFalse(module.waitForCompletion());
} finally {
module.dispose();
}
}
Aggregations