Search in sources :

Example 1 with SessionInfoStore

use of org.jacoco.core.data.SessionInfoStore in project dspot by STAMP-project.

the class JacocoListener method testStarted.

@Override
public void testStarted(Description description) throws Exception {
    this.executionData = new ExecutionDataStore();
    this.sessionInfos = new SessionInfoStore();
    data.setSessionId(description.getMethodName());
    data.collect(executionData, sessionInfos, true);
}
Also used : ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) SessionInfoStore(org.jacoco.core.data.SessionInfoStore)

Example 2 with SessionInfoStore

use of org.jacoco.core.data.SessionInfoStore in project jacoco by jacoco.

the class TcpConnectionTest method readAndAssertData.

private void readAndAssertData() throws IOException {
    final RemoteControlReader remoteReader = new RemoteControlReader(mockConnection.getSocketB().getInputStream());
    final ExecutionDataStore execStore = new ExecutionDataStore();
    remoteReader.setExecutionDataVisitor(execStore);
    final SessionInfoStore infoStore = new SessionInfoStore();
    remoteReader.setSessionInfoVisitor(infoStore);
    assertTrue(remoteReader.read());
    final List<SessionInfo> infos = infoStore.getInfos();
    assertEquals(1, infos.size());
    assertEquals("stubid", infos.get(0).getId());
    assertEquals("Foo", execStore.get(0x12345678).getName());
}
Also used : ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) SessionInfo(org.jacoco.core.data.SessionInfo) SessionInfoStore(org.jacoco.core.data.SessionInfoStore) RemoteControlReader(org.jacoco.core.runtime.RemoteControlReader)

Example 3 with SessionInfoStore

use of org.jacoco.core.data.SessionInfoStore in project jacoco by jacoco.

the class TcpConnectionTest method testRemoteReset.

@Test
public void testRemoteReset() throws Exception {
    data.getExecutionData(Long.valueOf(123), "Foo", 1).getProbes()[0] = true;
    final RemoteControlWriter remoteWriter = new RemoteControlWriter(mockConnection.getSocketB().getOutputStream());
    final TcpConnection con = new TcpConnection(mockConnection.getSocketA(), data);
    con.init();
    final Future<Void> f = executor.submit(new Callable<Void>() {

        public Void call() throws Exception {
            con.run();
            return null;
        }
    });
    assertBlocks(f);
    remoteWriter.visitDumpCommand(false, true);
    final RemoteControlReader remoteReader = new RemoteControlReader(mockConnection.getSocketB().getInputStream());
    final ExecutionDataStore execStore = new ExecutionDataStore();
    remoteReader.setExecutionDataVisitor(execStore);
    final SessionInfoStore infoStore = new SessionInfoStore();
    remoteReader.setSessionInfoVisitor(infoStore);
    assertTrue(remoteReader.read());
    assertTrue(infoStore.getInfos().isEmpty());
    assertTrue(execStore.getContents().isEmpty());
    assertFalse(data.getExecutionData(Long.valueOf(123), "Foo", 1).getProbes()[0]);
    con.close();
    f.get();
}
Also used : RemoteControlWriter(org.jacoco.core.runtime.RemoteControlWriter) ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) SessionInfoStore(org.jacoco.core.data.SessionInfoStore) IOException(java.io.IOException) RemoteControlReader(org.jacoco.core.runtime.RemoteControlReader) Test(org.junit.Test)

Example 4 with SessionInfoStore

use of org.jacoco.core.data.SessionInfoStore in project jacoco by jacoco.

the class CoreTutorial method execute.

/**
 * Run this example.
 *
 * @throws Exception
 *             in case of errors
 */
public void execute() throws Exception {
    final String targetName = TestTarget.class.getName();
    // For instrumentation and runtime we need a IRuntime instance
    // to collect execution data:
    final IRuntime runtime = new LoggerRuntime();
    // The Instrumenter creates a modified version of our test target class
    // that contains additional probes for execution data recording:
    final Instrumenter instr = new Instrumenter(runtime);
    InputStream original = getTargetClass(targetName);
    final byte[] instrumented = instr.instrument(original, targetName);
    original.close();
    // Now we're ready to run our instrumented class and need to startup the
    // runtime first:
    final RuntimeData data = new RuntimeData();
    runtime.startup(data);
    // In this tutorial we use a special class loader to directly load the
    // instrumented class definition from a byte[] instances.
    final MemoryClassLoader memoryClassLoader = new MemoryClassLoader();
    memoryClassLoader.addDefinition(targetName, instrumented);
    final Class<?> targetClass = memoryClassLoader.loadClass(targetName);
    // Here we execute our test target class through its Runnable interface:
    final Runnable targetInstance = (Runnable) targetClass.newInstance();
    targetInstance.run();
    // At the end of test execution we collect execution data and shutdown
    // the runtime:
    final ExecutionDataStore executionData = new ExecutionDataStore();
    final SessionInfoStore sessionInfos = new SessionInfoStore();
    data.collect(executionData, sessionInfos, false);
    runtime.shutdown();
    // Together with the original class definition we can calculate coverage
    // information:
    final CoverageBuilder coverageBuilder = new CoverageBuilder();
    final Analyzer analyzer = new Analyzer(executionData, coverageBuilder);
    original = getTargetClass(targetName);
    analyzer.analyzeClass(original, targetName);
    original.close();
    // Let's dump some metrics and line coverage information:
    for (final IClassCoverage cc : coverageBuilder.getClasses()) {
        out.printf("Coverage of class %s%n", cc.getName());
        printCounter("instructions", cc.getInstructionCounter());
        printCounter("branches", cc.getBranchCounter());
        printCounter("lines", cc.getLineCounter());
        printCounter("methods", cc.getMethodCounter());
        printCounter("complexity", cc.getComplexityCounter());
        for (int i = cc.getFirstLine(); i <= cc.getLastLine(); i++) {
            out.printf("Line %s: %s%n", Integer.valueOf(i), getColor(cc.getLine(i).getStatus()));
        }
    }
}
Also used : RuntimeData(org.jacoco.core.runtime.RuntimeData) LoggerRuntime(org.jacoco.core.runtime.LoggerRuntime) InputStream(java.io.InputStream) CoverageBuilder(org.jacoco.core.analysis.CoverageBuilder) Analyzer(org.jacoco.core.analysis.Analyzer) IRuntime(org.jacoco.core.runtime.IRuntime) ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) IClassCoverage(org.jacoco.core.analysis.IClassCoverage) Instrumenter(org.jacoco.core.instr.Instrumenter) SessionInfoStore(org.jacoco.core.data.SessionInfoStore)

Example 5 with SessionInfoStore

use of org.jacoco.core.data.SessionInfoStore in project jacoco by jacoco.

the class InstrumentingLoader method collect.

public ExecutionDataStore collect() {
    final ExecutionDataStore store = new ExecutionDataStore();
    data.collect(store, new SessionInfoStore(), false);
    runtime.shutdown();
    return store;
}
Also used : ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) SessionInfoStore(org.jacoco.core.data.SessionInfoStore)

Aggregations

ExecutionDataStore (org.jacoco.core.data.ExecutionDataStore)12 SessionInfoStore (org.jacoco.core.data.SessionInfoStore)12 Analyzer (org.jacoco.core.analysis.Analyzer)3 CoverageBuilder (org.jacoco.core.analysis.CoverageBuilder)3 IClassCoverage (org.jacoco.core.analysis.IClassCoverage)3 SessionInfo (org.jacoco.core.data.SessionInfo)3 RemoteControlReader (org.jacoco.core.runtime.RemoteControlReader)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 IMethodCoverage (org.jacoco.core.analysis.IMethodCoverage)2 RemoteControlWriter (org.jacoco.core.runtime.RemoteControlWriter)2 RuntimeData (org.jacoco.core.runtime.RuntimeData)2 TestListener (fr.inria.stamp.test.listener.TestListener)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 MalformedURLException (java.net.MalformedURLException)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 URL (java.net.URL)1