Coverage on obfuscated code

102 views
Skip to first unread message

Nicolas Garcin

unread,
Oct 7, 2022, 10:26:50 AM10/7/22
to JaCoCo and EclEmma Users
Hi everyone,

Our software is written in Java and (partly) obfuscated. We're measuring our test coverage with Jacoco agent. I'm surprised to see that Jacoco manages to calculate coverage even on obfusacted code. For example, I have a com.xxx.User.class that is obfuscated into a.b.c.class. The obfuscated class is used at runtime and I can see in the coverage report some coverage on com.xxx.User.class. How is that possible ? 

Thanks and Regards,
Nicolas

Marc Hoffmann

unread,
Oct 10, 2022, 7:56:55 AM10/10/22
to JaCoCo and EclEmma Users
Hi Nicolas,

JaCoCo works on byte code only. It doesn’t matter whether the byte code comes from the compiler or obfuscator. Of you create an report on the obfuscated code the result will probably not very readable though.

If you see coverage on a class “com.xxx.User” this means a class with exact this name was loaded in the JVM when coverage data was collected.

Regards,
-marc


--
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 jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/7dae77f8-7d63-43e2-8d10-3314a69420een%40googlegroups.com.

Nicolas Garcin

unread,
Oct 10, 2022, 10:02:43 AM10/10/22
to jac...@googlegroups.com
Hi Marc,

Thanks for your answer. I'll give you a bit more details because I still don't understand how I can get readable results:
The application for which I want to measure the coverage is a server. The classpath of the server contains obfuscated jars. I can clearly see the obfuscated classes by using the -verbose:class JVM option for the server. For example, I can see:

[Loaded lib.system.datactrl.k from file:/data/home/testauto/nxat/data/bamboo/datahub-build-10/datahub-build-10-agent/xml-data/build-dir/DAT-DHBB10454-UN/dist/nxdh-6.3-02-SNAPSHOT/NXDH/Soft/jar/smartsys.jar]

k is the result of obfuscation of a class called DataWriteController. The server is started using -javaagent:org.jacoco.agent-${jacoco.version}-runtime.jar in order to allow instrumentation.

In order to test the server, we run an Ant Junit task embedded into the jacoco coverage task:

<jacoco:coverage destfile="${jacoco.dest.file}" append="true" enabled="${nxdh.coverage.junit}">
<junit printsummary="true" fork="true" forkmode="perTest" dir="${basedir}" showoutput="${show.output}" jvm="${JAVA_HOME}/bin/java">
<classpath refid="test.classpath" />
<jvmarg line="${test.jvmargs}" />
<jvmarg line="${debug.jvmargs}" />
<jvmarg line="${test.args}" />
<formatter type="brief" usefile="false" />
<formatter type="xml" />
<batchtest todir="${test.report.dir}">
<zipfileset src="${test.jar}" includes="testsuites/*TestSuite*.class" excludes="${serial.test.suites}" />
</batchtest>
</junit>
</jacoco:coverage>

The junit task has its own classpath which may contain non-obfuscated jars but I guess it is used for the junit test process only, not for the server under test.

After generating coverage report, I can clearly see coverage on DataWriteController class. This makes me confused because I would expect to see coverage on lib.system.datactrl.k, and not on lib.system.datactrl.DataWriteController.

Does this make sense or do I miss something? 

Thanks a lot.

Regards,
Nicolas











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/aF8VnY1ApyQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/61253AB6-9F91-4F6F-9F8F-A7CF00AA8A59%40mountainminds.com.

Marc Hoffmann

unread,
Oct 10, 2022, 1:04:26 PM10/10/22
to jac...@googlegroups.com
Hi Nicolas,

the question is, for which JVM you want to collect coverage for:

  1) the server code —> Use the agent on the server process

or

  2) the test client code —> use the jacoco:coverage task

In case of 1) I have serious doubts that you will get a usable coverage report on obfuscated byte code. Maybe meassure test coverage on the original classes?

Regards,
-marc

Reply all
Reply to author
Forward
0 new messages