forked from MarathonLabs/marathon
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Extract code coverage from Android device #21
Open
karthyks
wants to merge
23
commits into
feature/agoda-android-ci
Choose a base branch
from
android-code-coverage
base: feature/agoda-android-ci
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a2d7d2e
enable code coverage for android
karthyks 11d4c84
sned uncompleted test results to trigger retry quota
karthyks 8890ca9
coverage listener now collects all coverages
karthyks 796071d
make testCoverageResultListener a attachmentProvider
karthyks 8b7b699
simplify list with not nulls
karthyks 88b6e60
add logs and filesDir for coverageFiles
karthyks 1cdd405
add packageName variable
karthyks e7e5e2d
get package name from apk parser
karthyks 9554122
filesDir to use data dir
karthyks 2a5966f
change trace to debug and remove files dir suffix
karthyks 0f62f8e
count coverage files generated
karthyks 1987879
update coverage tracker to create just coverage file
karthyks 207bfcb
add logs to debug
karthyks c9dd85b
add files dir
karthyks 37b48db
enable coverage in testRunner
karthyks 42c97f7
update ddmlib version
karthyks f8ca372
Revert "update ddmlib version"
karthyks c8f7d65
pull coverage file using dadb
karthyks aafb19f
Revert "pull coverage file using dadb"
karthyks 8a98852
add debug for listing folders and files in devices
karthyks 01caf4a
remove setting coverageReportLocation
karthyks 38cc7d2
more logs
karthyks 3731e65
add instrumentation args
karthyks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 19 additions & 0 deletions
19
core/src/main/kotlin/com/malinskiy/marathon/analytics/tracker/local/TestCoverageTracker.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,19 @@ | ||
package com.malinskiy.marathon.analytics.tracker.local | ||
|
||
import com.malinskiy.marathon.analytics.tracker.NoOpTracker | ||
import com.malinskiy.marathon.device.DeviceInfo | ||
import com.malinskiy.marathon.device.DevicePoolId | ||
import com.malinskiy.marathon.execution.TestResult | ||
import com.malinskiy.marathon.report.internal.TestCoverageReporter | ||
|
||
internal class TestCoverageTracker(private val testCoverageReporter: TestCoverageReporter) : | ||
NoOpTracker() { | ||
|
||
override fun trackTestFinished( | ||
poolId: DevicePoolId, | ||
device: DeviceInfo, | ||
testResult: TestResult | ||
) { | ||
testCoverageReporter.testFinished(poolId, device, testResult) | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
core/src/main/kotlin/com/malinskiy/marathon/report/internal/TestCoverageReporter.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,19 @@ | ||
package com.malinskiy.marathon.report.internal | ||
|
||
import com.malinskiy.marathon.device.DeviceInfo | ||
import com.malinskiy.marathon.device.DevicePoolId | ||
import com.malinskiy.marathon.execution.TestResult | ||
import com.malinskiy.marathon.io.FileManager | ||
import com.malinskiy.marathon.io.FileType | ||
|
||
class TestCoverageReporter(private val fileManager: FileManager) { | ||
|
||
fun testFinished(poolId: DevicePoolId, device: DeviceInfo, testResult: TestResult) { | ||
val file = fileManager.createFile(FileType.COVERAGE, poolId, device, testResult.test) | ||
file.setWritable(true) | ||
testResult.attachments.forEach { | ||
val bytes = it.file.readBytes() | ||
file.appendBytes(bytes) | ||
} | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
...in/kotlin/com/malinskiy/marathon/android/executor/listeners/TestCoverageResultListener.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,68 @@ | ||
package com.malinskiy.marathon.android.executor.listeners | ||
|
||
import com.android.ddmlib.testrunner.TestIdentifier | ||
import com.malinskiy.marathon.android.AndroidDevice | ||
import com.malinskiy.marathon.android.toTest | ||
import com.malinskiy.marathon.device.DevicePoolId | ||
import com.malinskiy.marathon.device.toDeviceInfo | ||
import com.malinskiy.marathon.execution.Attachment | ||
import com.malinskiy.marathon.execution.AttachmentType | ||
import com.malinskiy.marathon.io.FileManager | ||
import com.malinskiy.marathon.io.FileType | ||
import com.malinskiy.marathon.log.MarathonLogging | ||
import com.malinskiy.marathon.report.attachment.AttachmentListener | ||
import com.malinskiy.marathon.report.attachment.AttachmentProvider | ||
import kotlin.system.measureTimeMillis | ||
|
||
class TestCoverageResultListener( | ||
private val fileManager: FileManager, | ||
private val pool: DevicePoolId, | ||
private val device: AndroidDevice | ||
) : NoOpTestRunListener(), AttachmentProvider { | ||
|
||
private val logger = MarathonLogging.logger("CoverageListener") | ||
|
||
private val attachmentListeners = mutableListOf<AttachmentListener>() | ||
|
||
private lateinit var lastTestIdentifier: TestIdentifier | ||
|
||
override fun testEnded(test: TestIdentifier, testMetrics: Map<String, String>) { | ||
super.testEnded(test, testMetrics) | ||
lastTestIdentifier = test | ||
} | ||
|
||
override fun testRunEnded(elapsedTime: Long, runMetrics: Map<String, String>) { | ||
super.testRunEnded(elapsedTime, runMetrics) | ||
pullCoverageFile(lastTestIdentifier) | ||
removeCoverageFile() | ||
} | ||
|
||
private fun pullCoverageFile(test: TestIdentifier) { | ||
val localCoverageFile = | ||
fileManager.createFile(FileType.COVERAGE, pool, device.toDeviceInfo(), test.toTest()) | ||
val remoteFilePath = device.fileManager.remoteCoverageForTest() | ||
logger.trace { "Pulling from $remoteFilePath" } | ||
val millis = measureTimeMillis { | ||
device.fileManager.pullFile(remoteFilePath, localCoverageFile.toString()) | ||
} | ||
logger.trace { "Pulling file finished in ${millis}ms $remoteFilePath " } | ||
attachmentListeners.forEach { | ||
it.onAttachment( | ||
test.toTest(), | ||
Attachment(localCoverageFile, AttachmentType.COVERAGE) | ||
) | ||
} | ||
} | ||
|
||
private fun removeCoverageFile() { | ||
val remoteFilePath = device.fileManager.remoteCoverageForTest() | ||
val millis = measureTimeMillis { | ||
device.fileManager.removeRemotePath(remoteFilePath) | ||
} | ||
logger.trace { "Removed file in ${millis}ms $remoteFilePath" } | ||
} | ||
|
||
override fun registerListener(listener: AttachmentListener) { | ||
attachmentListeners.add(listener) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We are having an issue writing to influxDB 400 Bad Request, just want to log the request marathon is sending.