Skip to content

Commit

Permalink
Start including logs in test results
Browse files Browse the repository at this point in the history
  • Loading branch information
stevesoltys committed Oct 11, 2023
1 parent bc90378 commit c208d55
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
path: |
~/.android/avd/*
~/.android/adb*
key: aosp-${{ matrix.emulator_type }}-${{ matrix.android_target }}-${{ runner.os }}
key: avd-${{ matrix.emulator_type }}-${{ matrix.android_target }}

- name: Build Release APK
run: ./gradlew :app:assembleRelease
Expand Down Expand Up @@ -105,14 +105,14 @@ jobs:
medium_test_exit_code=0
./gradlew --stacktrace -Pinstrumented_test_size=medium :app:connectedAndroidTest || medium_test_exit_code=$?
adb pull /sdcard/seedvault_test_videos
adb pull /sdcard/seedvault_test_results
if [ $large_test_exit_code -ne 0 ]; then echo 'Gradle test failed.'; exit 0; fi
if [ $medium_test_exit_code -ne 0 ]; then echo 'Gradle test failed.'; exit 0; fi
- name: Upload screenshots and videos
- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
with:
name: seedvault_test_videos
path: seedvault_test_videos/**/*.mp4
name: ${{ matrix.emulator_type }}-${{ matrix.android_target }}-results
path: seedvault_test_results/**/*
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal interface LargeTestBase : KoinComponent {

companion object {
private const val TEST_STORAGE_FOLDER = "seedvault_test"
private const val TEST_VIDEO_FOLDER = "seedvault_test_videos"
private const val TEST_VIDEO_FOLDER = "seedvault_test_results"
}

val externalStorageDir: String get() = Environment.getExternalStorageDirectory().absolutePath
Expand Down Expand Up @@ -106,19 +106,23 @@ internal interface LargeTestBase : KoinComponent {
uiAutomation.executeShellCommand(command).close()
}

fun testResultFilename(testName: String): String {
val simpleDateFormat = SimpleDateFormat("yyyyMMdd_hhmmss")
val timeStamp = simpleDateFormat.format(Calendar.getInstance().time)
return "${timeStamp}_${testName.replace(" ", "_")}"
}

@OptIn(DelicateCoroutinesApi::class)
@WorkerThread
suspend fun startScreenRecord(
suspend fun startRecordingTest(
keepRecordingScreen: AtomicBoolean,
testName: String,
) {
val simpleDateFormat = SimpleDateFormat("yyyyMMdd_hhmmss")
val timeStamp = simpleDateFormat.format(Calendar.getInstance().time)
val fileName = "${timeStamp}_${testName.replace(" ", "_")}"

val folder = testVideoPath
runCommand("mkdir -p $folder")

val fileName = testResultFilename(testName)

// screen record automatically stops after 3 minutes
// we need to block on a loop and split it into multiple files
GlobalScope.launch(Dispatchers.IO) {
Expand All @@ -131,10 +135,16 @@ internal interface LargeTestBase : KoinComponent {
}

@WorkerThread
fun stopScreenRecord(keepRecordingScreen: AtomicBoolean) {
fun stopRecordingTest(
keepRecordingScreen: AtomicBoolean,
testName: String,
) {
keepRecordingScreen.set(false)

runCommand("pkill -2 screenrecord")

// write logcat to file
val fileName = testResultFilename(testName)
runCommand("logcat -d -f $testVideoPath/$fileName.log")
}

fun uninstallPackages(packages: Collection<PackageInfo>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ internal abstract class SeedvaultLargeTest :
resetApplicationState()
clearTestBackups()

startScreenRecord(keepRecordingScreen, name.methodName)
startRecordingTest(keepRecordingScreen, name.methodName)
restoreBaselineBackup()
}

@After
open fun tearDown() {
stopScreenRecord(keepRecordingScreen)
stopRecordingTest(keepRecordingScreen, name.methodName)
}

/**
Expand Down

0 comments on commit c208d55

Please sign in to comment.