Does hook really hinder jacoco's coverage analysis mechanism?

48 views
Skip to first unread message

Tool Ply

unread,
Jan 4, 2019, 11:43:23 AM1/4/19
to JaCoCo and EclEmma Users
I recently worked on applying jacoco on android app coverage. There is an interesting phenomenon. 

When I package the bytecodes both of the APK and my self-designed hook tool, which will hook getPackageInfo API of Android and return pre-set value in runtime, in a combined jar, and then instrumented by jacoco, jacoco will not respect that the coverage data came from that combined jar so that just get total method num but with no coverage.

Because it is high-cost for me to verify this, so I want to know does the hook affect jacoco's coverage analysis mechanism in principle?

Evgeny Mandrikov

unread,
Jan 4, 2019, 1:47:53 PM1/4/19
to JaCoCo and EclEmma Users
Hi,
Sorry, but at least for me (and probably will be for others) completely unclear what "hook" really means, what it really does, especially given that it is "self-designed", how/when instrumentation and analysis are actually performed, etc, etc.
Also, as you might have noticed from past discussions, note that small JaCoCo Team (primary responders in this ML) works on project in spare time, has very basic knowledge of Android specifics,
and does not provide integration with Android directly (Java bytecode is not Dalvik bytecode, Java agents are not available on Android) - third-party integrations use our APIs.
Finally if for you it has "high-cost to verify", then, summarizing all above, for us even attempts to guess will have much higher cost.
Please also note that unlike "self-designed hook", all code and documentation about JaCoCo are available publicly.

The best way to get attention in investigation of your "interesting phenomenon" - is to provide complete, runnable, debuggable and verifiable by others example of this phenomenon.


However speaking about "total method num but with no coverage" :

if there is no information about lines at all, then as was already said in https://groups.google.com/d/msg/jacoco/d-30r6hVrV4/d_3Dk3GdCgAJ :
quoting FAQ ( https://www.jacoco.org/jacoco/trunk/doc/faq.html ): "Class files must be compiled with debug information to contain line numbers."

if information about lines is there and no information about coverage at all, then
either analyzed classes do not match executed classes - see https://www.jacoco.org/jacoco/trunk/doc/classids.html
or there is no information about executed classes - see "sessions" page in html report, "execinfo" command in command line interface ( https://www.jacoco.org/jacoco/trunk/doc/cli.html ) and check third-party code that retrieves this information from Android and performs instrumentation.


Hope this helps.


Regards,
Evgeny

Tool Ply

unread,
Jan 4, 2019, 4:43:50 PM1/4/19
to JaCoCo and EclEmma Users
Ok, this indeed helps me, so sorry for providing the blurred question. I will try this, and if I need, provide complete information next time

在 2019年1月5日星期六 UTC+8上午2:47:53,Evgeny Mandrikov写道:

Evgeny Mandrikov

unread,
Jan 4, 2019, 5:53:40 PM1/4/19
to JaCoCo and EclEmma Users
Glad that this was helpful and thank you for your understanding.

Tool Ply

unread,
Jan 5, 2019, 10:29:03 AM1/5/19
to JaCoCo and EclEmma Users
According to https://groups.google.com/d/msg/jacoco/d-30r6hVrV4/d_3Dk3GdCgAJ, this was indeed because of that the decompiled classes has no LineNumberTable.

So, while the document says " To calculate line coverage class files must contain line number attributes. ", is this possible to get method coverage without line numbers?

在 2019年1月5日星期六 UTC+8上午6:53:40,Evgeny Mandrikov写道:

Evgeny Mandrikov

unread,
Jan 5, 2019, 9:01:48 PM1/5/19
to JaCoCo and EclEmma Users


On Saturday, January 5, 2019 at 4:29:03 PM UTC+1, Tool Ply wrote:
According to https://groups.google.com/d/msg/jacoco/d-30r6hVrV4/d_3Dk3GdCgAJ, this was indeed because of that the decompiled classes has no LineNumberTable.

So, while the document says " To calculate line coverage class files must contain line number attributes. ", is this possible to get method coverage without line numbers?

Without line numbers except line counters everything else will be calculated ( https://www.jacoco.org/jacoco/trunk/doc/counters.html ) - for example given Example.java

class Example {
  public static void main(String[] args) {
    if (args.length == 0) {
      System.out.println("Hello, World!");
    } else {
      System.out.println("Hello, " + args[0] + "!");
    }
  }
}

execution of

javac -g:none Example.java

will produce class without debug information. And execution of

java -javaagent:jacoco-0.8.2/lib/jacocoagent.jar Example
java -jar jacoco-0.8.2/lib/jacococli.jar report jacoco.exec --classfiles Example.class --html report

will produce following report

1.png


2.png



3.png



Tool Ply

unread,
Jan 7, 2019, 2:51:09 AM1/7/19
to JaCoCo and EclEmma Users
Thank you very much, this helps me, and I simply make a summary and hope to help others.

If anybody wants to get the line coverage, the class files must contain line number attributes. For my use scenario, without line number attributes lead that iCoverageNode.getLineCounter().getCoveredCount() always return 0. How to check if class files contain the line number attributes please refer to https://groups.google.com/d/msg/jacoco/d-30r6hVrV4/d_3Dk3GdCgAJ

If you just want to get coverage of other metrics, it will not be affected by the missing line number.

在 2019年1月6日星期日 UTC+8上午10:01:48,Evgeny Mandrikov写道:
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages