[K/N][Tests] Migrate test signext_zeroext_objc_export.kt

^KT-61259
This commit is contained in:
Vladimir Sukharev
2024-02-07 11:50:04 +01:00
committed by Space Team
parent f3d3ae8416
commit 7cb372e66f
5 changed files with 112 additions and 67 deletions
@@ -2016,12 +2016,6 @@ Task fileCheckTest(String name, Closure<FileCheckTest> configureClosure) {
}
}
fileCheckTest("filecheck_signext_zeroext_objc_export") {
annotatedSource = project.file('filecheck/signext_zeroext_objc_export.kt')
generateFramework = true
enabled = target.family.appleFamily
}
dependencies {
nopPluginApi kotlinCompilerModule
nopPluginApi project(":native:kotlin-native-utils")
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.konan.test.blackbox.support.group.FirPipeline
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.runner.doFileCheck
import org.jetbrains.kotlin.konan.test.blackbox.support.settings.*
import org.jetbrains.kotlin.konan.test.blackbox.support.util.createTestProvider
import org.jetbrains.kotlin.native.executors.runProcess
@@ -39,6 +40,47 @@ abstract class FrameworkTestBase : AbstractNativeSimpleTest() {
private val extras = TestCase.NoTestRunnerExtras("There's no entrypoint in Swift program")
private val testCompilationFactory = TestCompilationFactory()
@Test
fun testSignextZeroext() {
Assumptions.assumeTrue(targets.testTarget.family.isAppleFamily)
val fileCheckStage = "CStubs"
val testDataFile = testSuiteDir.resolve("signext_zeroext_objc_export.kt")
val testCase = generateObjCFrameworkTestCase(
TestKind.STANDALONE_NO_TR,
extras,
"SignextZeroext",
listOf(testDataFile),
TestCompilerArgs(
listOf(
"-Xbinary=bundleId=signextZeroext",
"-Xsave-llvm-ir-after=$fileCheckStage",
"-Xsave-llvm-ir-directory=${buildDir.absolutePath}",
)
),
givenDependencies = emptySet(),
checks = TestRunChecks.Default(Duration.ZERO)
.copy(fileCheckMatcher = TestRunCheck.FileCheckMatcher(testRunSettings, testDataFile))
)
val objCFrameworkCompilation = testCompilationFactory.testCaseToObjCFrameworkCompilation(testCase, testRunSettings)
objCFrameworkCompilation.result.assertSuccess()
val (result, outText, errText) = doFileCheck(
testCase.checks.fileCheckMatcher!!,
buildDir.resolve("out.$fileCheckStage.ll").also { assert(it.exists()) }
)
if (!(result == 0 && errText.isEmpty() && outText.isEmpty())) {
val shortOutText = outText.lines().take(100)
val shortErrText = errText.lines().take(100)
assert(false) {
"FileCheck matching of ${buildDir.resolve("out.$fileCheckStage.ll").also { assert(it.exists()) }.absolutePath}\n" +
"with '--check-prefixes ${testCase.checks.fileCheckMatcher.prefixes}'\n" +
"failed with result=$result:\n" +
shortOutText.joinToString("\n") + "\n" +
shortErrText.joinToString("\n")
}
}
}
@Test
fun testValuesGenerics() {
Assumptions.assumeTrue(targets.testTarget.family.isAppleFamily)
@@ -7,19 +7,12 @@ package org.jetbrains.kotlin.konan.test.blackbox.support.runner
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.text.StringUtilRt.convertLineSeparators
import org.jetbrains.kotlin.konan.target.Architecture
import org.jetbrains.kotlin.konan.target.KonanTarget
import org.jetbrains.kotlin.konan.target.needSmallBinary
import org.jetbrains.kotlin.konan.test.blackbox.support.LoggedData
import org.jetbrains.kotlin.konan.test.blackbox.support.TestName
import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestRunCheck.ExecutionTimeout
import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestRunCheck.ExitCode
import org.jetbrains.kotlin.konan.test.blackbox.support.settings.CacheMode
import org.jetbrains.kotlin.konan.test.blackbox.support.settings.KotlinNativeTargets
import org.jetbrains.kotlin.konan.test.blackbox.support.settings.OptimizationMode
import org.jetbrains.kotlin.konan.test.blackbox.support.settings.configurables
import org.jetbrains.kotlin.konan.test.blackbox.support.util.TestReport
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toUpperCaseAsciiOnly
import org.junit.jupiter.api.Assumptions
import java.io.File
@@ -85,57 +78,16 @@ internal class ResultHandler(
}
}
is TestRunCheck.FileCheckMatcher -> {
val fileCheckExecutable = check.settings.configurables.absoluteLlvmHome + File.separator + "bin" + File.separator +
if (SystemInfo.isWindows) "FileCheck.exe" else "FileCheck"
require(File(fileCheckExecutable).exists()) {
"$fileCheckExecutable does not exist. Make sure Distribution for `settings.configurables` " +
"was created using `propertyOverrides` to specify development variant of LLVM instead of user variant."
}
val fileCheckDump = runResult.testExecutable.executable.fileCheckDump!!
val fileCheckOut = File(fileCheckDump.absolutePath + ".out")
val fileCheckErr = File(fileCheckDump.absolutePath + ".err")
val testTarget = check.settings.get<KotlinNativeTargets>().testTarget
val checkPrefixes = buildList {
add("CHECK")
add("CHECK-${testTarget.abiInfoString}")
add("CHECK-${testTarget.name.toUpperCaseAsciiOnly()}")
if (testTarget.family.isAppleFamily) {
add("CHECK-APPLE")
}
if (testTarget.needSmallBinary()) {
add("CHECK-SMALLBINARY")
} else {
add("CHECK-BIGBINARY")
}
}
val optimizationMode = check.settings.get<OptimizationMode>().name
val checkPrefixesWithOptMode = checkPrefixes.map { "$it-$optimizationMode" }
val cacheMode = check.settings.get<CacheMode>().alias
val checkPrefixesWithCacheMode = checkPrefixes.map { "$it-CACHE_$cacheMode" }
val commaSeparatedCheckPrefixes = (checkPrefixes + checkPrefixesWithOptMode + checkPrefixesWithCacheMode).joinToString(",")
val result = ProcessBuilder(
fileCheckExecutable,
check.testDataFile.absolutePath,
"--input-file",
fileCheckDump.absolutePath,
"--check-prefixes", commaSeparatedCheckPrefixes,
"--allow-deprecated-dag-overlap" // TODO specify it via new test directive for `function_attributes_at_callsite.kt`
).redirectOutput(fileCheckOut)
.redirectError(fileCheckErr)
.start()
.waitFor()
val errText = fileCheckErr.readText()
val outText = fileCheckOut.readText()
if(!(result == 0 && errText.isEmpty() && outText.isEmpty())) {
val (result, outText, errText) = doFileCheck(check, fileCheckDump)
if (!(result == 0 && errText.isEmpty() && outText.isEmpty())) {
val shortOutText = outText.lines().take(100)
val shortErrText = errText.lines().take(100)
add("FileCheck matching of ${fileCheckDump.absolutePath}\n" +
"with '--check-prefixes $commaSeparatedCheckPrefixes'\n" +
"failed with result=$result:\n" +
shortOutText.joinToString("\n") + "\n" +
shortErrText.joinToString("\n")
"with '--check-prefixes ${check.prefixes}'\n" +
"failed with result=$result:\n" +
shortOutText.joinToString("\n") + "\n" +
shortErrText.joinToString("\n")
)
}
}
@@ -195,10 +147,29 @@ internal class ResultHandler(
}
}
// Shameless borrowing `val KonanTarget.abiInfo` from module `:kotlin-native:backend.native`, which cannot be imported here for now.
private val KonanTarget.abiInfoString: String
get() = when {
this == KonanTarget.MINGW_X64 -> "WINDOWSX64"
!family.isAppleFamily && architecture == Architecture.ARM64 -> "AAPCS"
else -> "DEFAULTABI"
internal fun doFileCheck(check: TestRunCheck.FileCheckMatcher, fileCheckDump: File): Triple<Int, String, String> {
val fileCheckExecutable = check.settings.configurables.absoluteLlvmHome + File.separator + "bin" + File.separator +
if (SystemInfo.isWindows) "FileCheck.exe" else "FileCheck"
require(File(fileCheckExecutable).exists()) {
"$fileCheckExecutable does not exist. Make sure Distribution for `settings.configurables` " +
"was created using `propertyOverrides` to specify development variant of LLVM instead of user variant."
}
val fileCheckOut = File(fileCheckDump.absolutePath + ".out")
val fileCheckErr = File(fileCheckDump.absolutePath + ".err")
val result = ProcessBuilder(
fileCheckExecutable,
check.testDataFile.absolutePath,
"--input-file",
fileCheckDump.absolutePath,
"--check-prefixes", check.prefixes,
"--allow-deprecated-dag-overlap" // TODO specify it via new test directive for `function_attributes_at_callsite.kt`
).redirectOutput(fileCheckOut)
.redirectError(fileCheckErr)
.start()
.waitFor()
val outText = fileCheckOut.readText()
val errText = fileCheckErr.readText()
return Triple(result, outText, errText)
}
@@ -5,8 +5,15 @@
package org.jetbrains.kotlin.konan.test.blackbox.support.runner
import org.jetbrains.kotlin.konan.target.Architecture
import org.jetbrains.kotlin.konan.target.KonanTarget
import org.jetbrains.kotlin.konan.target.needSmallBinary
import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestRunCheck.*
import org.jetbrains.kotlin.konan.test.blackbox.support.settings.CacheMode
import org.jetbrains.kotlin.konan.test.blackbox.support.settings.KotlinNativeTargets
import org.jetbrains.kotlin.konan.test.blackbox.support.settings.OptimizationMode
import org.jetbrains.kotlin.konan.test.blackbox.support.settings.Settings
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toUpperCaseAsciiOnly
import org.jetbrains.kotlin.utils.yieldIfNotNull
import java.io.File
import kotlin.time.Duration
@@ -36,7 +43,30 @@ internal sealed interface TestRunCheck {
class OutputMatcher(val output: Output = Output.ALL, val match: (String) -> Boolean): TestRunCheck
class FileCheckMatcher(val settings: Settings, val testDataFile: File): TestRunCheck
class FileCheckMatcher(val settings: Settings, val testDataFile: File) : TestRunCheck {
val prefixes: String
get() {
val testTarget = settings.get<KotlinNativeTargets>().testTarget
val checkPrefixes = buildList {
add("CHECK")
add("CHECK-${testTarget.abiInfoString}")
add("CHECK-${testTarget.name.toUpperCaseAsciiOnly()}")
if (testTarget.family.isAppleFamily) {
add("CHECK-APPLE")
}
if (testTarget.needSmallBinary()) {
add("CHECK-SMALLBINARY")
} else {
add("CHECK-BIGBINARY")
}
}
val optimizationMode = settings.get<OptimizationMode>().name
val checkPrefixesWithOptMode = checkPrefixes.map { "$it-$optimizationMode" }
val cacheMode = settings.get<CacheMode>().alias
val checkPrefixesWithCacheMode = checkPrefixes.map { "$it-CACHE_$cacheMode" }
return (checkPrefixes + checkPrefixesWithOptMode + checkPrefixesWithCacheMode).joinToString(",")
}
}
}
internal data class TestRunChecks(
@@ -67,3 +97,11 @@ internal data class TestRunChecks(
)
}
}
// Shameless borrowing `val KonanTarget.abiInfo` from module `:kotlin-native:backend.native`, which cannot be imported here for now.
private val KonanTarget.abiInfoString: String
get() = when {
this == KonanTarget.MINGW_X64 -> "WINDOWSX64"
!family.isAppleFamily && architecture == Architecture.ARM64 -> "AAPCS"
else -> "DEFAULTABI"
}