Skip to content

Commit

Permalink
8285965: TestScenarios.java does not check for "<!-- safepoint while …
Browse files Browse the repository at this point in the history
…printing -->" correctly

Reviewed-by: thartmann, kvn
  • Loading branch information
chhagedorn committed Jun 8, 2022
1 parent d959c22 commit 6e3e470
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,6 +27,9 @@
import compiler.lib.ir_framework.shared.TestRunException;
import jdk.test.lib.Asserts;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

/*
* @test
* @requires vm.debug == true & vm.compMode != "Xint" & vm.compiler2.enabled & vm.flagless
Expand All @@ -37,35 +40,35 @@

public class TestScenarios {
public static void main(String[] args) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream oldOut = System.out;
System.setOut(ps);

Scenario sDefault = new Scenario(0);
Scenario s1 = new Scenario(1, "-XX:TLABRefillWasteFraction=51");
Scenario s2 = new Scenario(2, "-XX:TLABRefillWasteFraction=52");
Scenario s3 = new Scenario(3, "-XX:TLABRefillWasteFraction=53");
Scenario s3dup = new Scenario(3, "-XX:TLABRefillWasteFraction=53");
try {
new TestFramework().addScenarios(sDefault, s1, s2, s3).start();
if (Utils.notAllBailedOut(sDefault, s1, s3)) {
// Not all scenarios had a bailout which means that at least one exception should have been thrown.
Asserts.fail("Should have thrown an exception");
}
Utils.shouldHaveThrownException(baos.toString());
} catch (TestRunException e) {
if (!e.getMessage().contains("The following scenarios have failed: #0, #1, #3")) {
// Was there a bailout in a scenario? If not fail.
Asserts.assertTrue(Utils.anyBailedOut(sDefault, s1, s3), e.getMessage());
Utils.throwIfNoSafepointPrinting(baos.toString(), e);
}
}

baos.reset();
try {
new TestFramework().addScenarios(s1, s2, s3).start();
if (Utils.notAllBailedOut(s1, s3)) {
// Not all scenarios had a bailout which means that at least one exception should have been thrown.
Asserts.fail("Should have thrown an exception");
}
Utils.shouldHaveThrownException(baos.toString());
} catch (TestRunException e) {
if (!e.getMessage().contains("The following scenarios have failed: #1, #3")) {
// Was there a bailout in a scenario? If not fail.
Asserts.assertTrue(Utils.anyBailedOut(sDefault, s1, s3), e.getMessage());
Utils.throwIfNoSafepointPrinting(baos.toString(), e);
}
}
System.setOut(oldOut);
new TestFramework(ScenarioTest.class).addScenarios(s1, s2, s3).start();
try {
new TestFramework().addScenarios(s1, s3dup, s2, s3).start();
Expand Down
20 changes: 6 additions & 14 deletions test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,17 @@
import java.util.Arrays;

public class Utils {
public static void shouldHaveThrownException(String s) {
public static void shouldHaveThrownException(String output) {
// Do not throw an exception if we hit a safepoint while printing which could possibly let the IR matching fail.
// This happens very rarely. If there is a problem with the test, then we will catch that on the next test invocation.
if (!s.contains(IRMatcher.SAFEPOINT_WHILE_PRINTING_MESSAGE)) {
if (!output.contains(IRMatcher.SAFEPOINT_WHILE_PRINTING_MESSAGE)) {
Asserts.fail("Should have thrown exception");
}
}

/**
* Is there at least one scenario which hit a safepoint while printing (i.e. a bailout)?
*/
public static boolean anyBailedOut(Scenario... scenarios) {
return Arrays.stream(scenarios).anyMatch(s -> s.getTestVMOutput().contains(IRMatcher.SAFEPOINT_WHILE_PRINTING_MESSAGE));
}

/**
* Is there at least one scenario which did not hit a safepoint while printing (i.e. a bailout)?
*/
public static boolean notAllBailedOut(Scenario... scenarios) {
return Arrays.stream(scenarios).anyMatch(s -> !s.getTestVMOutput().contains(IRMatcher.SAFEPOINT_WHILE_PRINTING_MESSAGE));
public static void throwIfNoSafepointPrinting(String output, RuntimeException e) {
if (!output.contains(IRMatcher.SAFEPOINT_WHILE_PRINTING_MESSAGE)) {
throw e;
}
}
}

3 comments on commit 6e3e470

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 6e3e470 Jan 24, 2023

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 6e3e470 Jan 24, 2023

Choose a reason for hiding this comment

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

@GoeLin the backport was successfully created on the branch GoeLin-backport-6e3e470d in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 6e3e470d from the openjdk/jdk repository.

The commit being backported was authored by Christian Hagedorn on 8 Jun 2022 and was reviewed by Tobias Hartmann and Vladimir Kozlov.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-6e3e470d:GoeLin-backport-6e3e470d
$ git checkout GoeLin-backport-6e3e470d
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-6e3e470d

Please sign in to comment.