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: Added scenario-numbers #1244

Merged
merged 6 commits into from
Oct 20, 2020
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
7 changes: 7 additions & 0 deletions test_runner/flank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ gcloud:
# - /sdcard/dir1/file1.txt: local/file.txt
# - /sdcard/dir2/file2.jpg: gs://bucket/file.jpg

## A list of game-loop scenario numbers which will be run as part of the test (default: all scenarios).
## A maximum of 1024 scenarios may be specified in one test matrix, but the maximum number may also be limited by the overall test --timeout setting.
# scenario-numbers:
# - 1
# - 2
# - 3

## A list of game-loop scenario labels (default: None). Each game-loop scenario may be labeled in the APK manifest file with one or more arbitrary strings, creating logical groupings (e.g. GPU_COMPATIBILITY_TESTS).
## If --scenario-numbers and --scenario-labels are specified together, Firebase Test Lab will first execute each scenario from --scenario-numbers.
## It will then expand each given scenario label into a list of scenario numbers marked with that label, and execute those scenarios.
Expand Down
2 changes: 2 additions & 0 deletions test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ data class AndroidArgs(
val directoriesToPull: List<String>,
val grantPermissions: String?,
val type: Type?,
val scenarioNumbers: List<String>,
val otherFiles: Map<String, String>,
val scenarioLabels: List<String>,
val performanceMetrics: Boolean,
Expand Down Expand Up @@ -50,6 +51,7 @@ AndroidArgs
grant-permissions: $grantPermissions
type: ${type?.ymlName}
other-files: ${ArgsToString.mapToString(otherFiles)}
scenario-numbers: ${ArgsToString.listToString(scenarioNumbers)}
scenario-labels: ${ArgsToString.listToString(scenarioLabels)}
performance-metrics: $performanceMetrics
num-uniform-shards: $numUniformShards
Expand Down
1 change: 1 addition & 0 deletions test_runner/src/main/kotlin/ftl/args/CreateAndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fun createAndroidArgs(
useLegacyJUnitResult = flank.useLegacyJUnitResult!!,
scenarioLabels = gcloud.scenarioLabels!!,
obfuscateDumpShards = obfuscate,
scenarioNumbers = gcloud.scenarioNumbers!!,
grantPermissions = gcloud.grantPermissions,
type = gcloud.type?.let { Type.fromString(it) }
)
7 changes: 7 additions & 0 deletions test_runner/src/main/kotlin/ftl/args/ValidateAndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ fun AndroidArgs.validate() = apply {
}

private fun AndroidArgs.assertGameLoop() {
assertLabelContent()
}

private fun AndroidArgs.assertLabelContent() {
if (scenarioLabels.isNotEmpty() && (type == null || type != Type.GAMELOOP))
throw FlankConfigurationError("Scenario labels defined but Type is not Game-loop.")
if (scenarioNumbers.isNotEmpty() && (type == null || type != Type.GAMELOOP))
throw FlankConfigurationError("Scenario numbers defined but Type is not Game-loop.")
scenarioNumbers.forEach { it.toIntOrNull() ?: throw FlankConfigurationError("Invalid scenario number provided - $it") }
}

private fun AndroidArgs.assertType() = type?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ data class AndroidGcloudConfig @JsonIgnore constructor(
@set:JsonProperty("other-files")
var otherFiles: Map<String, String>? by data

@set:CommandLine.Option(
names = ["--scenario-numbers"],
split = ",",
description = ["A list of game-loop scenario numbers which will be run as part of the test (default: all scenarios). " +
"A maximum of 1024 scenarios may be specified in one test matrix, " +
"but the maximum number may also be limited by the overall test --timeout setting."]
)
@set:JsonProperty("scenario-numbers")
var scenarioNumbers: List<String>? by data

@set:CommandLine.Option(
names = ["--scenario-labels"],
split = ",",
Expand Down Expand Up @@ -239,6 +249,7 @@ data class AndroidGcloudConfig @JsonIgnore constructor(
grantPermissions = FlankDefaults.GRANT_PERMISSIONS_ALL
directoriesToPull = emptyList()
otherFiles = emptyMap()
scenarioNumbers = emptyList()
scenarioLabels = emptyList()
performanceMetrics = FlankDefaults.DISABLE_PERFORMANCE_METRICS
numUniformShards = null
Expand Down
103 changes: 102 additions & 1 deletion test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ AndroidArgs
other-files:
/sdcard/dir1/file1.txt: $appApkAbsolutePath
/sdcard/dir2/file2.jpg: $testApkAbsolutePath
scenario-numbers:
scenario-labels:
performance-metrics: false
num-uniform-shards: null
Expand Down Expand Up @@ -398,6 +399,7 @@ AndroidArgs
grant-permissions: all
type: null
other-files:
scenario-numbers:
scenario-labels:
performance-metrics: false
num-uniform-shards: null
Expand Down Expand Up @@ -2021,7 +2023,8 @@ AndroidArgs
AndroidArgs.load(yaml).validate()
}

fun `should not throw exception if game-loop required but no scenario loop provided`() {
@Test
fun `should not throw exception if game-loop and scenario labels provided`() {
val yaml = """
gcloud:
app: $appApk
Expand All @@ -2038,6 +2041,104 @@ AndroidArgs
""".trimIndent()
AndroidArgs.load(yaml).validate()
}

@Test
fun `should not throw exception if game-loop and scenario numbers provided`() {
val yaml = """
gcloud:
app: $appApk
test: $testApk
device:
- model: Nexus6
version: 25
locale: en
orientation: portrait
type: game-loop
scenario-numbers:
- 1
- 2
""".trimIndent()
AndroidArgs.load(yaml).validate()
}

@Test(expected = FlankConfigurationError::class)
fun `should throw exception if game-loop not provided and scenario numbers provided`() {
val yaml = """
gcloud:
app: $appApk
test: $testApk
device:
- model: Nexus6
version: 25
locale: en
orientation: portrait
type: robo
scenario-numbers:
- 1
- 2
""".trimIndent()
AndroidArgs.load(yaml).validate()
}

@Test(expected = FlankConfigurationError::class)
fun `should throw exception if invalid scenario numbers provided`() {
val yaml = """
gcloud:
app: $appApk
test: $testApk
device:
- model: Nexus6
version: 25
locale: en
orientation: portrait
type: game-loop
scenario-numbers:
- error
- 2
""".trimIndent()
AndroidArgs.load(yaml).validate()
}

@Test
fun `should Not throw exception if valid scenario numbers provided`() {
val yaml = """
gcloud:
app: $appApk
test: $testApk
device:
- model: Nexus6
version: 25
locale: en
orientation: portrait
type: game-loop
scenario-numbers:
- 1
- 2
""".trimIndent()
AndroidArgs.load(yaml).validate()
}

@Test
fun `should Not throw exception if valid scenario numbers provided and scenario labels`() {
val yaml = """
gcloud:
app: $appApk
test: $testApk
device:
- model: Nexus6
version: 25
locale: en
orientation: portrait
type: game-loop
scenario-labels:
- label1
- label2
scenario-numbers:
- 1
- 2
""".trimIndent()
AndroidArgs.load(yaml).validate()
}
}

private fun AndroidArgs.Companion.load(yamlData: String, cli: AndroidRunCommand? = null): AndroidArgs =
Expand Down