Skip to content

Commit

Permalink
Merge branch 'master' into 1198-ios-directories-to-pull
Browse files Browse the repository at this point in the history
  • Loading branch information
adamfilipow92 committed Oct 26, 2020
2 parents a710203 + 4113afc commit 93c555e
Show file tree
Hide file tree
Showing 18 changed files with 127 additions and 28 deletions.
9 changes: 9 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ gcloud:
# directories-to-pull:
# - /private/var/mobile/Media


## A list of device-path=file-path pairs that specify the paths of the test device and the files you want pushed to the device prior to testing.
## Device paths should either be under the Media shared folder (e.g. prefixed with /private/var/mobile/Media) or
## within the documents directory of the filesystem of an app under test (e.g. /Documents). Device paths to app
## filesystems should be prefixed by the bundle ID and a colon. Source file paths may be in the local filesystem or in Google Cloud Storage (gs://…).
# other-files
# com.my.app:/Documents/file.txt: local/file.txt
# /private/var/mobile/Media/file.jpg: gs://bucket/file.jpg

flank:
# -- FlankYml --

Expand Down
8 changes: 8 additions & 0 deletions test_runner/flank.ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ gcloud:
## of the app under test. If the path is under an app's /Documents, it must be prefixed with the app's bundle id and a colon
# directories-to-pull:
# - /private/var/mobile/Media

## A list of device-path=file-path pairs that specify the paths of the test device and the files you want pushed to the device prior to testing.
## Device paths should either be under the Media shared folder (e.g. prefixed with /private/var/mobile/Media) or
## within the documents directory of the filesystem of an app under test (e.g. /Documents). Device paths to app
## filesystems should be prefixed by the bundle ID and a colon. Source file paths may be in the local filesystem or in Google Cloud Storage (gs://…).
# other-files
# com.my.app:/Documents/file.txt: local/file.txt
# /private/var/mobile/Media/file.jpg: gs://bucket/file.jpg

flank:
# -- FlankYml --
Expand Down
1 change: 0 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ data class AndroidArgs(
val grantPermissions: String?,
val type: Type?,
val scenarioNumbers: List<String>,
val otherFiles: Map<String, String>,
val scenarioLabels: List<String>,
val obbfiles: List<String>,
val performanceMetrics: Boolean,
Expand Down
1 change: 1 addition & 0 deletions test_runner/src/main/kotlin/ftl/args/CommonArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ data class CommonArgs(
override val clientDetails: Map<String, String>?,
override val networkProfile: String?,
override val directoriesToPull: List<String>,
override val otherFiles: Map<String, String>,

// flank
override val project: String,
Expand Down
1 change: 0 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/CreateAndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ fun createAndroidArgs(
testRunnerClass = gcloud.testRunnerClass,
roboDirectives = gcloud.roboDirectives!!.parseRoboDirectives(),
performanceMetrics = gcloud.performanceMetrics!!,
otherFiles = gcloud.otherFiles!!.mapValues { (_, path) -> path.normalizeFilePath() },
numUniformShards = gcloud.numUniformShards,
environmentVariables = gcloud.environmentVariables!!,
autoGoogleLogin = gcloud.autoGoogleLogin!!,
Expand Down
2 changes: 2 additions & 0 deletions test_runner/src/main/kotlin/ftl/args/CreateCommonArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ fun CommonConfig.createCommonArgs(
networkProfile = gcloud.networkProfile,
clientDetails = gcloud.clientDetails,
directoriesToPull = gcloud.directoriesToPull!!,
otherFiles = gcloud.otherFiles!!.mapValues { (_, path) -> path.normalizeFilePath() },

// flank
maxTestShards = flank.maxTestShards!!,
shardTime = flank.shardTime!!,
Expand Down
1 change: 1 addition & 0 deletions test_runner/src/main/kotlin/ftl/args/IArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface IArgs {
val resultsHistoryName: String?
val flakyTestAttempts: Int
val directoriesToPull: List<String>
val otherFiles: Map<String, String>

// FlankYml
val maxTestShards: Int
Expand Down
1 change: 1 addition & 0 deletions test_runner/src/main/kotlin/ftl/args/IosArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ IosArgs
device:${ArgsToString.objectsToString(devices)}
num-flaky-test-attempts: $flakyTestAttempts
directories-to-pull: ${ArgsToString.listToString(directoriesToPull)}
other-files: ${ArgsToString.mapToString(otherFiles)}
flank:
max-test-shards: $maxTestShards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,6 @@ data class AndroidGcloudConfig @JsonIgnore constructor(
@set:JsonProperty("type")
var type: String? by data

@set:CommandLine.Option(
names = ["--other-files"],
split = ",",
description = ["A list of device-path=file-path pairs that indicate the device paths to push files to the device before starting tests, and the paths of files to push." +
"Device paths must be under absolute, whitelisted paths (\${EXTERNAL_STORAGE}, or \${ANDROID_DATA}/local/tmp)." +
"Source file paths may be in the local filesystem or in Google Cloud Storage (gs://…). "]
)
@set:JsonProperty("other-files")
var otherFiles: Map<String, String>? by data

@set:CommandLine.Option(
names = ["--scenario-numbers"],
split = ",",
Expand Down Expand Up @@ -244,7 +234,6 @@ data class AndroidGcloudConfig @JsonIgnore constructor(
useOrchestrator = true
environmentVariables = emptyMap()
grantPermissions = FlankDefaults.GRANT_PERMISSIONS_ALL
otherFiles = emptyMap()
scenarioNumbers = emptyList()
scenarioLabels = emptyList()
obbfiles = emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ data class CommonGcloudConfig @JsonIgnore constructor(
@set:JsonProperty("directories-to-pull")
var directoriesToPull: List<String>? by data

@set:CommandLine.Option(
names = ["--other-files"],
split = ",",
description = [
"A list of device-path=file-path pairs that indicate the device paths to push files to the device before " +
"starting tests, and the paths of files to push."]
)
@set:JsonProperty("other-files")
var otherFiles: Map<String, String>? by data

constructor() : this(mutableMapOf<String, Any?>().withDefault { null })

companion object : IYmlKeys {
Expand All @@ -159,6 +169,7 @@ data class CommonGcloudConfig @JsonIgnore constructor(
networkProfile = null
devices = listOf(defaultDevice(android))
directoriesToPull = emptyList()
otherFiles = emptyMap()
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion test_runner/src/main/kotlin/ftl/gc/GcIosTestMatrix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.google.api.services.testing.model.TestMatrix
import com.google.api.services.testing.model.TestSpecification
import com.google.api.services.testing.model.ToolResultsHistory
import ftl.args.IosArgs
import ftl.gc.android.mapToIosDeviceFiles
import ftl.ios.Xctestrun
import ftl.ios.Xctestrun.toByteArray
import ftl.run.exception.FlankGeneralError
Expand All @@ -32,7 +33,8 @@ object GcIosTestMatrix {
args: IosArgs,
testTargets: List<String>,
shardCounter: ShardCounter,
toolResultsHistory: ToolResultsHistory
toolResultsHistory: ToolResultsHistory,
otherFiles: Map<String, String>
): Testing.Projects.TestMatrices.Create {
val clientInfo = ClientInfo()
.setName("Flank")
Expand Down Expand Up @@ -64,6 +66,7 @@ object GcIosTestMatrix {
val iOSTestSetup = IosTestSetup()
.setNetworkProfile(args.networkProfile)
.setPullDirectories(args.directoriesToPull.toIosDeviceFiles())
.setPushFiles(otherFiles.mapToIosDeviceFiles())

val testTimeoutSeconds = timeoutToSeconds(args.testTimeout)

Expand Down
15 changes: 15 additions & 0 deletions test_runner/src/main/kotlin/ftl/gc/android/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ftl.gc.android
import com.google.api.services.testing.model.Apk
import com.google.api.services.testing.model.DeviceFile
import com.google.api.services.testing.model.FileReference
import com.google.api.services.testing.model.IosDeviceFile
import com.google.api.services.testing.model.RegularFile

internal fun List<String>.mapGcsPathsToApks(): List<Apk>? = this
Expand All @@ -17,3 +18,17 @@ internal fun Map<String, String>.mapToDeviceFiles(): List<DeviceFile> =
.setContent(FileReference().setGcsPath(gcsFilePath))
)
}

internal fun Map<String, String>.mapToIosDeviceFiles(): List<IosDeviceFile> =
map { (testDevicePath, gcsFilePath) ->
IosDeviceFile().apply {
if (testDevicePath.contains(":")) {
val (bundleIdSeparated, pathSeparated) = testDevicePath.split(":")
bundleId = bundleIdSeparated
devicePath = pathSeparated
} else {
devicePath = testDevicePath
}
content = FileReference().setGcsPath(gcsFilePath)
}
}
6 changes: 4 additions & 2 deletions test_runner/src/main/kotlin/ftl/run/platform/RunIosTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ftl.ios.Xctestrun
import ftl.run.IOS_SHARD_FILE
import ftl.run.dumpShards
import ftl.run.model.TestResult
import ftl.run.platform.android.uploadOtherFiles
import ftl.run.platform.common.afterRunTests
import ftl.run.platform.common.beforeRunMessage
import ftl.run.platform.common.beforeRunTests
Expand All @@ -30,13 +31,13 @@ internal suspend fun runIosTests(iosArgs: IosArgs): TestResult = coroutineScope
val (stopwatch, runGcsPath) = beforeRunTests(iosArgs)

val iosDeviceList = GcIosMatrix.build(iosArgs.devices)

val xcTestParsed = Xctestrun.parse(iosArgs.xctestrunFile)

val jobs = arrayListOf<Deferred<TestMatrix>>()
val runCount = iosArgs.repeatTests
val shardCounter = ShardCounter()
val history = GcToolResults.createToolResultsHistory(iosArgs)
val otherGcsFiles = iosArgs.uploadOtherFiles(runGcsPath)

dumpShards(iosArgs)
if (iosArgs.disableResultsUpload.not())
Expand All @@ -58,7 +59,8 @@ internal suspend fun runIosTests(iosArgs: IosArgs): TestResult = coroutineScope
xcTestParsed = xcTestParsed,
args = iosArgs,
shardCounter = shardCounter,
toolResultsHistory = history
toolResultsHistory = history,
otherFiles = otherGcsFiles
).executeWithRetry()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package ftl.run.platform.android

import ftl.args.AndroidArgs
import ftl.args.IArgs
import ftl.gc.GcStorage
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope

internal suspend fun AndroidArgs.uploadOtherFiles(
internal suspend fun IArgs.uploadOtherFiles(
runGcsPath: String
): Map<String, String> = coroutineScope {
otherFiles.map { (devicePath: String, filePath: String) ->
async(Dispatchers.IO) { devicePath to GcStorage.upload(filePath, resultsBucket, runGcsPath) }
}.awaitAll().toMap()
otherFiles
.map { (devicePath: String, filePath: String) ->
async(Dispatchers.IO) { devicePath to GcStorage.upload(filePath, resultsBucket, runGcsPath) }
}.awaitAll().toMap()
}
7 changes: 7 additions & 0 deletions test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class IosArgsTest {
network-profile: LTE
project: projectFoo
results-history-name: ios-history
other-files:
com.my.app:/Documents/file.txt: local/file.txt
/private/var/mobile/Media/file.jpg: gs://bucket/file.jpg
test: $testPath
xctestrun-file: $xctestrunFile
Expand Down Expand Up @@ -228,6 +231,9 @@ IosArgs
orientation: default
num-flaky-test-attempts: 4
directories-to-pull:
other-files:
com.my.app:/Documents/file.txt: local/file.txt
/private/var/mobile/Media/file.jpg: gs://bucket/file.jpg
flank:
max-test-shards: 7
Expand Down Expand Up @@ -286,6 +292,7 @@ IosArgs
orientation: portrait
num-flaky-test-attempts: 0
directories-to-pull:
other-files:
flank:
max-test-shards: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class AndroidRunCommandTest {
assertThat(cmd.config.platform.gcloud.numUniformShards).isNull()
assertThat(cmd.config.platform.gcloud.testRunnerClass).isNull()
assertThat(cmd.config.platform.gcloud.environmentVariables).isNull()
assertThat(cmd.config.platform.gcloud.otherFiles).isNull()
assertThat(cmd.config.common.gcloud.otherFiles).isNull()
assertThat(cmd.config.common.gcloud.devices).isNull()
assertThat(cmd.config.common.gcloud.resultsBucket).isNull()
assertThat(cmd.config.common.gcloud.recordVideo).isNull()
Expand Down Expand Up @@ -227,7 +227,7 @@ class AndroidRunCommandTest {
val cmd = AndroidRunCommand()
CommandLine(cmd).parseArgs("--other-files=a=1,b=2")

assertThat(cmd.config.platform.gcloud.otherFiles).hasSize(2)
assertThat(cmd.config.common.gcloud.otherFiles).hasSize(2)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class IosRunCommandTest {
assertThat(cmd.config.common.flank.smartFlankDisableUpload).isNull()
assertThat(cmd.config.common.flank.smartFlankGcsPath).isNull()
assertThat(cmd.config.common.flank.runTimeout).isNull()
assertThat(cmd.config.common.gcloud.otherFiles).isNull()
}

@Test
Expand Down Expand Up @@ -371,4 +372,12 @@ class IosRunCommandTest {
verify(inverse = true) { GcStorage.upload(IOS_SHARD_FILE, any(), any()) }
}
}

@Test
fun `otherFiles parse`() {
val cmd = IosRunCommand()
CommandLine(cmd).parseArgs("--other-files=a=1,b=2")

assertThat(cmd.config.common.gcloud.otherFiles).hasSize(2)
}
}
52 changes: 47 additions & 5 deletions test_runner/src/test/kotlin/ftl/gc/GcIosTestMatrixTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.unmockkAll
import org.junit.After
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import java.io.StringReader

@RunWith(FlankTestRunner::class)
class GcIosTestMatrixTest {
Expand All @@ -36,7 +34,8 @@ class GcIosTestMatrixTest {
args = iosArgs,
testTargets = emptyList(),
shardCounter = ShardCounter(),
toolResultsHistory = GcToolResults.createToolResultsHistory(iosArgs)
toolResultsHistory = GcToolResults.createToolResultsHistory(iosArgs),
otherFiles = mapOf()
)
}

Expand All @@ -51,7 +50,8 @@ class GcIosTestMatrixTest {
args = iosArgs,
testTargets = listOf(""),
shardCounter = ShardCounter(),
toolResultsHistory = GcToolResults.createToolResultsHistory(iosArgs)
toolResultsHistory = GcToolResults.createToolResultsHistory(iosArgs),
otherFiles = mapOf()
)
}

Expand All @@ -72,10 +72,52 @@ class GcIosTestMatrixTest {
args = iosArgs,
testTargets = emptyList(),
shardCounter = ShardCounter(),
toolResultsHistory = GcToolResults.createToolResultsHistory(iosArgs)
toolResultsHistory = GcToolResults.createToolResultsHistory(iosArgs),
otherFiles = mapOf()
)
}


@Test
fun `should fill otherFiles`() {
val iosArgs = IosArgs.load(
StringReader(
"""
gcloud:
test: ./test_runner/src/test/kotlin/ftl/fixtures/tmp/earlgrey_example.zip
xctestrun-file: ./test_runner/src/test/kotlin/ftl/fixtures/tmp/EarlGreyExampleSwiftTests_iphoneos13.4-arm64e.xctestrun
results-dir: test_dir
other-files:
com.my.app:/Documents/file.txt: local/file.txt
/private/var/mobile/Media/file.jpg: gs://bucket/file.jpg
""".trimIndent()
)
)

val expected = mapOf(
"com.my.app:/Documents/file.txt" to "local/file.txt",
"/private/var/mobile/Media/file.jpg" to "gs://bucket/file.jpg"
)
assertEquals(expected, iosArgs.otherFiles)
}

@Test
fun `should not fill otherFiles`() {
val iosArgs = IosArgs.load(
StringReader(
"""
gcloud:
test: ./test_runner/src/test/kotlin/ftl/fixtures/tmp/earlgrey_example.zip
xctestrun-file: ./test_runner/src/test/kotlin/ftl/fixtures/tmp/EarlGreyExampleSwiftTests_iphoneos13.4-arm64e.xctestrun
results-dir: test_dir
""".trimIndent()
)
)

val expected = emptyMap<String, String>()
assertEquals(expected, iosArgs.otherFiles)
}

@Test
fun `should fill directoriesToPull`() {
val iosArgs = IosArgs.load(StringReader("""
Expand Down

0 comments on commit 93c555e

Please sign in to comment.