Hi,
not sure whether I understand you issue correctly. But the following
hints might help you to get a better understanding how JaCoCo works:
1) JaCoCo works on Java byte code only. The byte code created by the
compiler can look very different from what you see in source code. E.g.
conditions are typically inverted by the compiler, e.g.
if (a) {
doit()
}
typically becomes
if !a JUMPTO after
doit()
label after
To understand what JaCoCo sees please have a look at the bytecode.
2) There is no 1:1 relationship between probes and branches. JaCoCo
analyzes the control flow graph of the method and propagates execution
information through the CFG. This is described in the document you refer
to:
> If a probe has been executed we know that the corresponding edge has been
> visited. From this edge we can conclude to other preceding nodes and edges:
>
> * If a edge has been visited, we know that the source node of the this edge
> has been executed.
> * If a node has been executed and the node is the target of only one edge we
> know that this edge has been visited.
>
> Recursively applying these rules allows to determine the execution status of
> all instructions of a method - given that we have probes at the right
> positions
Regards,
-marc
On 2018-01-08 07:18, scarlet wrote:
> 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
>> [1].
>> 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
> [2].
> 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
> [3].
> For more options, visit https://groups.google.com/d/optout.
Links:
------
[1]
https://groups.google.com/d/msgid/jacoco/5a0c109f.83c4620a.6903b.9121%40mx.google.com?utm_medium=email&utm_source=footer
[2]
https://groups.google.com/d/msgid/jacoco/ef42ed297374d4672ae115a793bd63ab%40mountainminds.com?utm_medium=email&utm_source=footer
[3]
https://groups.google.com/d/msgid/jacoco/5a530d1a.4c5e240a.ea2cf.7ec1%40mx.google.com?utm_medium=email&utm_source=footer
--
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/22ee1312247c89719196c701a6e63349%40mountainminds.com.
For more options, visit https://groups.google.com/d/optout.