-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add cleanup device script #61
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ import com.malinskiy.marathon.android.AndroidComponentCacheKeyProvider | |
import com.malinskiy.marathon.android.AndroidComponentInfoExtractor | ||
import com.malinskiy.marathon.android.AndroidLogConfigurator | ||
import com.malinskiy.marathon.android.AndroidTestParser | ||
import com.malinskiy.marathon.android.ApkFileHasher | ||
import com.malinskiy.marathon.android.executor.logcat.LogcatCollector | ||
import com.malinskiy.marathon.android.executor.logcat.LogcatListener | ||
import com.malinskiy.marathon.android.executor.logcat.parse.LogcatEventsAdapter | ||
|
@@ -13,14 +12,15 @@ import com.malinskiy.marathon.cache.test.key.ComponentCacheKeyProvider | |
import com.malinskiy.marathon.execution.ComponentInfoExtractor | ||
import com.malinskiy.marathon.execution.TestParser | ||
import com.malinskiy.marathon.io.CachedFileHasher | ||
import com.malinskiy.marathon.io.Md5FileHasher | ||
import com.malinskiy.marathon.log.MarathonLogConfigurator | ||
import com.malinskiy.marathon.report.logs.LogsProvider | ||
import org.koin.dsl.module | ||
|
||
val androidModule = module { | ||
single<TestParser?> { AndroidTestParser() } | ||
single<ComponentInfoExtractor?> { AndroidComponentInfoExtractor() } | ||
single<ComponentCacheKeyProvider?> { AndroidComponentCacheKeyProvider(CachedFileHasher(ApkFileHasher())) } | ||
single<ComponentCacheKeyProvider?> { AndroidComponentCacheKeyProvider(CachedFileHasher(Md5FileHasher())) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use MD5 in |
||
single<LogcatCollector?> { LogcatCollector() } | ||
single<LogcatEventsListener?> { get<LogcatCollector>() } | ||
single<LogsProvider?> { get<LogcatCollector>() } | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,10 +53,11 @@ class AndroidAppInstaller( | |
if (isApkInstalled) { | ||
logger.info("Skipping installation of $appPackage on ${device.serialNumber} - APK is already installed") | ||
} else { | ||
cleanupSpaceBeforeInstallation(device) | ||
logger.info("Installing $appPackage, ${appApk.absolutePath} to ${device.serialNumber}") | ||
val installationStarted = Instant.now() | ||
val installMessage = device.safeInstallPackage(appApk.absolutePath, true, optionalParams(device)) | ||
installMessage?.let { logger.debug { it } } | ||
installMessage?.let { logger.info { it } } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to see as much as we can in the logs related to installation |
||
track.installation(device.serialNumber, installationStarted, Instant.now()) | ||
installedApps | ||
.getOrPut(device.serialNumber) { hashMapOf() } | ||
|
@@ -69,6 +70,22 @@ class AndroidAppInstaller( | |
} | ||
} | ||
|
||
private fun cleanupSpaceBeforeInstallation(device: AndroidDevice) { | ||
val storageUsedPercentage = device | ||
.safeExecuteShellCommand("df /storage/emulated -h | grep '/storage/emulated' | awk '{print \$5}'") | ||
.substringBefore("%") | ||
.toInt() | ||
logger.info { "Used $storageUsedPercentage% of storage on ${device.serialNumber}" } | ||
val usedStorageThresholdInPercents = androidConfiguration.usedStorageThresholdInPercents | ||
if (storageUsedPercentage > usedStorageThresholdInPercents) { | ||
logger.warn { "On ${device.serialNumber} used more than $usedStorageThresholdInPercents% of storage" } | ||
androidConfiguration.cleanupDeviceScript.let { | ||
logger.info { "Launching cleanup shell script `$it`" } | ||
device.safeExecuteShellCommand(it).let { logger.info { it } } | ||
} | ||
} | ||
} | ||
|
||
private suspend fun isApkInstalled(device: AndroidDevice, appPackage: String, fileHash: String): Boolean { | ||
if (installedApps[device.serialNumber]?.get(appPackage) == fileHash) { | ||
return true | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import com.android.ddmlib.ShellCommandUnresponsiveException | |
import com.android.ddmlib.TimeoutException | ||
import com.android.ddmlib.testrunner.ITestRunListener | ||
import com.android.ddmlib.testrunner.RemoteAndroidTestRunner | ||
import com.android.ddmlib.testrunner.RemoteAndroidTestRunner.StatusReporterMode | ||
import com.android.ddmlib.testrunner.TestIdentifier | ||
import com.malinskiy.marathon.android.AndroidComponentInfo | ||
import com.malinskiy.marathon.android.AndroidConfiguration | ||
|
@@ -104,7 +105,12 @@ class AndroidDeviceTestRunner(private val device: DdmlibAndroidDevice) { | |
testBatch: TestBatch | ||
): RemoteAndroidTestRunner { | ||
|
||
val runner = RemoteAndroidTestRunner(info.instrumentationPackage, info.testRunnerClass, device.ddmsDevice) | ||
val runner = RemoteAndroidTestRunner( | ||
info.instrumentationPackage, | ||
info.testRunnerClass, | ||
device.ddmsDevice, | ||
StatusReporterMode.PROTO_STD | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. StatusReporterMode.TEXT is deprecated from API 26 and used by default in 3 arguments constructor. StatusReporterMode.PROTO_STD should be better as it will use less data because of binary format rather than text. |
||
) | ||
|
||
val tests = testBatch.tests.map { | ||
val pkg = when { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use ddmlib similar to our AGP version