blob: e6a57ca96b8cf897c75f59d88eed07c799eb1ff3 [file]
// Copyright (c) 2026, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import java.io.File
import kotlin.io.path.listDirectoryEntries
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskAction
@CacheableTask
public abstract class CreateArtTestsTask : DefaultTask() {
@get:[InputFiles PathSensitive(PathSensitivity.RELATIVE)]
public abstract val artTestCaseDirectory: DirectoryProperty
@get:OutputDirectory public abstract val outputDir: DirectoryProperty
@TaskAction
public fun createTests() {
val outputDirectory = outputDir.get().asFile
outputDirectory.deleteRecursively()
val artTestCaseSubdirectory = File(artTestCaseDirectory.get().asFile, "dx")
check(artTestCaseSubdirectory.exists())
val subDirectories = artTestCaseSubdirectory.toPath().listDirectoryEntries()
val testCases = subDirectories.map { it.fileName.toString() }
for ((tool, toolEnum) in
listOf("r8" to "R8", "d8" to "R8_AFTER_D8", "r8cf" to "D8_AFTER_R8CF")) {
val packageDirectory = File(outputDirectory, "com/android/tools/r8/art/none/$tool")
packageDirectory.mkdirs()
for (testCase in testCases) {
val className = "Art${testCase.replace("-", "_")}Test"
val testRuntimes =
if (testCase == "800-smali")
"withDexRuntimesEndingAtExcluding(\n com.android.tools.r8.ToolHelper.DexVm.Version.V17_0_0)"
else "withDexRuntimes()"
File(packageDirectory, "$className.java")
.writeText(
"""// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.art.none.$tool;
import static com.android.tools.r8.R8RunArtTestsTest.DexTool.NONE;
import com.android.tools.r8.R8RunArtTestsTest;
import com.android.tools.r8.TestBase;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.TestParametersCollection;
import com.android.tools.r8.ToolHelper.DexVm;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/**
* Auto-generated test for the art $testCase test using the none toolchain.
*
* DO NOT EDIT THIS FILE. EDIT THE HERE DOCUMENT TEMPLATE IN d8_r8/commonBuildSrc/src/main/kotlin/CreateArtTestsTask.kt INSTEAD!
*/
@RunWith(Parameterized.class)
public class $className extends R8RunArtTestsTest {
@Parameters(name = "{0}")
public static TestParametersCollection data() {
return TestBase.getTestParameters().$testRuntimes.build();
}
private final TestParameters parameters;
public $className(TestParameters parameters) {
super("$testCase", NONE);
this.parameters = parameters;
}
@Test
public void test() throws Throwable {
runArtTest(parameters.getRuntime().asDex().getVm(), CompilerUnderTest.$toolEnum);
}
}
"""
)
}
}
}
}