Skip to content

Commit

Permalink
feat: Add support for emulator devices (#1711)
Browse files Browse the repository at this point in the history
In the scope of #1710

PR adds support for `EMULATOR` devices

## Test Plan
> How do we know the code works?

1. build flank locally with `./gradlew flankFullRun`
2. ensure you are logged to `flank-open-source` project
3. run `flank firebase test android models list`
4. you should see new devices of type `EMULATOR`
5. run a simple test with
    ```
      device:
         - model: NexusLowResEmulator
           version: 28
    ```
6. tests should finish normally

## Checklist

- [x] Unit tested
  • Loading branch information
pawelpasterz authored Mar 18, 2021
1 parent a4f1de3 commit f32ae8b
Show file tree
Hide file tree
Showing 8 changed files with 10,679 additions and 5,689 deletions.
4 changes: 2 additions & 2 deletions test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ object AndroidCatalog {
logLn("Unable to find device type for $modelId. PHYSICAL used as fallback in cost calculations")
}

return form.equals(DeviceType.VIRTUAL.name, ignoreCase = true)
return form.equals(DeviceType.VIRTUAL.name, ignoreCase = true) || form.equals(DeviceType.EMULATOR.name, ignoreCase = true)
}
}

enum class DeviceType {
VIRTUAL, PHYSICAL
VIRTUAL, PHYSICAL, EMULATOR
}

sealed class DeviceConfigCheck
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ const val RESOLUTION = "RESOLUTION"
const val OS_VERSION_IDS = "OS_VERSION_IDS"
const val TAGS = "TAGS"
const val PHYSICAL_DEVICE = "PHYSICAL"
const val VIRTUAL_DEVICE = "VIRTUAL"
const val EMULATOR_DEVICE = "EMULATOR"
const val OS_VERSION_ID = "OS_VERSION_ID"
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ftl.environment.android

import com.google.testing.model.AndroidModel
import ftl.environment.EMULATOR_DEVICE
import ftl.environment.FORM
import ftl.environment.MAKE
import ftl.environment.MODEL_ID
Expand All @@ -10,6 +11,7 @@ import ftl.environment.PHYSICAL_DEVICE
import ftl.environment.RESOLUTION
import ftl.environment.TAGS
import ftl.environment.TestEnvironmentInfo
import ftl.environment.VIRTUAL_DEVICE
import ftl.environment.createTableColumnFor
import ftl.environment.getOrCreateList
import ftl.environment.orUnknown
Expand Down Expand Up @@ -47,5 +49,10 @@ private val AndroidModel.resolution
get() = if (screenX == null || screenY == null) "UNKNOWN" else "$screenY x $screenX"

private val formToSystemOutColorMapper: (String) -> SystemOutColor = {
if (it == PHYSICAL_DEVICE) SystemOutColor.YELLOW else SystemOutColor.BLUE
when (it) {
PHYSICAL_DEVICE -> SystemOutColor.YELLOW
VIRTUAL_DEVICE -> SystemOutColor.BLUE
EMULATOR_DEVICE -> SystemOutColor.GREEN
else -> SystemOutColor.DEFAULT
}
}
10 changes: 5 additions & 5 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class AndroidArgsTest {
app: $appApk
test: $testApk
device:
- model: shamu
- model: walleye
version: 18
"""
).validate()
Expand Down Expand Up @@ -836,7 +836,7 @@ AndroidArgs
@Test
fun `cli device`() {
val cli = AndroidRunCommand()
CommandLine(cli).parseArgs("--device=model=shamu,version=22,locale=zh_CN,orientation=default")
CommandLine(cli).parseArgs("--device=model=walleye,version=27,locale=zh_CN,orientation=default")

val yaml = """
gcloud:
Expand All @@ -849,7 +849,7 @@ AndroidArgs
assertThat(defaultDevices.size).isEqualTo(1)

val androidArgs = AndroidArgs.load(yaml, cli).validate()
val expectedDevice = Device("shamu", "22", "zh_CN", "default", isVirtual = false)
val expectedDevice = Device("walleye", "27", "zh_CN", "default", isVirtual = false)
val actualDevices = androidArgs.devices
assertThat(actualDevices.first()).isEqualTo(expectedDevice)
assertThat(actualDevices.size).isEqualTo(1)
Expand All @@ -858,7 +858,7 @@ AndroidArgs
@Test
fun `cli device repeat`() {
val cli = AndroidRunCommand()
val deviceCmd = "--device=model=shamu,version=22,locale=zh_CN,orientation=default"
val deviceCmd = "--device=model=walleye,version=27,locale=zh_CN,orientation=default"
CommandLine(cli).parseArgs(deviceCmd, deviceCmd)

val yaml = """
Expand All @@ -867,7 +867,7 @@ AndroidArgs
test: $testApk
"""
val androidArgs = AndroidArgs.load(yaml, cli).validate()
val expectedDevice = Device("shamu", "22", "zh_CN", "default", false)
val expectedDevice = Device("walleye", "27", "zh_CN", "default", false)
val actualDevices = androidArgs.devices
assertThat(actualDevices.size).isEqualTo(2)
assertThat(actualDevices[0]).isEqualTo(expectedDevice)
Expand Down
Loading

0 comments on commit f32ae8b

Please sign in to comment.