[K/N][Tests] Use runProcess in doFileCheck

^KT-61259
This commit is contained in:
Vladimir Sukharev
2024-02-08 23:44:23 +01:00
committed by Space Team
parent 7cb372e66f
commit a0ffea48a2
9 changed files with 72 additions and 33 deletions
@@ -19522,6 +19522,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
runTest("compiler/testData/codegen/box/fileCheck/escape_analysis.kt");
}
@Test
@TestMetadata("filecheck_expected_failure.kt")
public void testFilecheck_expected_failure() throws Exception {
runTest("compiler/testData/codegen/box/fileCheck/filecheck_expected_failure.kt");
}
@Test
@TestMetadata("force_arm_instruction_set.kt")
public void testForce_arm_instruction_set() throws Exception {
@@ -19522,6 +19522,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
runTest("compiler/testData/codegen/box/fileCheck/escape_analysis.kt");
}
@Test
@TestMetadata("filecheck_expected_failure.kt")
public void testFilecheck_expected_failure() throws Exception {
runTest("compiler/testData/codegen/box/fileCheck/filecheck_expected_failure.kt");
}
@Test
@TestMetadata("force_arm_instruction_set.kt")
public void testForce_arm_instruction_set() throws Exception {
@@ -0,0 +1,8 @@
// TARGET_BACKEND: NATIVE
// IGNORE_BACKEND: NATIVE
// FILECHECK_STAGE: CStubs
// The check below is intentionally wrong and must fail.
// Test system should report test as passed due to IGNORE_BACKEND directive above.
// CHECK-LABEL: NONEXISTENT
fun box(): String = "OK"
@@ -16198,6 +16198,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
runTest("compiler/testData/codegen/box/fileCheck/escape_analysis.kt");
}
@Test
@TestMetadata("filecheck_expected_failure.kt")
public void testFilecheck_expected_failure() throws Exception {
runTest("compiler/testData/codegen/box/fileCheck/filecheck_expected_failure.kt");
}
@Test
@TestMetadata("force_arm_instruction_set.kt")
public void testForce_arm_instruction_set() throws Exception {
@@ -16576,6 +16576,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
runTest("compiler/testData/codegen/box/fileCheck/escape_analysis.kt");
}
@Test
@TestMetadata("filecheck_expected_failure.kt")
public void testFilecheck_expected_failure() throws Exception {
runTest("compiler/testData/codegen/box/fileCheck/filecheck_expected_failure.kt");
}
@Test
@TestMetadata("force_arm_instruction_set.kt")
public void testForce_arm_instruction_set() throws Exception {
@@ -15820,6 +15820,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
runTest("compiler/testData/codegen/box/fileCheck/escape_analysis.kt");
}
@Test
@TestMetadata("filecheck_expected_failure.kt")
public void testFilecheck_expected_failure() throws Exception {
runTest("compiler/testData/codegen/box/fileCheck/filecheck_expected_failure.kt");
}
@Test
@TestMetadata("force_arm_instruction_set.kt")
public void testForce_arm_instruction_set() throws Exception {
@@ -16199,6 +16199,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
runTest("compiler/testData/codegen/box/fileCheck/escape_analysis.kt");
}
@Test
@TestMetadata("filecheck_expected_failure.kt")
public void testFilecheck_expected_failure() throws Exception {
runTest("compiler/testData/codegen/box/fileCheck/filecheck_expected_failure.kt");
}
@Test
@TestMetadata("force_arm_instruction_set.kt")
public void testForce_arm_instruction_set() throws Exception {
@@ -64,20 +64,17 @@ abstract class FrameworkTestBase : AbstractNativeSimpleTest() {
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" +
val fileCheckDump = buildDir.resolve("out.$fileCheckStage.ll").also { assert(it.exists()) }
val result = doFileCheck(testCase.checks.fileCheckMatcher!!, fileCheckDump)
if (!(result.stdout.isEmpty() && result.stderr.isEmpty())) {
val shortOutText = result.stdout.lines().take(100)
val shortErrText = result.stderr.lines().take(100)
fail("FileCheck matching of ${fileCheckDump.absolutePath}\n" +
"with '--check-prefixes ${testCase.checks.fileCheckMatcher.prefixes}'\n" +
"failed with result=$result:\n" +
shortOutText.joinToString("\n") + "\n" +
shortErrText.joinToString("\n")
}
)
}
}
@@ -13,8 +13,11 @@ import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestRunCheck.Exec
import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestRunCheck.ExitCode
import org.jetbrains.kotlin.konan.test.blackbox.support.settings.configurables
import org.jetbrains.kotlin.konan.test.blackbox.support.util.TestReport
import org.jetbrains.kotlin.native.executors.RunProcessResult
import org.jetbrains.kotlin.native.executors.runProcess
import org.junit.jupiter.api.Assumptions
import java.io.File
import kotlin.time.Duration
private fun RunResult.processOutputAsString(output: TestRunCheck.Output) = when (output) {
TestRunCheck.Output.STDOUT -> processOutput.stdOut.filteredOutput
@@ -79,10 +82,11 @@ internal class ResultHandler(
}
is TestRunCheck.FileCheckMatcher -> {
val fileCheckDump = runResult.testExecutable.executable.fileCheckDump!!
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)
val result = doFileCheck(check, fileCheckDump)
if (!(result.stdout.isEmpty() && result.stderr.isEmpty())) {
val shortOutText = result.stdout.lines().take(100)
val shortErrText = result.stderr.lines().take(100)
add("FileCheck matching of ${fileCheckDump.absolutePath}\n" +
"with '--check-prefixes ${check.prefixes}'\n" +
"failed with result=$result:\n" +
@@ -147,29 +151,23 @@ internal class ResultHandler(
}
}
internal fun doFileCheck(check: TestRunCheck.FileCheckMatcher, fileCheckDump: File): Triple<Int, String, String> {
internal fun doFileCheck(check: TestRunCheck.FileCheckMatcher, fileCheckDump: File): RunProcessResult {
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)
return try {
runProcess(
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`
)
} catch (t: Throwable) {
RunProcessResult(Duration.ZERO, "FileCheck utility failed:", t.toString())
}
}