-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implementation for #4: Offline Instrumentation #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@marchof Hi Marc, do you want me to do a review? I saw couple of TODOs, which I probably would be able to solve. Also if we will provide an offline mode, I'd like to be sure that it can be used for development for Android. |
@@ -6,9 +6,11 @@ Bundle-Version: 0.6.1.qualifier | |||
Bundle-RequiredExecutionEnvironment: J2SE-1.5 | |||
Bundle-Vendor: Mountainminds GmbH & Co. KG and Contributors | |||
Require-Bundle: org.apache.ant;bundle-version="[1.7.0,2.0.0)" | |||
Import-Package: org.jacoco.agent;bundle-version="[0.6.1,0.6.2)", | |||
Import-Package: org.objectweb.asm;version="[4.1.0,4.2.0)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marchof Why import of "org.objectweb.asm" required now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to the dependency on org.jacoco.core.instr.Instrumenter which has a dependency on ASM in its API. If we drop the following method from the API we should be able to remove the dependency again:
byte[] instrument(ClassReader reader);
Beside our tests I don't see a real use case for this method.
@Godin Absolutely, a review would be great! Concerning the Android scenario it would be helpful to have a working example, or maybe at least some description how to integrate it with JaCoCo. I don't think I have a chance to work on this. Maybe then community jumps in once JaCoCo supports offline mode? |
@marchof Ok, I'll do a review and testing. And I plan to experiment with scenario for Android, so maybe will provide an example. Also IMO we should enhance Maven Plugin to support offline instrumentation. |
The Maven plug-in will be some work. For this we should really know the scenario why we take the hassle. I see the offline feature as the last resort for very specific scenarios. I don't feel we should push this feature too much. |
Scenario for Maven plugin is the same - to better support development for Android, i.e. to integrate into projects based on https://github.com/jayway/maven-android-plugin |
But I agree that offline instrumentation should be a last resort. |
Conflicts: org.jacoco.ant/META-INF/MANIFEST.MF
@Godin Many thanks for making the commit hash work! WDYT, can we merge this? Any concerns? |
@marchof Currently I'm trying to use this for Android. For sure modification of Maven Plugin will be required for better integration. But not yet sure, if this will require other changes. So it's up to you to decide whether to merge or not. In last case - we can commit required changes later. |
Sure, if you're working on an Android example we can wait until we see whether the current implementation actually does the job. |
@marchof FYI : I spent a lot of time (around 5 hours) to make a "hello world" project for Android, and to use Emma for it (to understand how it works). Then I was able to instrument classes in-place with help of JaCoCo Ant Task. And run instrumented classes with JaCoCo Runtime under Android emulator. But now I'm a bit stuck as I don't know how to pass System properties in order to change destination of dump file. Here is a log from Android Emulator:
As soon as this will be solved - we're done and can claim that JaCoCo can work for Android ;) |
Another problem : seems that we can't rely on ShutdownHook. |
And the last point is that original classes must be presented to generate report, which means that actually we can't instrument classes in-place. Despite the 3 problems described above (actually using some hacks like hard-coded value for dump file) I was able to collect data and generate report. |
And to be precise - here is info about how Emma integrated: android.test.InstrumentationTestRunner executes method com.vladium.emma.rt.RT.dumpCoverageData with path to the dump file. As a workaround I can imagine that we will provide this class, which will do a proper shutdown of agent. But WDYT? |
Concerning configuration: EMMA has a alternative was for configuration, which is a optional file emma.properties on the class path. Do we need that? |
Concerning ShutdownHook: A dumpCoverageData() would mean that we actually start exposing APIs be the agent which I wanted to avoid. Are there other alternatives like tcpclient output? |
Concerning InstrumentationTestRunner: Or we simply document your prototype (blog?) with an example implementation and let the Android community pick-up an this? I don't think we can also maintain the Android integration. |
|
Even if we can use solution like tcpclient, most important is how to configure agent, because I still didn't found a way to pass System properties and file mode is a default. |
I managed to do following:
I wouldn't say that this is non-intrusive solution - requires free port, requires custom code with dependency on jacoco-core, stability not guaranteed (due to the way of setting properties), ... |
|
To sum up : agent API looks really sexy for me. And it can be minimalistic like existing MBean. |
@Godin I'll add the ability load configuration from a jacoco-agent.properties file. Concerning the agent API I would like to work on this in a separate pull request. |
@marchof Ok, sounds good, so we can merge this branch since offline instrumentation works fine, and adjust other parts separately.. |
@Godin I added an additional way to provide configuration options without system properties. So I propose to merge this one and create a separate pull request for the agent API. |
@marchof Cool! Do you want me to merge this one? |
Implementation for #4: Offline Instrumentation
I am trying to pull these changes into my fork and have hit some test failures when trying to run InstrumentTaskTest from Eclipse:
I am using Eclipse 3.8.0. When I run the tests from Maven I hit different errors:
Have you seen any of these errors before? |
This is a known issue. The problem is that the Ant tests are more or less integration tests which need properly processed resources.
Please check your dependencies, we need Ant 1.7.1 to run this tests (see master POM).
Looks like a merge problem. Both tests have been adjusted this way for #66. |
Thanks for the quick reply. It's a pity that InstrumentTaskTest can't be run from Eclipse. It makes debugging failures more awkward. My Eclipse includes Ant 1.8.3. Ant 1.7.1 is on my project classpath but Eclipse still seems to be using the built in Ant 1.8.3. Have you had any Ant version issues within Eclipse? I am investigating the Maven failures. In testInstrumentInvalidClassFile it looks like the instrumentation correctly fails to process the truncated class file but it seems to be failing to delete the zero length output file. |
testInstrumentInvalidClassFile fails on Windows because the task attempts to delete the invalid zero length output class file before the outputstream has been closed. I have fixed this: mchr3k@e716107 testInstrumentAndRunWithConfigFile is still failing for me. I'm investigating. |
testInstrumentAndRunWithConfigFile fails on Windows due to the following line:
This writes a path which includes \ path separators. These are not valid when loaded by the Properties class. I'm not sure what the best way is to fix this as Ant doesn't seem to have built in support for replacing \ with / in a property. |
@mchr3k Thanks for analyzing this! The property file should be created with the (optional) PropertyFile task instead. I need to check how to make the optional task work under Maven. |
Much better thanks! |
APIs, Ant task, tests and documentation for issue #4.