Skip to content

Commit

Permalink
Add line execution count capped by using Math.min
Browse files Browse the repository at this point in the history
  • Loading branch information
Badbond committed Jul 28, 2021
1 parent d19ea59 commit 853fbe7
Show file tree
Hide file tree
Showing 75 changed files with 895 additions and 567 deletions.
4 changes: 2 additions & 2 deletions jacoco/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
<configuration>
<rules>
<requireFilesSize>
<maxsize>4500000</maxsize>
<minsize>3400000</minsize>
<maxsize>5500000</maxsize>
<minsize>4400000</minsize>
<files>
<file>${project.build.directory}/jacoco-${qualified.bundle.version}.zip</file>
</files>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -266,14 +265,14 @@ public void setSessionId_should_modify_session_id() throws Exception {
@Test
public void reset_should_reset_probes() {
Agent agent = createAgent();
boolean[] probes = agent.getData()
int[] probes = agent.getData()
.getExecutionData(Long.valueOf(0x12345678), "Foo", 1)
.getProbes();
probes[0] = true;
probes[0] = 1;

agent.reset();

assertFalse(probes[0]);
assertEquals(0, probes[0]);
}

@Test
Expand All @@ -282,7 +281,7 @@ public void getExecutionData_should_return_probes_and_session_id()
Agent agent = createAgent();
agent.startup();
agent.getData().getExecutionData(Long.valueOf(0x12345678), "Foo", 1)
.getProbes()[0] = true;
.getProbes()[0] = 1;

byte[] data = agent.getExecutionData(true);

Expand All @@ -299,29 +298,29 @@ public void getExecutionData_should_reset_probes_when_enabled()
throws Exception {
Agent agent = createAgent();
agent.startup();
final boolean[] probes = agent.getData()
final int[] probes = agent.getData()
.getExecutionData(Long.valueOf(0x12345678), "Foo", 1)
.getProbes();
probes[0] = true;
probes[0] = 1;

agent.getExecutionData(true);

assertFalse(probes[0]);
assertEquals(0, probes[0]);
}

@Test
public void getExecutionData_should_not_reset_probes_when_disabled()
throws Exception {
Agent agent = createAgent();
agent.startup();
final boolean[] probes = agent.getData()
final int[] probes = agent.getData()
.getExecutionData(Long.valueOf(0x12345678), "Foo", 1)
.getProbes();
probes[0] = true;
probes[0] = 1;

agent.getExecutionData(false);

assertTrue(probes[0]);
assertEquals(1, probes[0]);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void testInvalidCommand() throws Exception {
@Test
public void testWriteExecutionData() throws Exception {
data.getExecutionData(Long.valueOf(0x12345678), "Foo", 42)
.getProbes()[0] = true;
.getProbes()[0] = 1;
data.setSessionId("stubid");

controller.writeExecutionData(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public Void call() throws Exception {
@Test
public void testRemoteDump() throws Exception {
data.getExecutionData(Long.valueOf(0x12345678), "Foo", 42)
.getProbes()[0] = true;
.getProbes()[0] = 1;
data.setSessionId("stubid");

final RemoteControlWriter remoteWriter = new RemoteControlWriter(
Expand Down Expand Up @@ -161,7 +161,7 @@ public Void call() throws Exception {
@Test
public void testLocalDump() throws Exception {
data.getExecutionData(Long.valueOf(0x12345678), "Foo", 42)
.getProbes()[0] = true;
.getProbes()[0] = 1;
data.setSessionId("stubid");

new RemoteControlWriter(mockConnection.getSocketB().getOutputStream());
Expand Down Expand Up @@ -217,8 +217,7 @@ private void readAndAssertData() throws IOException {

@Test
public void testRemoteReset() throws Exception {
data.getExecutionData(Long.valueOf(123), "Foo", 1)
.getProbes()[0] = true;
data.getExecutionData(Long.valueOf(123), "Foo", 1).getProbes()[0] = 1;

final RemoteControlWriter remoteWriter = new RemoteControlWriter(
mockConnection.getSocketB().getOutputStream());
Expand Down Expand Up @@ -250,7 +249,7 @@ public Void call() throws Exception {
assertTrue(infoStore.getInfos().isEmpty());
assertTrue(execStore.getContents().isEmpty());
assertFalse(data.getExecutionData(Long.valueOf(123), "Foo", 1)
.getProbes()[0]);
.getProbes()[0] > 0);

con.close();
f.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void testShutdownWithConnection() throws Exception {
@Test
public void testWriteExecutionData() throws Exception {
data.getExecutionData(Long.valueOf(0x12345678), "Foo", 42)
.getProbes()[0] = true;
.getProbes()[0] = 1;
data.setSessionId("stubid");

final Socket socket = serverSocket.connect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ private static synchronized RuntimeData getRuntimeData() {
* probe count for this class
* @return probe array instance for this class
*/
public static boolean[] getProbes(final long classid,
final String classname, final int probecount) {
public static int[] getProbes(final long classid, final String classname,
final int probecount) {
return getRuntimeData()
.getExecutionData(Long.valueOf(classid), classname, probecount)
.getProbes();
Expand Down
4 changes: 2 additions & 2 deletions org.jacoco.ant.test/src/org/jacoco/ant/CreateExecFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public static void main(String[] args) throws IOException {

out = new FileOutputStream(BASE_LOCATION + "nomatch.exec");
ExecutionDataWriter writer = new ExecutionDataWriter(out);
writer.visitClassExecution(new ExecutionData(0,
"org/jacoco/ant/TestTarget", new boolean[0]));
writer.visitClassExecution(
new ExecutionData(0, "org/jacoco/ant/TestTarget", new int[0]));
out.close();
}

Expand Down
7 changes: 7 additions & 0 deletions org.jacoco.build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
<asm.version>9.1</asm.version>
<ant.version>1.9.15</ant.version>
<args4j.version>2.0.28</args4j.version>
<fastutil.version>8.1.0</fastutil.version>
<junit.version>4.13.1</junit.version>
<googlecodeprettify.version>20100721</googlecodeprettify.version>

Expand Down Expand Up @@ -262,6 +263,12 @@
<artifactId>args4j</artifactId>
<version>${args4j.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/it.unimi.dsi/fastutil -->
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
<version>${fastutil.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private File createExecFile() throws IOException {
final ExecutionDataWriter writer = new ExecutionDataWriter(out);
writer.visitSessionInfo(new SessionInfo("testid", 1, 2));
writer.visitClassExecution(new ExecutionData(0x1234, "foo/MyClass",
new boolean[] { false, true, true }));
new int[] { 0, 1, 1 }));
out.close();
return f;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ private File createExecFile(String name) throws IOException {
File file = new File(tmp.getRoot(), name + ".exec");
final FileOutputStream execout = new FileOutputStream(file);
ExecutionDataWriter writer = new ExecutionDataWriter(execout);
writer.visitClassExecution(new ExecutionData(name.hashCode(), name,
new boolean[] { true }));
writer.visitClassExecution(
new ExecutionData(name.hashCode(), name, new int[] { 1 }));
execout.close();
return file;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ public void should_print_warning_when_exec_data_does_not_match()
final FileOutputStream execout = new FileOutputStream(exec);
ExecutionDataWriter writer = new ExecutionDataWriter(execout);
// Add probably invalid id for this test class:
writer.visitClassExecution(
new ExecutionData(0x123, getClass().getName().replace('.', '/'),
new boolean[] { true }));
writer.visitClassExecution(new ExecutionData(0x123,
getClass().getName().replace('.', '/'), new int[] { 1 }));
execout.close();

execute("report", exec.getAbsolutePath(), "--classfiles",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public void visitClassExecution(final ExecutionData data) {
out.println();
}

private int getHitCount(final boolean[] data) {
private int getHitCount(final int[] data) {
int count = 0;
for (final boolean hit : data) {
if (hit) {
for (final int hit : data) {
if (hit > 0) {
count++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.jacoco.core.analysis;

import static org.jacoco.core.internal.analysis.CounterImpl.COUNTER_0_1;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

Expand Down Expand Up @@ -45,9 +46,12 @@ public void setup() {
public void testCreateClassMissed() {
final MethodCoverageImpl method = new MethodCoverageImpl("doit", "()V",
null);
method.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 6);
method.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 7);
method.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 8);
method.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0,
6);
method.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0,
7);
method.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0,
8);
method.incrementMethodCounter();
addClass(123L, false, "Sample", null, method);

Expand Down Expand Up @@ -77,9 +81,9 @@ public void testCreateClassMissed() {
public void testCreateClassCovered() {
final MethodCoverageImpl method = new MethodCoverageImpl("doit", "()V",
null);
method.increment(CounterImpl.COUNTER_0_1, CounterImpl.COUNTER_0_0, 6);
method.increment(CounterImpl.COUNTER_0_1, CounterImpl.COUNTER_0_0, 7);
method.increment(CounterImpl.COUNTER_0_1, CounterImpl.COUNTER_0_0, 8);
method.increment(COUNTER_0_1, 1, CounterImpl.COUNTER_0_0, 6);
method.increment(COUNTER_0_1, 1, CounterImpl.COUNTER_0_0, 7);
method.increment(COUNTER_0_1, 1, CounterImpl.COUNTER_0_0, 8);
method.incrementMethodCounter();
addClass(123L, false, "Sample", null, method);

Expand Down Expand Up @@ -115,24 +119,28 @@ public void should_not_ignore_empty_classes() {
@Test(expected = IllegalStateException.class)
public void testDuplicateClassNameDifferent() {
MethodCoverageImpl method = new MethodCoverageImpl("doit", "()V", null);
method.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
method.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0,
3);
addClass(123L, false, "Sample", null, method);

// Add class with different id must fail:
method = new MethodCoverageImpl("doit", "()V", null);
method.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
method.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0,
3);
addClass(345L, false, "Sample", null, method);
}

@Test
public void testDuplicateClassNameIdentical() {
MethodCoverageImpl method = new MethodCoverageImpl("doit", "()V", null);
method.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
method.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0,
3);
addClass(123L, false, "Sample", null, method);

// Add class with same id:
method = new MethodCoverageImpl("doit", "()V", null);
method.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
method.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0,
3);
addClass(123L, false, "Sample", null, method);

// Second add must be ignored:
Expand All @@ -144,12 +152,14 @@ public void testDuplicateClassNameIdentical() {
public void testCreateSourceFile() {
final MethodCoverageImpl method1 = new MethodCoverageImpl("doit", "()V",
null);
method1.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
method1.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0,
3);
addClass(123L, false, "Sample", "Sample.java", method1);

final MethodCoverageImpl method2 = new MethodCoverageImpl("doit", "()V",
null);
method2.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 6);
method2.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0,
6);
addClass(234L, false, "Second", "Sample.java", method2);

final Collection<ISourceFileCoverage> sourcefiles = coverageBuilder
Expand All @@ -165,12 +175,14 @@ public void testCreateSourceFile() {
public void testCreateSourceFileDuplicateClassNameIdentical() {
final MethodCoverageImpl method1 = new MethodCoverageImpl("doit", "()V",
null);
method1.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
method1.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0,
3);
addClass(123L, false, "Sample", "Sample.java", method1);

final MethodCoverageImpl method2 = new MethodCoverageImpl("doit", "()V",
null);
method2.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
method2.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0,
3);
addClass(123L, false, "Sample", "Sample.java", method2);

final Collection<ISourceFileCoverage> sourcefiles = coverageBuilder
Expand All @@ -186,17 +198,20 @@ public void testCreateSourceFileDuplicateClassNameIdentical() {
public void testGetBundle() {
final MethodCoverageImpl method1 = new MethodCoverageImpl("doit", "()V",
null);
method1.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
method1.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0,
3);
addClass(1, false, "org/jacoco/examples/Sample1", null, method1);

final MethodCoverageImpl method2 = new MethodCoverageImpl("doit", "()V",
null);
method2.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 6);
method2.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0,
6);
addClass(2, false, "org/jacoco/examples/Sample2", null, method2);

final MethodCoverageImpl method3 = new MethodCoverageImpl("doit", "()V",
null);
method3.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 1);
method3.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0,
1);
addClass(3, false, "Sample3", null, method3);

IBundleCoverage bundle = coverageBuilder.getBundle("testbundle");
Expand Down Expand Up @@ -225,15 +240,15 @@ public void testGetBundle() {
@Test
public void testGetNoMatchClasses() {
MethodCoverageImpl m = new MethodCoverageImpl("doit", "()V", null);
m.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 1);
m.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0, 1);
addClass(1, true, "Sample1", null, m);

m = new MethodCoverageImpl("doit", "()V", null);
m.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 2);
m.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0, 2);
addClass(2, true, "Sample2", null, m);

m = new MethodCoverageImpl("doit", "()V", null);
m.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
m.increment(CounterImpl.COUNTER_1_0, 0, CounterImpl.COUNTER_0_0, 3);
addClass(3, false, "Sample3", null, m);

final Set<String> actual = getNames(
Expand Down
Loading

0 comments on commit 853fbe7

Please sign in to comment.