Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Windows IOS integration tests #1739

Merged
merged 11 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private fun shouldDownloadBinaries(): Boolean {
}

private fun neededFilesListByOs(): List<String> = if (isWindows) {
listOf("libatomic.so.1", "libatomic.so.1.2.0", "nm.exe", "swift-demangle.exe", "swiftDemangle.dll")
listOf("libatomic.so.1", "libatomic.so.1.2.0", "nm.exe", "swift-demangle.exe", "swiftDemangle.dll", "xargs.cmd")
} else {
listOf("nm", "swift-demangle", "libatomic.so.1", "libatomic.so.1.2.0")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ internal fun parseObjcTests(binary: String): List<String> {
val results = mutableListOf<String>()
// https://github.com/linkedin/bluepill/blob/37e7efa42472222b81adaa0e88f2bd82aa289b44/Source/Shared/BPXCTestFile.m#L18
// must quote binary path in case there are spaces
var cmd = if (!isWindows) "nm -U ${binary.quote()}" else "nm.exe -U ${binary.quote()}"
if (!isMacOS) cmd = if (isWindows) "PATH=$appDataDirectory\\.flank $cmd" else "PATH=~/.flank $cmd"
val output = Bash.execute(cmd)
var cmd = if (!isWindows) "nm -U ${binary.quote()}" else "llvm-nm.exe --undefined-only ${binary.quote()}"
if (!isMacOS) cmd = if (isWindows) cmd.replace("\\", "/") else "PATH=~/.flank $cmd"

val path = if (isWindows) listOf(Pair("Path", "$appDataDirectory\\.flank\\;C:\\Windows\\System32\\"))
else emptyList()

val output = Bash.execute(cmd, path)

output.lines().forEach { line ->
// 000089b0 t -[EarlGreyExampleTests testLayout]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package ftl.ios.xctest.common

import flank.common.appDataDirectory
import flank.common.isLinux
import flank.common.isMacOS
import flank.common.isWindows
import ftl.util.Bash
import ftl.util.ShellEnvironment

internal fun parseSwiftTests(binary: String): List<String> {
installBinaries
Expand All @@ -10,16 +14,24 @@ internal fun parseSwiftTests(binary: String): List<String> {
// The OS limits the list of arguments to ARG_MAX. Setting the xargs limit avoids a fatal
// 'argument too long' error. xargs will split the args and run the command for each chunk.
// getconf ARG_MAX
val argMax = 262_144
// Windows has different limits
val argMax = if (isWindows) 251_36 else 262_144

val cmd = if (isMacOS) {
"nm -gU ${binary.quote()} | xargs -s $argMax xcrun swift-demangle"
} else {
"export LD_LIBRARY_PATH=~/.flank; export PATH=~/.flank:\$PATH; nm -gU ${binary.quote()} | xargs -s $argMax swift-demangle"
val cmd = when {
isMacOS -> "nm -gU ${binary.quote()} | xargs -s $argMax xcrun swift-demangle"
isLinux -> "export LD_LIBRARY_PATH=~/.flank; export PATH=~/.flank:\$PATH; nm -gU ${binary.quote()} | xargs -s $argMax swift-demangle"
isWindows -> "llvm-nm.exe --undefined-only --extern-only ${binary.quote().replace("\\", "/")} | xargs swift-demangle"
else -> throw RuntimeException("Unsupported OS for Integration Tests")
}

val path = if (isWindows) {
listOf(Pair("Path", "$appDataDirectory\\.flank\\;C:\\Windows\\System32\\"), Pair("LD_LIBRARY_PATH", "$appDataDirectory\\.flank\\"))
} else emptyList()

// https://github.com/linkedin/bluepill/blob/37e7efa42472222b81adaa0e88f2bd82aa289b44/Source/Shared/BPXCTestFile.m#L17-18
val demangledOutput = Bash.execute(cmd)
val shell = if (isWindows) ShellEnvironment.Cmd else ShellEnvironment.Default

val demangledOutput = Bash.execute(cmd, path, shell)
Sloox marked this conversation as resolved.
Show resolved Hide resolved
demangledOutput.lines().forEach { line ->
// _T025EarlGreyExampleTestsSwift0abceD0C10testLayoutyyF ---> EarlGreyExampleTestsSwift.EarlGreyExampleSwiftTests.testLayout() -> ()
// _T025EarlGreyExampleTestsSwift0abceD0C16testCustomActionyyF ---> EarlGreyExampleTestsSwift.EarlGreyExampleSwiftTests.testCustomAction() -> ()
Expand Down
34 changes: 25 additions & 9 deletions test_runner/src/main/kotlin/ftl/util/Bash.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@ import ftl.run.exception.FlankGeneralError
import java.lang.ProcessBuilder.Redirect.PIPE

object Bash {

fun execute(cmd: String): String {
fun execute(
cmd: String,
additionalPath: List<Pair<String, String>> = emptyList(),
shellEnvironment: ShellEnvironment = ShellEnvironment.Default
): String {
logLn(cmd)

val bashPath = if (isWindows) "bash.exe" else "/bin/bash"

val process = ProcessBuilder(bashPath, "-c", cmd)
.redirectOutput(PIPE)
.redirectError(PIPE)
.start()
val process = ProcessBuilder(
shellEnvironment.execution,
if (isWindows) "/c"
else "-c",
cmd
).also {
if (additionalPath.isNotEmpty()) {
val envs: MutableMap<String, String> = it.environment()
additionalPath.forEach { extra ->
envs[extra.first] = extra.second
}
}
}.redirectOutput(PIPE).redirectError(PIPE).start()

val result = process.waitForResult()

Expand All @@ -27,3 +36,10 @@ object Bash {
return result.stdout.trim() + result.stderr.trim()
}
}

sealed class ShellEnvironment(val execution: String) {
object Bash : ShellEnvironment("Bash.exe")
object BinBash : ShellEnvironment("/bin/bash")
object Cmd : ShellEnvironment("cmd.exe")
object Default : ShellEnvironment(if (isWindows) Cmd.execution else BinBash.execution)
}