Add infrastructure to run codegen test on jdk 6

Perform actual codegen test execution in separate process.
One server process is used to run all codegen tests
through socket connection.
This commit is contained in:
Mikhael Bogdanov
2017-04-20 16:05:16 +02:00
parent 1ee337d976
commit 9d021ee1ac
11 changed files with 434 additions and 79 deletions
@@ -16,13 +16,9 @@
package org.jetbrains.kotlin.codegen;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.util.io.FileUtil;
import kotlin.io.FilesKt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil;
import org.jetbrains.kotlin.load.java.JvmAbi;
import org.jetbrains.kotlin.psi.KtDeclaration;
import org.jetbrains.kotlin.psi.KtFile;
import org.jetbrains.kotlin.psi.KtNamedFunction;
@@ -31,9 +27,12 @@ import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import static org.jetbrains.kotlin.codegen.TestUtilsKt.clearReflectionCache;
import static org.jetbrains.kotlin.codegen.TestUtilsKt.getBoxMethodOrNull;
import static org.jetbrains.kotlin.codegen.TestUtilsKt.getGeneratedClass;
public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
@Override
@@ -42,21 +41,6 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
blackBox();
}
@NotNull
protected static List<String> findJavaSourcesInDirectory(@NotNull File directory) {
List<String> javaFilePaths = new ArrayList<>(1);
FileUtil.processFilesRecursively(directory, file -> {
if (file.isFile() && FilesKt.getExtension(file).equals(JavaFileType.DEFAULT_EXTENSION)) {
javaFilePaths.add(file.getPath());
}
return true;
});
return javaFilePaths;
}
protected void blackBox() {
// If there are many files, the first 'box(): String' function will be executed.
GeneratedClassLoader generatedClassLoader = generateAndCreateClassLoader();
@@ -67,8 +51,7 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
try {
Method method = getBoxMethodOrNull(aClass);
if (method != null) {
String r = (String) method.invoke(null);
assertEquals("OK", r);
callBoxMethodAndCheckResult(generatedClassLoader, aClass, method);
return;
}
}
@@ -80,21 +63,9 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
clearReflectionCache(generatedClassLoader);
}
}
fail("Can't find box method!");
}
private static void clearReflectionCache(@NotNull ClassLoader classLoader) {
try {
Class<?> klass = classLoader.loadClass(JvmAbi.REFLECTION_FACTORY_IMPL.asSingleFqName().asString());
Method method = klass.getDeclaredMethod("clearCaches");
method.invoke(null);
}
catch (ClassNotFoundException e) {
// This is OK for a test without kotlin-reflect in the dependencies
}
catch (Exception e) {
throw ExceptionUtilsKt.rethrow(e);
}
}
@Nullable
private static String getFacadeFqName(@NotNull KtFile firstFile) {
@@ -105,23 +76,4 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
}
return null;
}
private static Class<?> getGeneratedClass(GeneratedClassLoader generatedClassLoader, String className) {
try {
return generatedClassLoader.loadClass(className);
}
catch (ClassNotFoundException e) {
fail("No class file was generated for: " + className);
}
return null;
}
private static Method getBoxMethodOrNull(Class<?> aClass) {
try {
return aClass.getMethod("box");
}
catch (NoSuchMethodException e){
return null;
}
}
}