Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8325810

[IR framework] Automatic correctness checks

XMLWordPrintable

    • generic
    • generic

      The IR framework supports `@Check` annotations to validate the return value of a method. We can add an `@AutomaticCheck` for automatic correctness checks. For example, lets say we want to test the correctness of constant folding with a non-constant in between:

      ```
      int input;

      @Setup
      public Object[] setup() {
        input = random();
        return new Object[]{ input };
      }

      @Test
      @Arguments(setup = "setup"})
      @IR(counts = {IRNode.AddI, "1"})
      public int add(int x) {
        return 1 + x + 2;
      }

      @Check(test = "add")
      public void check(int retVal) {
        if (retVal != x + 3) { throw Exception(); }
      }
      ```

      It can be a lot of code to validate correctness. The check method often will need to check inputs, which can be read through a class member variable or passed in by the test method itself.

      I think it is a common pattern and can be automated. We can pass in inputs to a compiled method vs an interpreted method and confirm they are equal. Some options could be:

      1) Spawn another test VM with "dontcompile" flags
      2) Create a copy of the method and mark that method "dontcompile"

      This option can only be applied to deterministic tests that do not involved global state, but I suspect this applies to most IR tests. With this change, we can simplify the test code to look like:

      ```
      @Test
      @Arguments(setup = "setup"})
      @IR(counts = {IRNode.AddI, "1"})
      @AutomaticCheck
      public int add(int x) {
        return 1 + x + 2;
      }
      ```

            Unassigned Unassigned
            jcao Joshua Cao
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: