Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8273410: IR verification framework fails with "Should find method nam…
…e in validIrRulesMap"

Reviewed-by: thartmann, neliasso
  • Loading branch information
chhagedorn committed Oct 6, 2021
1 parent c74726d commit df125f6
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 1 deletion.
Expand Up @@ -619,13 +619,16 @@ private void addCheckedTest(Method m, Check checkAnno, Run runAnno) {
DeclaredTest test = declaredTests.get(testMethod);
checkCheckedTest(m, checkAnno, runAnno, testMethod, test);
test.setAttachedMethod(m);
TestFormat.check(getAnnotation(testMethod, Arguments.class) != null || testMethod.getParameterCount() == 0,
"Missing @Arguments annotation to define arguments of " + testMethod + " required by "
+ "checked test " + m);
CheckedTest.Parameter parameter = getCheckedTestParameter(m, testMethod);
dontCompileAndDontInlineMethod(m);
CheckedTest checkedTest = new CheckedTest(test, m, checkAnno, parameter, shouldExcludeTest(testMethod.getName()));
allTests.add(checkedTest);
if (PRINT_VALID_IR_RULES) {
// Only need to emit IR verification information if IR verification is actually performed.
irMatchRulePrinter.emitRuleEncoding(m, checkedTest.isSkipped());
irMatchRulePrinter.emitRuleEncoding(testMethod, checkedTest.isSkipped());
}
}

Expand Down
Expand Up @@ -139,6 +139,13 @@ class BadArgumentsAnnotation {
@Test
public void noArgAnnotation(int a) {}

@FailCount(0) // Combined with both checkNoArgAnnotation2() below
@Test
public void noArgAnnotation2(int a) {}

@Check(test = "noArgAnnotation2")
public void checkNoArgAnnotation2() {}

@Test
@Arguments(Argument.DEFAULT)
public void argNumberMismatch(int a, int b) {}
Expand Down
@@ -0,0 +1,222 @@
/*
* Copyright (c) 2021, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package ir_framework.tests;

import compiler.lib.ir_framework.*;
import compiler.lib.ir_framework.driver.IRViolationException;
import compiler.lib.ir_framework.driver.TestVMException;
import jdk.test.lib.Asserts;

/*
* @test
* @bug 8273410
* @requires vm.debug == true & vm.compMode != "Xint" & vm.compiler2.enabled & vm.flagless
* @summary Test different custom run tests.
* @library /test/lib /testlibrary_tests /
* @run driver ir_framework.tests.TestCheckedTests
*/

public class TestCheckedTests {
public int iFld;

public static void main(String[] args) {
TestFramework.run();
try {
TestFramework.run(BadIRAndRuntimeCheckedTests.class);
Utils.shouldHaveThrownException();
} catch (TestVMException e) {
Asserts.assertTrue(e.getExceptionInfo().contains("Test Failures (2)"));
Asserts.assertTrue(e.getExceptionInfo().contains("checkTestBad3"));
Asserts.assertTrue(e.getExceptionInfo().contains("checkTestBad5"));
Asserts.assertTrue(e.getExceptionInfo().split("BadCheckedTestException").length == 3);
Asserts.assertFalse(e.getExceptionInfo().contains("Failed IR Rules"));
}

try {
TestFramework.run(BadIRCheckedTests.class);
Utils.shouldHaveThrownException();
} catch (IRViolationException e) {
Asserts.assertTrue(e.getExceptionInfo().contains("Failed IR Rules (3)"));
}
}

@Test
@IR(counts = {IRNode.STORE_I, "1"})
public void testGood1() {
iFld = 3;
}

@Check(test = "testGood1")
public void checkTestGood1(TestInfo info) {
}

@Test
@IR(failOn = IRNode.LOAD)
public int testGood2() {
iFld = 3;
return 3;
}

@Check(test = "testGood2")
public void sameName(int retValue) {
if (retValue != 3) {
throw new RuntimeException("must be 3 but was " + retValue);
}
}

@Test
@Arguments(Argument.NUMBER_42)
@IR(failOn = IRNode.LOAD)
@IR(counts = {IRNode.STORE_I, "0"})
public int testGood3(int x) {
return x;
}

@Check(test = "testGood3")
public void sameName(int retValue, TestInfo info) {
if (retValue != 42) {
throw new RuntimeException("must be 42");
}
}
}

class BadIRAndRuntimeCheckedTests {
public int iFld;

@Test
@IR(counts = {IRNode.STORE_I, "2"})
public void testBad1() {
iFld = 3;
}

@Check(test = "testBad1")
public void checkTestBad1(TestInfo info) {
}

@Test
@IR(failOn = IRNode.STORE_I)
public int testBad2() {
iFld = 3;
return 3;
}

@Check(test = "testBad2")
public void sameName(int retValue) {
if (retValue != 3) {
throw new RuntimeException("must be 3");
}
}

@Test
@Arguments(Argument.NUMBER_42)
public int testBad3(int x) {
return x;
}

@Check(test = "testBad3")
public void checkTestBad3(int retValue) {
if (retValue == 42) {
// Always
throw new BadCheckedTestException("expected");
}
}

@Test
@Arguments(Argument.NUMBER_42)
@IR(failOn = IRNode.LOAD)
@IR(counts = {IRNode.STORE_I, "1"})
public int testBad4(int x) {
return x;
}

@Check(test = "testBad4")
public void sameName(int retValue, TestInfo info) {
if (retValue != 42) {
throw new RuntimeException("must be 42");
}
}

@Test
@Arguments(Argument.NUMBER_42)
public int testBad5(int x) {
return x;
}

@Check(test = "testBad5")
public void checkTestBad5(int retValue) {
if (retValue == 42) {
// Always
throw new BadCheckedTestException("expected");
}
}
}

class BadIRCheckedTests {
public int iFld;

@Test
@IR(counts = {IRNode.STORE_I, "2"})
public void testBad1() {
iFld = 3;
}

@Check(test = "testBad1")
public void checkTestBad1(TestInfo info) {
}

@Test
@IR(failOn = IRNode.STORE_I)
public int testBad2() {
iFld = 3;
return 3;
}

@Check(test = "testBad2")
public void sameName(int retValue) {
if (retValue != 3) {
throw new RuntimeException("must be 3");
}
}

@Test
@Arguments(Argument.NUMBER_42)
@IR(failOn = IRNode.LOAD)
@IR(counts = {IRNode.STORE_I, "1"})
public int testBad4(int x) {
return x;
}

@Check(test = "testBad4")
public void sameName(int retValue, TestInfo info) {
if (retValue != 42) {
throw new RuntimeException("must be 42");
}
}
}

class BadCheckedTestException extends RuntimeException {
BadCheckedTestException(String s) {
super(s);
}
}

3 comments on commit df125f6

@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 df125f6 Dec 27, 2022

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 df125f6 Dec 27, 2022

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-df125f68 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 df125f68 from the openjdk/jdk repository.

The commit being backported was authored by Christian Hagedorn on 6 Oct 2021 and was reviewed by Tobias Hartmann and Nils Eliasson.

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-df125f68:GoeLin-backport-df125f68
$ git checkout GoeLin-backport-df125f68
# 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-df125f68

Please sign in to comment.