-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
200 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
kotlin(Plugins.Kotlin.PLUGIN_JVM) | ||
kotlin(Plugins.Kotlin.PLUGIN_SERIALIZATION) version Versions.KOTLIN | ||
} | ||
|
||
repositories { | ||
jcenter() | ||
mavenCentral() | ||
maven(url = "https://kotlin.bintray.com/kotlinx") | ||
} | ||
|
||
tasks.withType<KotlinCompile> { kotlinOptions.jvmTarget = "1.8" } | ||
|
||
dependencies { | ||
implementation(project(":corellium:api")) | ||
implementation(project(":corellium:adapter")) | ||
implementation(project(":corellium:shard")) | ||
implementation(project(":corellium:log")) | ||
|
||
implementation(Dependencies.KOTLIN_COROUTINES_CORE) | ||
|
||
testImplementation(Dependencies.JUNIT) | ||
} | ||
|
||
tasks.test { | ||
maxHeapSize = "3072m" | ||
minHeapSize = "512m" | ||
dependsOn(":resolveArtifacts") | ||
} |
123 changes: 123 additions & 0 deletions
123
corellium/domain/src/main/kotlin/flank/corellium/domain/RunTestAndroidCorellium.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package flank.corellium.domain | ||
|
||
import flank.corellium.api.AndroidApps | ||
import flank.corellium.api.AndroidInstance | ||
import flank.corellium.api.AndroidTestPlan | ||
import flank.corellium.api.Authorization | ||
import flank.corellium.api.CorelliumApi | ||
import flank.corellium.api.TestApk | ||
import flank.corellium.api.invoke | ||
import flank.corellium.shard.Shard | ||
import flank.corellium.shard.calculateShards | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.runBlocking | ||
|
||
interface RunTestAndroidCorellium { | ||
val api: CorelliumApi | ||
val config: Config | ||
|
||
data class Config( | ||
val credentials: Authorization.Credentials, | ||
val apks: List<Apk.App>, | ||
val maxShardsCount: Int, | ||
) | ||
|
||
sealed class Apk { | ||
abstract val path: String | ||
|
||
data class App( | ||
override val path: String, | ||
val tests: List<Test>, | ||
) : Apk() | ||
|
||
data class Test( | ||
override val path: String | ||
) : Apk() | ||
} | ||
} | ||
|
||
fun RunTestAndroidCorellium.invoke(): Unit = runBlocking { | ||
|
||
println("* Authorizing") | ||
api.authorize(config.credentials) | ||
|
||
println("* Calculating shards") | ||
val shards: List<List<Shard.App>> = config.apks | ||
.prepareDataForSharding(api.parseTestCases) | ||
.calculateShards(config.maxShardsCount) | ||
|
||
println("* Invoking devices") | ||
val associatedShards: AssociatedShards = api | ||
.invokeAndroidDevices(AndroidInstance.Config(shards.size)) | ||
.associateShardsToInstances(shards) | ||
|
||
println("* Installing apks") | ||
val apps: List<AndroidApps> = associatedShards.prepareApkToInstall() | ||
api.installAndroidApps(apps) | ||
|
||
// If tests will be executed too fast just after the | ||
// app installed, the instrumentation will fail | ||
delay(10_000) | ||
|
||
println("* Executing tests") | ||
val testPlan = associatedShards.prepareTestPlan(api.parsePackageName) | ||
|
||
api.executeTest(testPlan).collect { line -> | ||
print(line) | ||
} | ||
println() | ||
println("* Finish") | ||
} | ||
|
||
private fun List<RunTestAndroidCorellium.Apk.App>.prepareDataForSharding( | ||
parseTestCases: TestApk.ParseTestCases | ||
): List<Shard.App> = | ||
map { app -> | ||
Shard.App( | ||
name = app.path, | ||
tests = app.tests.map { test -> | ||
Shard.Test( | ||
name = test.path, | ||
cases = parseTestCases(test.path).map(Shard.Test::Case) | ||
) | ||
} | ||
) | ||
} | ||
|
||
private fun List<String>.associateShardsToInstances( | ||
shards: List<List<Shard.App>>, | ||
): AssociatedShards { | ||
require(shards.size <= size) { "Not enough instances, required ${shards.size} but was $size" } | ||
return mapIndexed { index, id -> id to shards[index] }.toMap() | ||
} | ||
|
||
private fun AssociatedShards.prepareApkToInstall(): List<AndroidApps> = | ||
map { (instanceId, list: List<Shard.App>) -> | ||
AndroidApps( | ||
instanceId = instanceId, | ||
paths = list.flatMap { app -> app.tests.map { test -> test.name } + app.name } | ||
) | ||
} | ||
|
||
private fun AssociatedShards.prepareTestPlan( | ||
parsePackageName: TestApk.ParsePackageName | ||
) = | ||
AndroidTestPlan.Config( | ||
instances = mapValues { (_, shards) -> | ||
shards.map { shard -> | ||
shard.tests.map { test -> | ||
|
||
AndroidTestPlan.Shard( | ||
packageName = shard.name, | ||
testRunner = "", | ||
testCases = shard.tests.map { test -> | ||
test.name | ||
} | ||
) | ||
} | ||
} | ||
} | ||
) | ||
|
||
private typealias AssociatedShards = Map<String, List<Shard.App>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## Credentials | ||
api=rh.corellium.io | ||
username=matthew.edwards@robinhood.com | ||
password=hakequkihojoxux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters