Hello!

I am try to get the branch coverage with Jacoco recently.

However, there are some problems about the probes value.

So I hope to seek your advices.

For example:

If(a>0&&b>0&&c>0){
        d=0;
}

I think jacoco will insert 4 probes when [a>0 is false, b>0 is false, c>0 is 
false and, all three are true] in the class file.

I saw the strategy to insert probes in 
http://www.eclemma.org/jacoco/trunk/doc/flow.html

I think the first three probes inside the if() should be  JUMP (conditional) 
and the other should be SEQUENCE.

And the problem come,

The branch coverage I think can be divided to three types: covered and 
true,covered and false,not covered.

When all of the initial value of the four probes are 0,

And my input is: a=1, b=1, c=0;

The probes should become [1,1,0,0].Which “c>0” is covered but false.

But when my input is: a=1, b=0 ,c=0,

The probes should become [1,0,0,0].Which “c>0” is not covered.

The probes about “c>0” are both 0, but the meanning of it are different.

I think the method that Jacoco deal with the probes is separate.

So if I want to know the third 0 here is not covered or covered but false, the 
only way is to analyze the 4 probes together.To find “b>0” is true or false to 
determine  “c>0” is covered or not covered?

Or there are some convenient method to distinguish them?

Hope for your suggestions.

Thank you!







发件人: Marc Hoffmann
发送时间: 2017年11月16日 1:17
收件人: [email protected]
主题: Re: 答复: [java code coverage] Can we know the details about the 
branchcoverage by JaCoCo?

Hi,
your right: JaCoCo inserts probes in a way that we know the execution status of 
every branch on the byte code level.
The tricky part is to map this back to source code. Remember: JaCoCo does not 
use source code for analysis. If jump targets are in a different line, this 
might in fact give an idea to the user ("jump target to line 7 not executed").
If we have multiple conditions in the same line things get more tricky:
  a() && b() && c()
How would we give users some hint in this situation?
Cheers,
-marc
 
 
On 2017-11-15 11:02, scarlet wrote:
Thank you for your answer!
 
But I am confused with a problem: We can get the probs information(in executing 
data)
and the class file. So if I write something to find where is the probs in the 
class file,
would I get the information that I want?
 
For example, here is the code:
 
public int greaterThen(int intOne, int intTwo) {
    if (intOne > intTwo) {
        return 0;
    } else {
        return 1;
    }
}
 
And when it comes to bytecode:
 
0: iload_1
1: iload_2
2: if_icmple     7
5: iconst_0
6: ireturn
7: iconst_1
8: ireturn
 
If JaCoCo insert the prob between the 5 and 6 , for example prob[5] in the 
executing data
 
Without considering  the efficiency, can I finally check the class file and 
find the prob[5] is 
between the 5 and 6, then backstepping to find that the java code execute 
"return 0" 
and we miss the branch"intOne<=intTwo" ?
 
Just an idea, and hope for your reply.
 
Thank you!
 
 
 
发件人: Marc Hoffmann
发送时间: 2017年11月14日 19:46
收件人: [email protected]
主题: Re: [java code coverage] Can we know the details about the branchcoverage 
by JaCoCo?
 
Hi,
 
short answer: JaCoCo does not provide this information.
 
JaCoCo is fully based on Java class files (bytecode). The only mapping 
back to source are the line numbers contained with the debug 
information. Within a line we cannot differentiate what exactly has been 
executed.
 
In OpenJDK there is a experimental flag which provides more fine-grain 
mapping. We created a POC using this extra information:
 
   https://github.com/jacoco/jacoco/pull/317
 
As a workaround you might break complex conditions in multiple lines.
 
Regards,
-marc
 
 
On 2017-11-14 09:19, [email protected] wrote:
> Hello.
> 
> I found that if a branch was missed, only a yellow bolck was be shown
> and said "1 of 2 branches missed." or other words like this.
> 
> However, could we know some details about it? Such as "1 of 4 branches
> missed. True/False/True/True"?
> 
> In other words, is there any possiblity to konw which side of the
> branch have been executed?
> 
> Thanks!
 
-- 
You received this message because you are subscribed to a topic in the Google 
Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/jacoco/h0VJYpAeb9U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/7056b1568c1f62336375458442a4b5b6%40mountainminds.com.
For more options, visit https://groups.google.com/d/optout.
 
 
-- 
You received this message because you are subscribed to the Google Groups 
"JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/5a0c109f.83c4620a.6903b.9121%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.
 
-- 
You received this message because you are subscribed to a topic in the Google 
Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/jacoco/h0VJYpAeb9U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/ef42ed297374d4672ae115a793bd63ab%40mountainminds.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/5a530d1a.4c5e240a.ea2cf.7ec1%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to