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

Backport-of: 6e3e470dac80d3b6c3a0f4845ce4115858178dd3
  • Loading branch information
GoeLin committed Jan 30, 2023
1 parent d37977e commit 9fc178b
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;
}
}
}

1 comment on commit 9fc178b

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.