Skip to content

Commit

Permalink
PR process setup (#1)
Browse files Browse the repository at this point in the history
* build(workflow): update action-android + upgrade deployment setup
* fix(workflow): build.prop is not available on emulator version 26. try other test file
* feat(framebuffer): handle protocol version 2
* fix(test): rewrite FileE2ETest pulling
  • Loading branch information
Malinskiy authored May 14, 2020
1 parent 946ad05 commit b92961e
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 67 deletions.
28 changes: 10 additions & 18 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 1.8
- uses: malinskiy/action-android/install-sdk@release/0.0.4
- uses: malinskiy/action-android/install-sdk@release/0.0.6
- name: gradle test jacocoTestReport
run: ./gradlew test jacocoTestReport
- name: Save test output
Expand Down Expand Up @@ -38,9 +38,10 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 1.8
- uses: malinskiy/action-android/install-sdk@release/0.0.4
- uses: malinskiy/action-android/install-sdk@release/0.0.6
- name: integration test
uses: malinskiy/action-android/emulator-run-cmd@release/0.0.4
uses: malinskiy/action-android/emulator-run-cmd@release/0.0.6
timeout-minutes: 20
with:
cmd: ./gradlew integrationTest
api: ${{ matrix.api }}
Expand All @@ -59,22 +60,13 @@ jobs:
with:
name: integration-test-coverage
path: build/reports/jacoco/jacocoIntegrationTestReport/html
- name: Save logcat output
uses: actions/upload-artifact@master
if: failure()
with:
name: logcat
path: artifacts/logcat.log
- name: codecov integartion tests
run: bash <(curl -s https://codecov.io/bash) -f ./build/reports/jacoco/jacocoIntegrationTestReport/jacocoIntegrationTestReport.xml -F integration
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
deploy:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: deploy-snapshot
run: bash .buildsystem/deploy-sonatype.sh
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
22 changes: 22 additions & 0 deletions .github/workflows/deploy-sonatype-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: deploy-sonatype-snapshot
on:
push:
branches:
- master
tags-ignore:
- '*'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: deploy-snapshot
run: bash .buildsystem/deploy-sonatype.sh
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.runBlocking
import org.junit.Rule
import org.junit.Test
import java.awt.image.BufferedImage
import java.io.File
import java.io.IOException
import javax.imageio.ImageIO
Expand All @@ -44,21 +43,9 @@ class E2ETest {
val image = adbRule.adb.execute(
ScreenCaptureRequest(),
adbRule.deviceSerial
)

val finalImage = BufferedImage(image.width, image.height, BufferedImage.TYPE_INT_ARGB)

var index = 0
val increment = image.bitsPerPixel shr 3
for (y in 0 until image.height) {
for (x in 0 until image.width) {
val value = image.getARGB(index)
index += increment
finalImage.setRGB(x, y, value)
}
}
).toBufferedImage()

if (!ImageIO.write(finalImage, "png", File("/tmp/screen.png"))) {
if (!ImageIO.write(image, "png", File("/tmp/screen.png"))) {
throw IOException("Failed to find png writer")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.malinskiy.adam.integration

import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.isEqualTo
import com.malinskiy.adam.extension.md5
import com.malinskiy.adam.request.sync.PullFileRequest
Expand All @@ -27,6 +28,8 @@ import com.malinskiy.adam.rule.AdbDeviceRule
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.channels.receiveOrNull
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import org.junit.After
import org.junit.Rule
import org.junit.Test
import java.io.File
Expand Down Expand Up @@ -88,12 +91,33 @@ class FileE2ETest {
}
}

@After
fun cleanup() {
runBlocking {
adbRule.adb.execute(ShellCommandRequest("rm /data/local/tmp/testfile"), serial = adbRule.deviceSerial)
}
}

@Test
fun testFilePulling() {
runBlocking {
val testFile = File("/tmp/build.prop")
val testFile = createTempFile()

withTimeout(10_000) {
while (true) {
var output =
adbRule.adb.execute(ShellCommandRequest("echo cafebabe > /data/local/tmp/testfile"), serial = adbRule.deviceSerial)
println(output)
output = adbRule.adb.execute(ShellCommandRequest("cat /data/local/tmp/testfile"), serial = adbRule.deviceSerial)
println(output)
if (output.contains("cafebabe")) {
break
}
}
}

val channel = adbRule.adb.execute(
PullFileRequest("/system/build.prop", testFile),
PullFileRequest("/data/local/tmp/testfile", testFile),
GlobalScope,
adbRule.deviceSerial
)
Expand All @@ -110,7 +134,7 @@ class FileE2ETest {
}
println()

val sizeString = adbRule.adb.execute(ShellCommandRequest("ls -ln /system/build.prop"), adbRule.deviceSerial)
val sizeString = adbRule.adb.execute(ShellCommandRequest("ls -ln /data/local/tmp/testfile"), adbRule.deviceSerial)
val split = sizeString.split(" ").filter { it != "" }

/**
Expand All @@ -120,6 +144,8 @@ class FileE2ETest {
*/
val dateIndex = split.indexOfLast { it.matches("[\\d]{4}-[\\d]{2}-[\\d]{2}".toRegex()) }
assertThat(split[dateIndex - 1].toLong()).isEqualTo(testFile.length())

assertThat(testFile.readText()).contains("cafebabe")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,48 @@ package com.malinskiy.adam.rule

import com.malinskiy.adam.AndroidDebugBridgeClientFactory
import com.malinskiy.adam.interactor.StartAdbInteractor
import com.malinskiy.adam.request.devices.Device
import com.malinskiy.adam.request.devices.DeviceState
import com.malinskiy.adam.request.devices.ListDevicesRequest
import com.malinskiy.adam.request.sync.GetSinglePropRequest
import kotlinx.coroutines.runBlocking
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
import java.net.ConnectException

class AdbDeviceRule : TestRule {
val deviceSerial = "emulator-5554"
val adb = AndroidDebugBridgeClientFactory().build()

override fun apply(base: Statement?, description: Description?): Statement {
return object: Statement() {
return object : Statement() {
override fun evaluate() {
runBlocking {
StartAdbInteractor().execute()

//Wait for device to be available on adb server
while (true) {
try {
val output = adb.execute(ListDevicesRequest())
if (output.contains(Device(deviceSerial, DeviceState.DEVICE))) {
break
}
} catch (e: ConnectException) {
continue
}
}

//Wait for device boot
while (true) {
try {
val completed = adb.execute(GetSinglePropRequest("sys.boot_completed"))
if (completed.isNotEmpty()) break
continue
} catch (e: ConnectException) {
continue
}
}
}
base?.evaluate()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ class PullFileRequest(
return currentPosition.toDouble() / totalBytes
}
header.contentEquals(Const.Message.FAIL) -> {
throw PullFailedException("Failed to pull file $remotePath")
val size = headerBuffer.copyOfRange(4, 8).toInt()
readChannel.readFully(dataBuffer, 0, size)
val errorMessage = String(dataBuffer, 0, size)
throw PullFailedException("Failed to pull file $remotePath: $errorMessage")
}
else -> {
throw UnsupportedSyncProtocolException("Unexpected header message ${String(header, Const.DEFAULT_TRANSPORT_ENCODING)}")
Expand Down
Loading

0 comments on commit b92961e

Please sign in to comment.