Skip to content

Commit

Permalink
feat(android): add tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
Malinskiy committed Nov 6, 2024
1 parent 7d376e5 commit 1f3702b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data class Attachment(val file: File, val type: AttachmentType, val name: String
const val LOG = "log"
const val LOGCAT = "logcat"
const val XCODEBUILDLOG = "xcodebuild-log"
const val TRACING = "perfetto-trace"
const val TRACING = "tracing"
}
}

Expand All @@ -22,5 +22,5 @@ enum class AttachmentType(val mimeType: String) {
SCREENSHOT_WEBP("image/webp"),
VIDEO("video/mp4"),
LOG("text/plain"),
TRACING("text/plain");
TRACING("application/octet-stream");
}
2 changes: 1 addition & 1 deletion core/src/main/kotlin/com/malinskiy/marathon/io/FileType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ enum class FileType(val dir: String, val suffix: String) {
SCREENSHOT_GIF("screenshot", "jpg"),
XCTESTRUN("xctestrun", "xctestrun"),
BILL("bill", "json"),
TRACING("tracing", "perfetto-trace"),
TRACING("tracing", "trace"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.google.common.collect.ImmutableMap
import com.malinskiy.marathon.analytics.internal.sub.ExecutionReport
import com.malinskiy.marathon.config.Configuration
import com.malinskiy.marathon.device.DeviceInfo
import com.malinskiy.marathon.execution.AttachmentType
import com.malinskiy.marathon.execution.TestResult
import com.malinskiy.marathon.execution.TestStatus
import com.malinskiy.marathon.report.Reporter
Expand All @@ -15,6 +16,7 @@ import io.qameta.allure.AllureLifecycle
import io.qameta.allure.FileSystemResultsWriter
import io.qameta.allure.model.Attachment
import io.qameta.allure.model.Label
import io.qameta.allure.model.Link
import io.qameta.allure.model.Status
import io.qameta.allure.model.StatusDetails
import io.qameta.allure.util.ResultsUtils
Expand Down Expand Up @@ -77,10 +79,22 @@ class AllureReporter(val configuration: Configuration, private val outputDirecto
TestStatus.IGNORED -> Status.SKIPPED
}

val links = mutableListOf<Link>()

val allureAttachments: List<Attachment> = testResult.attachments.mapNotNull {
if (it.empty) {
null
} else {
when (it.type) {
AttachmentType.TRACING -> links.add(
Link().apply {
setUrl("https://cloud.marathonlabs.io/trace/view?todo=x")
setName("Tracing")
}
)

else -> Unit
}
val name = it.name ?: it.type.name.lowercase(Locale.ENGLISH)
.replaceFirstChar { cher -> if (cher.isLowerCase()) cher.titlecase(Locale.ENGLISH) else cher.toString() }
Attachment()
Expand All @@ -100,6 +114,7 @@ class AllureReporter(val configuration: Configuration, private val outputDirecto
.setStop(testResult.endTime)
.setAttachments(allureAttachments)
.setParameters(emptyList())
.setLinks(links)
.setLabels(
mutableListOf(
ResultsUtils.createHostLabel().setValue(device.serialNumber),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.malinskiy.marathon.android.executor.listeners.TestResultsListener
import com.malinskiy.marathon.android.executor.listeners.filesync.FileSyncTestRunListener
import com.malinskiy.marathon.android.executor.listeners.screenshot.AdamScreenCaptureTestRunListener
import com.malinskiy.marathon.android.executor.listeners.screenshot.ScreenCapturerTestRunListener
import com.malinskiy.marathon.android.executor.listeners.tracing.PerfettoRunListener
import com.malinskiy.marathon.android.executor.listeners.tracing.TracingRunListener
import com.malinskiy.marathon.android.executor.listeners.video.ScreenRecorderTestBatchListener
import com.malinskiy.marathon.android.model.ShellCommandResult
import com.malinskiy.marathon.device.screenshot.Rotation
Expand Down Expand Up @@ -256,7 +256,7 @@ abstract class BaseAndroidDevice(

val tracingConfiguration = this@BaseAndroidDevice.androidConfiguration.tracingConfiguration
val tracingListener = if (tracingConfiguration.enabled && tracingConfiguration.pbtxt != null) {
PerfettoRunListener(
TracingRunListener(
fileManager,
devicePoolId,
testBatch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RemoteFileManager(private val device: AndroidDevice) {
}

fun remoteTracingForTest(test: Test, testBatchId: String): String {
return "$PERFETTO_TRACE_ROOT/${traceFileName(test, testBatchId)}"
return "$TRACE_ROOT/${traceFileName(test, testBatchId)}"
}

private fun remoteFileForTest(filename: String): String {
Expand Down Expand Up @@ -62,7 +62,7 @@ class RemoteFileManager(private val device: AndroidDevice) {
companion object {
const val MAX_FILENAME = 255
const val TMP_PATH = "/data/local/tmp"
const val PERFETTO_TRACE_ROOT = "/data/misc/perfetto-traces"
const val PERFETTO_CONFIG_FILE = "$TMP_PATH/tracing.pbtx"
const val TRACE_ROOT = "/data/misc/perfetto-traces"
const val TRACE_CONFIG_FILE = "$TMP_PATH/tracing.pbtx"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import kotlin.coroutines.cancellation.CancellationException
import kotlin.system.measureTimeMillis


class PerfettoRunListener(
class TracingRunListener(
private val fileManager: FileManager,
private val pool: DevicePoolId,
private val testBatch: TestBatch,
Expand All @@ -37,7 +37,7 @@ class PerfettoRunListener(
private val testBundleIdentifier: AndroidTestBundleIdentifier,
coroutineScope: CoroutineScope
) : NoOpTestRunListener(), AttachmentProvider, CoroutineScope by coroutineScope {
private val logger = MarathonLogging.logger("PerfettoRunListener")
private val logger = MarathonLogging.logger("TracingRunListener")

private var job: Job? = null
private val attachmentListeners = mutableListOf<AttachmentListener>()
Expand Down

0 comments on commit 1f3702b

Please sign in to comment.