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

7903519 : jtreg/jtharness is missing features for basic crash testing #235

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

Conversation

andrlos
Copy link

@andrlos andrlos commented Nov 6, 2024

provides SPI for enabling external status transformations of failed tests

this is a continuation of efforts after openjdk/jtharness#59

Requires newest jtharness build (not even tagged yet) that includes above mentioned change to be compiled succesfully

The main idea is to provide a unified StatusTransformer interface, that can be externally implemented by users and added to a classpath in a separate jar to allow modifications of test execution status based on some elementary analysis. This can be easily used for crashtesting (filtering out only tests with jvm crashes).


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • CODETOOLS-7903519: jtreg/jtharness is missing features for basic crash testing (Enhancement - P3)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jtreg.git pull/235/head:pull/235
$ git checkout pull/235

Update a local copy of the PR:
$ git checkout pull/235
$ git pull https://git.openjdk.org/jtreg.git pull/235/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 235

View PR using the GUI difftool:
$ git pr show -t 235

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jtreg/pull/235.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 6, 2024

👋 Welcome back andrlos! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Nov 6, 2024

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 6, 2024
@mlbridge
Copy link

mlbridge bot commented Nov 6, 2024

Webrevs

@sormuras
Copy link
Member

sormuras commented Nov 6, 2024

A test status listener (in the sense of JUnit's TestWatcher) would be okay-ish, but a general test status transforming SPI is too intrusive and intransparent ... and also exposing an internal field of jtharness's Script class.

In the light of the above, I tend to close this PR.

What would an implementation handling "crashtesting" look like? Do you have a draft for it?

@andrlos
Copy link
Author

andrlos commented Nov 11, 2024

@sormuras feast your eyes on the code below :D

public class CrashOnlyStatusTransformer implements StatusTransformer {
        @Override
        public Status transform(Status originalStatus, TestDescription td) {
            Status newStatus = originalStatus;
            if(originalStatus.getType() == Status.FAILED && ! this.didCrash(td)){
                newStatus = new Status(Status.PASSED, "Just a regular failure.");
            }
            return newStatus;
        }

        private boolean didCrash(TestDescription td){
            Pattern pattern = Pattern.compile("^hs_err_pid(\\d+)\\.log");
            List<String> hs_errs = Arrays.stream(td.getDir().list()).filter(pattern.asPredicate()).collect(Collectors.toList());
            return !hs_errs.isEmpty();
    }
}

this is an approach that we use for crashtesting with debug jdk builds to separate crashes from regular failures

@jaikiran
Copy link
Member

Hello @andrlos, looking at that code you pasted:

if(originalStatus.getType() == Status.FAILED && ! this.didCrash(td)){
    newStatus = new Status(Status.PASSED, "Just a regular failure.");
}

It looks odd to be marking a failed test as successful. Furthermore, doesn't a crashed JVM result in test status to be Status.ERROR?

@sormuras
Copy link
Member

[...] this is an approach that we use for crashtesting with debug jdk builds to separate crashes from regular failures

And sometimes tests do produce hs_err_pid.log files and expect/assert them; marking those tests as PASSED, right?

Where (console log, web-view, ...) do you check for such crashes? Manually or with tool/script support?

Isn't it possible to implement/apply an after-the-fact filter that doesn't rewrite actual run results?

@andrlos
Copy link
Author

andrlos commented Nov 12, 2024

@sormuras it proved to be much harder to filter them after, as the hs_err_pid log is not being copied, plus we have many tests that run via a shell script, so a generic jvm watcher is not an option as would be the option with jvm agent that we use for junit testing.. we need to cover cases, where jvm crashes even tho it has been run via a shell script (or multiple levels of scripts) and watching for hs_err_pid.log proved to be the most reliable and universal approach.

@andrlos
Copy link
Author

andrlos commented Nov 15, 2024

@jaikiran
the idea is that if the crashed test is resulting in an error, we still want it to be reported, so those remain unchanged.. if the test has crashed but is reported as failure (usually shell scripts executing JVM) then we want them to stay as they are.. same with the test that test are reported as passed but had a crash occur during execution (we check how the jvm is behaving after crash - e.g. give correct links to report the jvm crash etc..) but when it is reported as failed without the crash happening, we want to ignore those for debug testing... but the code is just a very primitive demo of capabilities of this serviceLookup hook..

@andrlos
Copy link
Author

andrlos commented Nov 21, 2024

@sormuras @jaikiran I would like to also point out, since Junit has been already mentioned here, that JUnit since JUnit4 provides a feature called TestRule where you can implement a custom testRule, that allows the user to modify behavior of any test.. It can be used in a similar scenario, by implementing a TestRule that ignores any regular exceptions, thus only reporting JVM crashes as failures. https://github.com/junit-team/junit4/blob/HEAD/doc/ReleaseNotes4.9.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

4 participants