test/tools/javac/lambdaShapes/org/openjdk/tests/vm/FDSeparateCompilationTest.java

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 3938
93012e2a5d1d
parent 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 // this test has been disabled because of timeout issues.
aoqi@0 27 // see JDK-8006746
aoqi@0 28
aoqi@0 29 package org.openjdk.tests.vm;
aoqi@0 30
aoqi@0 31 import java.util.*;
aoqi@0 32
aoqi@0 33 import org.testng.ITestResult;
aoqi@0 34 import org.testng.annotations.Test;
aoqi@0 35 import org.testng.annotations.DataProvider;
aoqi@0 36 import org.testng.annotations.AfterMethod;
aoqi@0 37 import org.testng.annotations.AfterSuite;
aoqi@0 38
aoqi@0 39 import org.openjdk.tests.separate.*;
aoqi@0 40 import org.openjdk.tests.separate.Compiler;
aoqi@0 41
aoqi@0 42 import org.openjdk.tests.shapegen.Hierarchy;
aoqi@0 43 import org.openjdk.tests.shapegen.HierarchyGenerator;
aoqi@0 44 import org.openjdk.tests.shapegen.ClassCase;
aoqi@0 45
aoqi@0 46 import static org.testng.Assert.*;
aoqi@0 47 import static org.openjdk.tests.separate.SourceModel.*;
aoqi@0 48 import static org.openjdk.tests.separate.SourceModel.Class;
aoqi@0 49 import static org.openjdk.tests.separate.SourceModel.Method;
aoqi@0 50 import static org.openjdk.tests.separate.SourceModel.Type;
aoqi@0 51
aoqi@0 52 public class FDSeparateCompilationTest extends TestHarness {
aoqi@0 53
aoqi@0 54 private static String EMPTY = "\"\"";
aoqi@0 55
aoqi@0 56 public FDSeparateCompilationTest() {
aoqi@0 57 super(false, true);
aoqi@0 58 }
aoqi@0 59
aoqi@0 60 @DataProvider(name = "allShapes", parallel = true)
aoqi@0 61 public Object[][] hierarchyGenerator() {
aoqi@0 62 ArrayList<Object[]> allCases = new ArrayList<>();
aoqi@0 63
aoqi@0 64 HierarchyGenerator hg = new HierarchyGenerator();
aoqi@0 65 for (Object x : hg.getOK()) {
aoqi@0 66 allCases.add(new Object[]{x});
aoqi@0 67 }
aoqi@0 68 for (Object x : hg.getErr()) {
aoqi@0 69 allCases.add(new Object[]{x});
aoqi@0 70 }
aoqi@0 71 return allCases.toArray(new Object[0][]);
aoqi@0 72 }
aoqi@0 73
aoqi@0 74 // The expected value obtained when invoking the method from the specified
aoqi@0 75 // class. If returns null, then an AbstractMethodError is expected.
aoqi@0 76 private static String getExpectedResult(ClassCase cc) {
aoqi@0 77 Set<ClassCase> provs = cc.get_mprov();
aoqi@0 78 if (cc.get_mres() != null) {
aoqi@0 79 return cc.get_mres().getName();
aoqi@0 80 } else if (provs != null && provs.size() == 1) {
aoqi@0 81 ClassCase cand = provs.iterator().next();
aoqi@0 82 switch (cand.kind) {
aoqi@0 83 case CCONCRETE:
aoqi@0 84 case IDEFAULT:
aoqi@0 85 return cand.getName();
aoqi@0 86 case CNONE:
aoqi@0 87 case IVAC:
aoqi@0 88 return getExpectedResult(cand);
aoqi@0 89 }
aoqi@0 90 }
aoqi@0 91 return null;
aoqi@0 92 }
aoqi@0 93
aoqi@0 94 private static final ConcreteMethod canonicalMethod = new ConcreteMethod(
aoqi@0 95 "String", "m", "returns " + EMPTY + ";", AccessFlag.PUBLIC);
aoqi@0 96
aoqi@0 97 @Test(enabled = false, groups = "vm", dataProvider = "allShapes")
aoqi@0 98 public void separateCompilationTest(Hierarchy hs) {
aoqi@0 99 ClassCase cc = hs.root;
aoqi@0 100 Type type = sourceTypeFrom(hs.root);
aoqi@0 101
aoqi@0 102 Class specimen = null;
aoqi@0 103 if (type instanceof Class) {
aoqi@0 104 Class ctype = (Class)type;
aoqi@0 105 if (ctype.isAbstract()) {
aoqi@0 106 specimen = new Class("Test" + ctype.getName(), ctype);
aoqi@0 107 } else {
aoqi@0 108 specimen = ctype;
aoqi@0 109 }
aoqi@0 110 } else {
aoqi@0 111 specimen = new Class("Test" + type.getName(), (Interface)type);
aoqi@0 112 }
aoqi@0 113
aoqi@0 114 String value = getExpectedResult(cc);
aoqi@0 115 if (value != null) {
aoqi@0 116 assertInvokeVirtualEquals(value, specimen, canonicalMethod, EMPTY);
aoqi@0 117 } else {
aoqi@0 118 assertThrows(AbstractMethodError.class, specimen,
aoqi@0 119 canonicalMethod, EMPTY);
aoqi@0 120 }
aoqi@0 121 }
aoqi@0 122
aoqi@0 123 @AfterMethod
aoqi@0 124 public void printCaseError(ITestResult result) {
aoqi@0 125 if (result.getStatus() == ITestResult.FAILURE) {
aoqi@0 126 Hierarchy hs = (Hierarchy)result.getParameters()[0];
aoqi@0 127 System.out.println("Separate compilation case " + hs);
aoqi@0 128 printCaseDetails(hs);
aoqi@0 129 }
aoqi@0 130 }
aoqi@0 131
aoqi@0 132 @AfterSuite
aoqi@0 133 public void cleanupCompilerCache() {
aoqi@0 134 Compiler.purgeCache();
aoqi@0 135 }
aoqi@0 136
aoqi@0 137 private void printCaseDetails(Hierarchy hs) {
aoqi@0 138 String exp = getExpectedResult(hs.root);
aoqi@0 139 for (String s : hs.getDescription()) {
aoqi@0 140 System.out.println(" " + s);
aoqi@0 141 }
aoqi@0 142 if (exp != null) {
aoqi@0 143 System.out.println(" Expected \"" + exp + "\"");
aoqi@0 144 } else {
aoqi@0 145 System.out.println(" Expected AbstractMethodError");
aoqi@0 146 }
aoqi@0 147 }
aoqi@0 148
aoqi@0 149 private Type sourceTypeFrom(ClassCase cc) {
aoqi@0 150 Type type = null;
aoqi@0 151
aoqi@0 152 if (cc.isInterface()) {
aoqi@0 153 Interface iface = new Interface(cc.getName());
aoqi@0 154 for (ClassCase scc : cc.getInterfaces()) {
aoqi@0 155 Interface supertype = (Interface)sourceTypeFrom(scc);
aoqi@0 156 iface.addSuperType(supertype);
aoqi@0 157 }
aoqi@0 158 type = iface;
aoqi@0 159 } else {
aoqi@0 160 Class cls = new Class(cc.getName());
aoqi@0 161 if (cc.hasSuperclass()) {
aoqi@0 162 Class superc = (Class)sourceTypeFrom(cc.getSuperclass());
aoqi@0 163 cls.setSuperClass(superc);
aoqi@0 164 }
aoqi@0 165 for (ClassCase scc : cc.getInterfaces()) {
aoqi@0 166 Interface supertype = (Interface)sourceTypeFrom(scc);
aoqi@0 167 cls.addSuperType(supertype);
aoqi@0 168 }
aoqi@0 169 if (cc.isAbstract()) {
aoqi@0 170 cls.getAccessFlags().add(AccessFlag.ABSTRACT);
aoqi@0 171 }
aoqi@0 172 type = cls;
aoqi@0 173 }
aoqi@0 174 Method method = methodFrom(cc);
aoqi@0 175 if (method != null) {
aoqi@0 176 type.addMethod(method);
aoqi@0 177 }
aoqi@0 178 return type;
aoqi@0 179 }
aoqi@0 180
aoqi@0 181 private Method methodFrom(ClassCase cc) {
aoqi@0 182 switch (cc.kind) {
aoqi@0 183 case IVAC:
aoqi@0 184 case CNONE: return null;
aoqi@0 185 case IPRESENT:
aoqi@0 186 case CABSTRACT:
aoqi@0 187 return new AbstractMethod("String", "m", AccessFlag.PUBLIC);
aoqi@0 188 case IDEFAULT:
aoqi@0 189 return new DefaultMethod(
aoqi@0 190 "String", "m", "return \"" + cc.getName() + "\";");
aoqi@0 191 case CCONCRETE:
aoqi@0 192 return new ConcreteMethod(
aoqi@0 193 "String", "m", "return \"" + cc.getName() + "\";",
aoqi@0 194 AccessFlag.PUBLIC);
aoqi@0 195 default:
aoqi@0 196 fail("Unknown method type in class");
aoqi@0 197 return null;
aoqi@0 198 }
aoqi@0 199 }
aoqi@0 200 }

mercurial