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