From 6234bcb4537778134a46c2d4efaf6fd4664e3170 Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Thu, 26 Nov 2020 05:57:58 +0100 Subject: [PATCH] [build][test] enable external compiler tests --- .../backend.native/tests/build.gradle | 107 ++++-------------- .../org/jetbrains/kotlin/KonanTest.groovy | 47 ++++---- .../org/jetbrains/kotlin/TestDirectives.kt | 1 + 3 files changed, 50 insertions(+), 105 deletions(-) diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index fc5d49d2e57..6d1ab64a0e5 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -52,24 +52,6 @@ configurations { dependencies { compile 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7' cli_bc project(path: ':kotlin-native:backend.native', configuration: 'cli_bc') - def updateTestData = true - if (project.hasProperty("kotlinProjectPath")) { - def kotlinProj = project.property("kotlinProjectPath").toString() - def testDataZip = Paths.get(kotlinProj, "dist", "kotlin-test-data.zip").toFile() - if (testDataZip.exists()) { - update_tests files(testDataZip) - updateTestData = false - } else { - println("WARN: using tests provided by gradle.properties. Please execute :kotlin:zipTestData") - } - def stdlibTestsZip = Paths.get(kotlinProj, "dist", "kotlin-stdlib-tests.zip").toFile() - if (stdlibTestsZip.exists()) { - update_stdlib_tests files(stdlibTestsZip) - updateTestData = false - } else { - println("WARNING: using stdlib tests provided by gradle.properties. Please execute :kotlin:zipTestData") - } - } } ext.testOutputRoot = rootProject.file("test.output").absolutePath ext.externalTestsDir = project.file("build/external") @@ -182,43 +164,6 @@ def installTestLib = tasks.register("installTestLibrary", KlibInstall) { } } -// Gets tests from the same Kotlin compiler build -def update_external_tests() { - // Copy only used tests into the test directory. - if (externalTestsDir.exists()) { - delete(externalTestsDir) - } - externalTestsDir.mkdirs() - - def compilerTestsFiles = configurations.update_tests.asFileTree - copy { - compilerTestsFiles.each { - from(zipTree(it)) - into(externalTestsDir) - include 'compiler/codegen/box/**' - include 'compiler/codegen/boxInline/**' - include 'compiler/compileKotlinAgainstKotlin/**' - include 'compiler/binaryCompatibility/klibEvolution/**' - exclude 'stdlib/**' - } - } - - if (externalStdlibTestsDir.exists()) { - delete(externalStdlibTestsDir) - } - externalStdlibTestsDir.mkdirs() - def stdlibTestsFiles = configurations.update_stdlib_tests.asFileTree - copy { - stdlibTestsFiles.each { - into(externalStdlibTestsDir) - include 'common/**' - include 'test/**' - exclude 'test/js/**' - include 'kotlin-test/**' - } - } -} - void konanc(String[] args) { def konancScript = isWindows() ? "konanc.bat" : "konanc" def konanc = "$dist/bin/$konancScript" @@ -229,7 +174,7 @@ void konanc(String[] args) { clean { doLast { - delete(rootProject.file(testOutputRoot)) + delete(project(":kotlin-native").file(testOutputRoot)) } } @@ -303,33 +248,13 @@ boolean isExcluded(String dir) { return result } -def createTestTasks(File testRoot, Class taskType) { - testRoot.eachDirRecurse { - // Skip build directory and directories without *.kt files. - if (it.name == "build" || it.listFiles().count { it.name.endsWith(".kt") && it.isFile() } == 0) { - return - } - - def taskDirectory = project.relativePath(it).substring("build/".length()) - if (!isExcluded(taskDirectory)) { - def taskName = taskDirectory.replaceAll("[-/\\\\]", '_') - project.tasks.register(taskName, taskType) { - it.groupDirectory = taskDirectory - it.finalizedBy resultsTask - } - } else { - println("$taskDirectory is excluded") - } - } -} - void dependsOnPlatformLibs(Task t) { if (!useCustomDist) { def testTarget = project.target if (testTarget != project.platformManager.Companion.host) { t.dependsOn(":${testTarget}PlatformLibs") } else { - t.dependsOn(':distPlatformLibs') + t.dependsOn(':kotlin-native:distPlatformLibs') } } } @@ -418,14 +343,28 @@ Task dynamicTest(String name, Closure configureClosure) { } } -task run_external () { - // Set this property to disable auto update tests - if (!project.hasProperty("test.disable_update")) { - update_external_tests() - } +def ignoredTests = [ + "compiler_testData_codegen_box_callableReference" : ["genericConstructorReference.kt"] +] - // Create tasks for external tests. - createTestTasks(externalTestsDir, RunExternalTestGroup) +task run_external () { + outputs.upToDateWhen{ false } + + rootProject.files( + 'compiler/testData/codegen/box', + 'compiler/codegen/boxInline', + 'compiler/compileKotlinAgainstKotlin' + ).asFileTree.visit { file -> + if (!file.isDirectory() || !file.file.list().any{ it.endsWith(".kt")}) + return + def taskPath = rootProject.relativePath(file.file) + def taskName = taskPath.split(System.properties["file.separator"]).join('_') + project.tasks.register(taskName, RunExternalTestGroup) { + it.groupDirectory = taskPath + it.finalizedBy resultsTask + it.ignoredTests = ignoredTests[taskName] + } + } // Set up dependencies. dependsOn(tasksOf(RunExternalTestGroup)) diff --git a/kotlin-native/build-tools/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy b/kotlin-native/build-tools/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy index d696fe700c4..87c5b198dfd 100644 --- a/kotlin-native/build-tools/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy +++ b/kotlin-native/build-tools/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy @@ -27,9 +27,10 @@ import java.util.function.Function import java.util.function.UnaryOperator import java.util.regex.Pattern import java.util.stream.Collectors +import java.io.File class RunExternalTestGroup extends JavaExec implements CompilerRunner { - def platformManager = project.rootProject.platformManager + def platformManager = project.project(":kotlin-native").platformManager def target = platformManager.targetManager(project.testTarget).target def dist = UtilsKt.getKotlinNativeDist(project) @@ -206,12 +207,14 @@ class RunExternalTestGroup extends JavaExec implements CompilerRunner { @Input def groupDirectory = "." + def ignoredTests = [] + String filter = project.findProperty("filter") def testGroupReporter = new KonanTestGroupReportEnvironment(project) void parseLanguageFlags(String src) { - def text = project.buildDir.toPath().resolve(src).text + def text = project.rootProject.file(src).text def languageSettings = findLinesWithPrefixesRemoved(text, "// !LANGUAGE: ") if (languageSettings.size() != 0) { languageSettings.forEach { line -> @@ -269,14 +272,13 @@ class RunExternalTestGroup extends JavaExec implements CompilerRunner { def boxPattern = ~/(?m)fun\s+box\s*\(\s*\)/ def classPattern = ~/.*(class|object|enum|interface)\s+(${identifier}*).*/ - def sourceName = "_" + normalize(project.buildDir.toPath().resolve(src).toFile().name) + def sourceName = "_" + normalize(project.rootProject.file(src).name) def packages = new LinkedHashSet() def imports = [] def classes = [] def vars = new HashSet() // variables that has the same name as a package TestModule mainModule = null - - def testFiles = TestDirectivesKt.buildCompileList(project.file("build/$src").toPath(), "$outputDirectory/$src") + def testFiles = TestDirectivesKt.buildCompileList(project.rootProject.file(src).toPath(), "$outputDirectory/${project.rootProject.file(src).name}") for (TestFile testFile: testFiles) { def text = testFile.text def filePath = testFile.path @@ -299,7 +301,7 @@ class RunExternalTestGroup extends JavaExec implements CompilerRunner { } // Find mutable objects that should be marked as ThreadLocal - if (filePath != "$outputDirectory/$src/helpers.kt") { + if (filePath != "$outputDirectory/${project.rootProject.file(src).name}/helpers.kt") { text = markMutableObjects(text) } testFile.text = text @@ -369,13 +371,13 @@ class RunExternalTestGroup extends JavaExec implements CompilerRunner { testFile.text = res } def launcherText = createLauncherFileText(src, imports) - testFiles.add(new TestFile("_launcher.kt", "$outputDirectory/$src/_launcher.kt".toString(), + testFiles.add(new TestFile("_launcher.kt", "$outputDirectory/${project.rootProject.file(src).name}/_launcher.kt".toString(), launcherText, mainModule != null ? mainModule : TestModule.default)) return testFiles } String normalize(String name) { - name.replace('.kt', '') + return name.replace('.kt', '') .replace('-','_') .replace('.', '_') } @@ -415,18 +417,22 @@ fun runTest() { } static def excludeList = [ - "external/compiler/codegen/boxInline/multiplatform/defaultArguments/receiversAndParametersInLambda.kt", // KT-36880 - "external/compiler/compileKotlinAgainstKotlin/specialBridgesInDependencies.kt", // KT-42723 - "external/compiler/codegen/box/collections/kt41123.kt", // KT-42723 - "external/compiler/codegen/box/multiplatform/multiModule/expectActualTypealiasLink.kt", // KT-40137 - "external/compiler/codegen/box/multiplatform/multiModule/expectActualMemberLink.kt", // KT-33091 - "external/compiler/codegen/box/multiplatform/multiModule/expectActualLink.kt", // KT-41901 - "external/compiler/codegen/box/coroutines/multiModule/", // KT-40121 - "external/compiler/codegen/box/defaultArguments/recursiveDefaultArguments.kt" // KT-42684 + "compiler/testData/codegen/boxInline/multiplatform/defaultArguments/receiversAndParametersInLambda.kt", // KT-36880 + "compiler/testData/compileKotlinAgainstKotlin/specialBridgesInDependencies.kt", // KT-42723 + "compiler/testData/codegen/box/collections/kt41123.kt", // KT-42723 + "compiler/testData/codegen/box/multiplatform/multiModule/expectActualTypealiasLink.kt", // KT-40137 + "compiler/testData/codegen/box/multiplatform/multiModule/expectActualMemberLink.kt", // KT-33091 + "compiler/testData/codegen/box/multiplatform/multiModule/expectActualLink.kt", // KT-41901 + "compiler/testData/codegen/box/coroutines/multiModule/", // KT-40121 + "compiler/testData/codegen/box/defaultArguments/recursiveDefaultArguments.kt" // KT-42684 ] boolean isEnabledForNativeBackend(String fileName) { - def text = project.buildDir.toPath().resolve(fileName).text + def testFile = project.rootProject.file(fileName) + def text = testFile.text + + if (testFile.name in ignoredTests) + return false if (excludeList.any { fileName.replace(File.separator, "/").contains(it) }) return false @@ -476,7 +482,7 @@ fun runTest() { void executeTest() { createOutputDirectory() // Form the test list. - List ktFiles = project.buildDir.toPath().resolve(groupDirectory).toFile() + def ktFiles = project.rootProject.projectDir.toPath().resolve(groupDirectory).toFile() .listFiles({ it.isFile() && it.name.endsWith(".kt") } as FileFilter) @@ -492,10 +498,9 @@ fun runTest() { flags = (flags ?: []) + "-tr" List compileList = [] ktFiles.each { - def src = project.buildDir.relativePath(it) + def src = project.rootProject.relativePath(it) if (isEnabledForNativeBackend(src)) { // Create separate output directory for each test in the group. - project.file("$outputDirectory/${it.name}").mkdirs() parseLanguageFlags(src) compileList.addAll(createTestFiles(src)) } @@ -543,7 +548,7 @@ fun runTest() { // Run the tests. arguments = (arguments ?: []) + "--ktest_logger=SILENT" ktFiles.each { file -> - def src = project.buildDir.relativePath(file) + def src = project.rootProject.relativePath(file) def savedArgs = arguments arguments += "--ktest_filter=_${normalize(file.name)}.*" use(KonanTestSuiteReportKt) { diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/TestDirectives.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/TestDirectives.kt index c604b49b009..005d3017b63 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/TestDirectives.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/TestDirectives.kt @@ -11,6 +11,7 @@ import java.nio.file.Path import java.nio.file.Paths import java.util.regex.Matcher import java.util.regex.Pattern +import java.io.File private const val MODULE_DELIMITER = ",\\s*" // These patterns are copies from