From c1651714711eec5507c95907222d8e3e73b919a7 Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Tue, 5 Dec 2023 14:00:13 +0200 Subject: [PATCH] [Native][tests] Port KT-36639 test case to the new infra --- .../backend.native/tests/build.gradle | 6 --- .../testData/CExport/kt36639}/main-main.out | 0 .../testData/CExport/kt36639}/main.c | 6 +-- .../testData/CExport/kt36639}/main.kt | 0 .../blackbox/CExportTestDynamicGenerated.java | 38 +++++++++++++++++ .../blackbox/CExportTestStaticGenerated.java | 38 +++++++++++++++++ .../FirCExportTestDynamicGenerated.java | 42 +++++++++++++++++++ .../FirCExportTestStaticGenerated.java | 42 +++++++++++++++++++ .../blackbox/AbstractNativeCExportTest.kt | 11 +++-- 9 files changed, 171 insertions(+), 12 deletions(-) rename {kotlin-native/backend.native/tests/produce_dynamic/kt-36639 => native/native.tests/testData/CExport/kt36639}/main-main.out (100%) rename {kotlin-native/backend.native/tests/produce_dynamic/kt-36639 => native/native.tests/testData/CExport/kt36639}/main.c (88%) rename {kotlin-native/backend.native/tests/produce_dynamic/kt-36639 => native/native.tests/testData/CExport/kt36639}/main.kt (100%) create mode 100644 native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportTestDynamicGenerated.java create mode 100644 native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportTestStaticGenerated.java create mode 100644 native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportTestDynamicGenerated.java create mode 100644 native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportTestStaticGenerated.java diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index d9550471178..11ac32f322c 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -2000,12 +2000,6 @@ dynamicTest("produce_dynamic") { useGoldenData = true } -dynamicTest("kt36639") { - source = "produce_dynamic/kt-36639/main.kt" - cSource = "$projectDir/produce_dynamic/kt-36639/main.c" - useGoldenData = true -} - dynamicTest("kt36878") { source = "produce_dynamic/kt-36878/hello.kt" cSource = "$projectDir/produce_dynamic/kt-36878/main.c" diff --git a/kotlin-native/backend.native/tests/produce_dynamic/kt-36639/main-main.out b/native/native.tests/testData/CExport/kt36639/main-main.out similarity index 100% rename from kotlin-native/backend.native/tests/produce_dynamic/kt-36639/main-main.out rename to native/native.tests/testData/CExport/kt36639/main-main.out diff --git a/kotlin-native/backend.native/tests/produce_dynamic/kt-36639/main.c b/native/native.tests/testData/CExport/kt36639/main.c similarity index 88% rename from kotlin-native/backend.native/tests/produce_dynamic/kt-36639/main.c rename to native/native.tests/testData/CExport/kt36639/main.c index b2236dbc277..2dcfd45dfa0 100644 --- a/kotlin-native/backend.native/tests/produce_dynamic/kt-36639/main.c +++ b/native/native.tests/testData/CExport/kt36639/main.c @@ -1,7 +1,7 @@ -#include "testlib_api.h" +#include "kt36639_api.h" -#define __ testlib_symbols()-> -#define T_(x) testlib_kref_ ## x +#define __ kt36639_symbols()-> +#define T_(x) kt36639_kref_ ## x int diff --git a/kotlin-native/backend.native/tests/produce_dynamic/kt-36639/main.kt b/native/native.tests/testData/CExport/kt36639/main.kt similarity index 100% rename from kotlin-native/backend.native/tests/produce_dynamic/kt-36639/main.kt rename to native/native.tests/testData/CExport/kt36639/main.kt diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportTestDynamicGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportTestDynamicGenerated.java new file mode 100644 index 00000000000..050e29c6ceb --- /dev/null +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportTestDynamicGenerated.java @@ -0,0 +1,38 @@ +/* + * Copyright 2010-2024 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.kotlin.konan.test.blackbox; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +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 org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("native/native.tests/testData/CExport") +@TestDataPath("$PROJECT_ROOT") +public class CExportTestDynamicGenerated extends AbstractNativeCExportDynamicTest { + @Test + public void testAllFilesPresentInCExport() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CExport"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("kt36639") + public void testKt36639() throws Exception { + runTest("native/native.tests/testData/CExport/kt36639/"); + } + + @Test + @TestMetadata("smoke0") + public void testSmoke0() throws Exception { + runTest("native/native.tests/testData/CExport/smoke0/"); + } +} diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportTestStaticGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportTestStaticGenerated.java new file mode 100644 index 00000000000..67ca46be7cc --- /dev/null +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/CExportTestStaticGenerated.java @@ -0,0 +1,38 @@ +/* + * Copyright 2010-2024 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.kotlin.konan.test.blackbox; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +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 org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("native/native.tests/testData/CExport") +@TestDataPath("$PROJECT_ROOT") +public class CExportTestStaticGenerated extends AbstractNativeCExportStaticTest { + @Test + public void testAllFilesPresentInCExport() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CExport"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("kt36639") + public void testKt36639() throws Exception { + runTest("native/native.tests/testData/CExport/kt36639/"); + } + + @Test + @TestMetadata("smoke0") + public void testSmoke0() throws Exception { + runTest("native/native.tests/testData/CExport/smoke0/"); + } +} diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportTestDynamicGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportTestDynamicGenerated.java new file mode 100644 index 00000000000..9ff58c2183f --- /dev/null +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportTestDynamicGenerated.java @@ -0,0 +1,42 @@ +/* + * Copyright 2010-2024 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.kotlin.konan.test.blackbox; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.junit.jupiter.api.Tag; +import org.jetbrains.kotlin.konan.test.blackbox.support.group.FirPipeline; +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 org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("native/native.tests/testData/CExport") +@TestDataPath("$PROJECT_ROOT") +@Tag("frontend-fir") +@FirPipeline() +public class FirCExportTestDynamicGenerated extends AbstractNativeCExportDynamicTest { + @Test + public void testAllFilesPresentInCExport() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CExport"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("kt36639") + public void testKt36639() throws Exception { + runTest("native/native.tests/testData/CExport/kt36639/"); + } + + @Test + @TestMetadata("smoke0") + public void testSmoke0() throws Exception { + runTest("native/native.tests/testData/CExport/smoke0/"); + } +} diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportTestStaticGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportTestStaticGenerated.java new file mode 100644 index 00000000000..c45e08f0e48 --- /dev/null +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirCExportTestStaticGenerated.java @@ -0,0 +1,42 @@ +/* + * Copyright 2010-2024 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.kotlin.konan.test.blackbox; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.junit.jupiter.api.Tag; +import org.jetbrains.kotlin.konan.test.blackbox.support.group.FirPipeline; +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 org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("native/native.tests/testData/CExport") +@TestDataPath("$PROJECT_ROOT") +@Tag("frontend-fir") +@FirPipeline() +public class FirCExportTestStaticGenerated extends AbstractNativeCExportStaticTest { + @Test + public void testAllFilesPresentInCExport() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CExport"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("kt36639") + public void testKt36639() throws Exception { + runTest("native/native.tests/testData/CExport/kt36639/"); + } + + @Test + @TestMetadata("smoke0") + public void testSmoke0() throws Exception { + runTest("native/native.tests/testData/CExport/smoke0/"); + } +} diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/AbstractNativeCExportTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/AbstractNativeCExportTest.kt index 36a26bd116f..0d5c1410518 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/AbstractNativeCExportTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/AbstractNativeCExportTest.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.TestCompilat import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.TestCompilationFactory import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.TestCompilationResult.Companion.assertSuccess import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestExecutable +import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestRunCheck import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestRunChecks import org.jetbrains.kotlin.konan.test.blackbox.support.settings.Timeouts import org.jetbrains.kotlin.konan.test.blackbox.support.settings.configurables @@ -51,7 +52,11 @@ abstract class AbstractNativeCExportTest( .filter { it.endsWith(".c") } .map { testPathFull.resolve(it) } - val testCase = generateCExportTestCase(testPathFull, ktSources) + val goldenData = testPathFull.list()!! + .singleOrNull { it.endsWith(".out") } + ?.let { testPathFull.resolve(it) } + + val testCase = generateCExportTestCase(testPathFull, ktSources, goldenData = goldenData) val binaryLibrary = testCompilationFactory.testCaseToBinaryLibrary( testCase, testRunSettings, @@ -80,7 +85,7 @@ abstract class AbstractNativeCExportTest( runExecutableAndVerify(testCase, testExecutable) } - private fun generateCExportTestCase(testPathFull: File, sources: List): TestCase { + private fun generateCExportTestCase(testPathFull: File, sources: List, goldenData: File? = null): TestCase { val moduleName: String = testPathFull.name val module = TestModule.Exclusive(DEFAULT_MODULE_NAME, emptySet(), emptySet(), emptySet()) sources.forEach { module.files += TestFile.createCommitted(it, module) } @@ -94,7 +99,7 @@ abstract class AbstractNativeCExportTest( checks = TestRunChecks( executionTimeoutCheck = TestRunCheck.ExecutionTimeout.ShouldNotExceed(testRunSettings.get().executionTimeout), exitCodeCheck = TestRunCheck.ExitCode.Expected(0), - outputDataFile = goldenData?.let { TestRunCheck.OutputDataFile(file = it) }, + outputDataFile = goldenData?.let { TestRunCheck.OutputDataFile(it) }, outputMatcher = null, fileCheckMatcher = null, ),