Search in sources :

Example 1 with TmfStateSystemAnalysisModule

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();
    }
}
Also used : TmfStateSystemAnalysisModule(org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TestStateSystemModule(org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestStateSystemModule) Nullable(org.eclipse.jdt.annotation.Nullable) Test(org.junit.Test)

Example 2 with TmfStateSystemAnalysisModule

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());
}
Also used : TmfStateSystemAnalysisModule(org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule) FileWriter(java.io.FileWriter) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) File(java.io.File) KernelAnalysisModule(org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule) ITmfStateValue(org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue) CtfTmfTrace(org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace) PrintWriter(java.io.PrintWriter) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test)

Example 3 with TmfStateSystemAnalysisModule

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();
    }
}
Also used : TmfStateSystemAnalysisModule(org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule) ITmfStateProvider(org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TestStateSystemModule(org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestStateSystemModule) NonNull(org.eclipse.jdt.annotation.NonNull) Test(org.junit.Test)

Aggregations

TmfStateSystemAnalysisModule (org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule)3 Test (org.junit.Test)3 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)2 TestStateSystemModule (org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestStateSystemModule)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 KernelAnalysisModule (org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule)1 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)1 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)1 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)1 ITmfStateProvider (org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider)1 CtfTmfTrace (org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace)1