kotlinx.atomicfu JVM/IR compiler plugin support

Merge-request: KT-MR-6541
Merged-by: Maria Sokolova <maria.sokolova@jetbrains.com>
This commit is contained in:
mvicsokolova
2022-06-26 07:17:06 +00:00
committed by Space
parent eaad75fd52
commit 8053746ae0
62 changed files with 4249 additions and 349 deletions
@@ -17,8 +17,8 @@ import org.jetbrains.kotlin.test.services.TestServices
import org.jetbrains.kotlinx.atomicfu.compiler.extensions.AtomicfuLoweringExtension
import java.io.File
private val atomicfuCompileDependency = System.getProperty("atomicfu.classpath")
private val atomicfuRuntime = System.getProperty("atomicfuRuntimeForTests.classpath")
private val atomicfuJsCompileDependency = System.getProperty("atomicfuJs.classpath")
private val atomicfuJsIrRuntime = System.getProperty("atomicfuJsIrRuntimeForTests.classpath")
open class AbstractAtomicfuJsIrTest : AbstractJsIrTest(
pathToTestDir = "plugins/atomicfu/atomicfu-compiler/testData/box/",
@@ -28,19 +28,21 @@ open class AbstractAtomicfuJsIrTest : AbstractJsIrTest(
super.configure(builder)
with(builder) {
useConfigurators(::AtomicfuEnvironmentConfigurator)
useCustomRuntimeClasspathProviders(::AtomicfuRuntimeClasspathProvider)
useCustomRuntimeClasspathProviders(::AtomicfuJsRuntimeClasspathProvider)
}
}
}
class AtomicfuRuntimeClasspathProvider(testServices: TestServices) : RuntimeClasspathProvider(testServices) {
override fun runtimeClassPaths(module: TestModule): List<File> {
return listOf(atomicfuCompileDependency, atomicfuRuntime).map { File(it) }
}
}
class AtomicfuEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigurator(testServices) {
override fun registerCompilerExtensions(project: Project, module: TestModule, configuration: CompilerConfiguration) {
IrGenerationExtension.registerExtension(project, AtomicfuLoweringExtension())
}
}
class AtomicfuJsRuntimeClasspathProvider(
testServices: TestServices
) : RuntimeClasspathProvider(testServices) {
override fun runtimeClassPaths(module: TestModule): List<File> {
return listOf(atomicfuJsCompileDependency, atomicfuJsIrRuntime).map { File(it) }
}
}
@@ -0,0 +1,74 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlinx.atomicfu
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.ObsoleteTestInfrastructure
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
import org.jetbrains.kotlin.codegen.AbstractAsmLikeInstructionListingTest
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.test.TargetBackend
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives
import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.runners.codegen.AbstractIrBlackBoxCodegenTest
import org.jetbrains.kotlin.test.services.EnvironmentConfigurator
import org.jetbrains.kotlin.test.services.RuntimeClasspathProvider
import org.jetbrains.kotlin.utils.PathUtil
import org.jetbrains.kotlinx.atomicfu.compiler.extensions.AtomicfuComponentRegistrar
import java.io.File
private val coreLibraryPath = getLibraryJar("kotlinx.atomicfu.AtomicFU")
private val kotlinTestPath = getLibraryJar("kotlin.test.AssertionsKt")
private val javaUtilConcurrentPath = getLibraryJar("java.util.concurrent.atomic.AtomicIntegerFieldUpdater")
private val kotlinJvm = getLibraryJar("kotlin.jvm.JvmField")
open class AbstractAtomicfuJvmIrTest : AbstractIrBlackBoxCodegenTest() {
override fun configure(builder: TestConfigurationBuilder) {
super.configure(builder)
val librariesPaths = listOf(coreLibraryPath!!, kotlinTestPath!!, javaUtilConcurrentPath!!, kotlinJvm!!)
builder.configureForKotlinxAtomicfu(librariesPaths)
}
}
private fun getLibraryJar(classToDetect: String): File? = try {
PathUtil.getResourcePathForClass(Class.forName(classToDetect))
} catch (e: ClassNotFoundException) {
null
}
private fun TestConfigurationBuilder.configureForKotlinxAtomicfu(librariesPaths: List<File>) {
useConfigurators(
{ services ->
object : EnvironmentConfigurator(services) {
override fun configureCompilerConfiguration(
configuration: CompilerConfiguration,
module: TestModule
) {
configuration.addJvmClasspathRoots(librariesPaths)
}
override fun registerCompilerExtensions(project: Project, module: TestModule, configuration: CompilerConfiguration) {
AtomicfuComponentRegistrar.registerExtensions(project)
}
}
})
useCustomRuntimeClasspathProviders(
{
object : RuntimeClasspathProvider(it) {
override fun runtimeClassPaths(module: TestModule): List<File> = librariesPaths
}
}
)
defaultDirectives {
+CodegenTestDirectives.CHECK_BYTECODE_LISTING
}
}
@@ -32,9 +32,15 @@ public class AtomicfuJsIrTestGenerated extends AbstractAtomicfuJsIrTest {
}
@Test
@TestMetadata("ArrayInlineFunctionTest.kt")
public void testArrayInlineFunctionTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/ArrayInlineFunctionTest.kt");
@TestMetadata("ArrayInlineExtensionTest.kt")
public void testArrayInlineExtensionTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/ArrayInlineExtensionTest.kt");
}
@Test
@TestMetadata("ArrayLoopTest.kt")
public void testArrayLoopTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/ArrayLoopTest.kt");
}
@Test
@@ -43,12 +49,24 @@ public class AtomicfuJsIrTestGenerated extends AbstractAtomicfuJsIrTest {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/AtomicArrayTest.kt");
}
@Test
@TestMetadata("ComplexLoopTest.kt")
public void testComplexLoopTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/ComplexLoopTest.kt");
}
@Test
@TestMetadata("DelegatedPropertiesTest.kt")
public void testDelegatedPropertiesTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/DelegatedPropertiesTest.kt");
}
@Test
@TestMetadata("ExtensionLoopTest.kt")
public void testExtensionLoopTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/ExtensionLoopTest.kt");
}
@Test
@TestMetadata("ExtensionsTest.kt")
public void testExtensionsTest() throws Exception {
@@ -67,6 +85,18 @@ public class AtomicfuJsIrTestGenerated extends AbstractAtomicfuJsIrTest {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/InlineExtensionWithTypeParameterTest.kt");
}
@Test
@TestMetadata("LambdaTest.kt")
public void testLambdaTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/LambdaTest.kt");
}
@Test
@TestMetadata("LateinitPropertiesTest.kt")
public void testLateinitPropertiesTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/LateinitPropertiesTest.kt");
}
@Test
@TestMetadata("LockFreeIntBitsTest.kt")
public void testLockFreeIntBitsTest() throws Exception {
@@ -115,12 +145,6 @@ public class AtomicfuJsIrTestGenerated extends AbstractAtomicfuJsIrTest {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/ParameterizedInlineFunExtensionTest.kt");
}
@Test
@TestMetadata("PropertyDeclarationTest.kt")
public void testPropertyDeclarationTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/PropertyDeclarationTest.kt");
}
@Test
@TestMetadata("ReentrantLockTest.kt")
public void testReentrantLockTest() throws Exception {
@@ -0,0 +1,189 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlinx.atomicfu;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("plugins/atomicfu/atomicfu-compiler/testData/box")
@TestDataPath("$PROJECT_ROOT")
public class AtomicfuJvmIrTestGenerated extends AbstractAtomicfuJvmIrTest {
@Test
public void testAllFilesPresentInBox() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/atomicfu/atomicfu-compiler/testData/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("ArithmeticTest.kt")
public void testArithmeticTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/ArithmeticTest.kt");
}
@Test
@TestMetadata("ArrayInlineExtensionTest.kt")
public void testArrayInlineExtensionTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/ArrayInlineExtensionTest.kt");
}
@Test
@TestMetadata("ArrayLoopTest.kt")
public void testArrayLoopTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/ArrayLoopTest.kt");
}
@Test
@TestMetadata("AtomicArrayTest.kt")
public void testAtomicArrayTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/AtomicArrayTest.kt");
}
@Test
@TestMetadata("ComplexLoopTest.kt")
public void testComplexLoopTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/ComplexLoopTest.kt");
}
@Test
@TestMetadata("DelegatedPropertiesTest.kt")
public void testDelegatedPropertiesTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/DelegatedPropertiesTest.kt");
}
@Test
@TestMetadata("ExtensionLoopTest.kt")
public void testExtensionLoopTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/ExtensionLoopTest.kt");
}
@Test
@TestMetadata("ExtensionsTest.kt")
public void testExtensionsTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/ExtensionsTest.kt");
}
@Test
@TestMetadata("IndexArrayElementGetterTest.kt")
public void testIndexArrayElementGetterTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/IndexArrayElementGetterTest.kt");
}
@Test
@TestMetadata("InlineExtensionWithTypeParameterTest.kt")
public void testInlineExtensionWithTypeParameterTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/InlineExtensionWithTypeParameterTest.kt");
}
@Test
@TestMetadata("LambdaTest.kt")
public void testLambdaTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/LambdaTest.kt");
}
@Test
@TestMetadata("LateinitPropertiesTest.kt")
public void testLateinitPropertiesTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/LateinitPropertiesTest.kt");
}
@Test
@TestMetadata("LockFreeIntBitsTest.kt")
public void testLockFreeIntBitsTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/LockFreeIntBitsTest.kt");
}
@Test
@TestMetadata("LockFreeLongCounterTest.kt")
public void testLockFreeLongCounterTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/LockFreeLongCounterTest.kt");
}
@Test
@TestMetadata("LockFreeQueueTest.kt")
public void testLockFreeQueueTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/LockFreeQueueTest.kt");
}
@Test
@TestMetadata("LockFreeStackTest.kt")
public void testLockFreeStackTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/LockFreeStackTest.kt");
}
@Test
@TestMetadata("LockTest.kt")
public void testLockTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/LockTest.kt");
}
@Test
@TestMetadata("LoopTest.kt")
public void testLoopTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/LoopTest.kt");
}
@Test
@TestMetadata("MultiInitTest.kt")
public void testMultiInitTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/MultiInitTest.kt");
}
@Test
@TestMetadata("ParameterizedInlineFunExtensionTest.kt")
public void testParameterizedInlineFunExtensionTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/ParameterizedInlineFunExtensionTest.kt");
}
@Test
@TestMetadata("ReentrantLockTest.kt")
public void testReentrantLockTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/ReentrantLockTest.kt");
}
@Test
@TestMetadata("ScopeTest.kt")
public void testScopeTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/ScopeTest.kt");
}
@Test
@TestMetadata("SimpleLockTest.kt")
public void testSimpleLockTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/SimpleLockTest.kt");
}
@Test
@TestMetadata("SynchronizedObjectTest.kt")
public void testSynchronizedObjectTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/SynchronizedObjectTest.kt");
}
@Test
@TestMetadata("TopLevelTest.kt")
public void testTopLevelTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/TopLevelTest.kt");
}
@Test
@TestMetadata("TraceTest.kt")
public void testTraceTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/TraceTest.kt");
}
@Test
@TestMetadata("UncheckedCastTest.kt")
public void testUncheckedCastTest() throws Exception {
runTest("plugins/atomicfu/atomicfu-compiler/testData/box/UncheckedCastTest.kt");
}
}