Skip to content
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

Fix JaCoCo instrumented constructor skipped. #8057

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ZSmallX
Copy link
Contributor

@ZSmallX ZSmallX commented Mar 16, 2023

Strip JaCoCo constructor probes data initialization instructions from callSuper instructions for JaCoCo instrumentation was detected. And insert these instructions into the beginning of the original constructor.

Note that there can be many instructions before the call super() or this(), so this can still break the instruction compatibility?

Tested by: JaCoCo offline integration tests.

Fixes #8001

@hoisie
Copy link
Contributor

hoisie commented Mar 16, 2023

Can a constructor and a shadow constructor be added to JacocoTester and ShadowJacocoTester

Detect JaCoCo instrumentation from the original constructor by checking if the beginning one or two instructions are from JaCoCo. Simply by instructions' type and content.

An then strip JaCoCo constructor probes data initialization instructions from `callSuper` instructions for JaCoCo instrumentation was detected. And insert these instructions into the beginning of the original construction.

Overall, we assume that the JaCoCo instrumentation detecting and JaCoCo initialization instructions are in general cases and obey the JaCoCo implementations.

Note that there can be many instructions before the call super() or this(), so this can still break the instruction compatibility?

Tested by: JaCoCo offline integration tests.

Signed-off-by: ZSmallX <diosmallx@gmail.com>
@ZSmallX ZSmallX force-pushed the fix_jacoco_instrumentec_constructor branch from f3020ea to 943b71e Compare March 19, 2023 05:20
}
}

throw new RuntimeException("huh? JaCoCo instrumented?!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it fine to throw RuntimeException here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could be a violation between robolectric's JaCoCo detection and JaCoCo instructions strip and split when it comes to line 421.
I think it would be better to fail early to avoid the previous issue when we has assumed that all the JaCoCo detection and JaCoCo instructions strip and split are breaked.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But some users can accept no-code-coverage or other things, but they can't accept exceptions when running tests.

@ZSmallX
Copy link
Contributor Author

ZSmallX commented Mar 19, 2023

Can a constructor and a shadow constructor be added to JacocoTester and ShadowJacocoTester

Yeap, that should be a test over constructor and shadow constructor to test all 3 robolectric instrumented methods: redirector constructor, constructor and $robo$constructor.
Let me extend the tests~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JaCoCo offline instrument on custom shadow regression when upgrade from 4.8.2 to 4.9.2
3 participants