Skip to content

Commit

Permalink
Make baseline profile generators independently copyable
Browse files Browse the repository at this point in the history
Remove dependency on BaselineProfileGeneratorScaffold.
This makes it easier to copy each generator into a separate project.
  • Loading branch information
keyboardsurfer committed Aug 30, 2024
1 parent 8ca6d63 commit 26651e0
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 114 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,41 @@
package com.example.macrobenchmark.baselineprofile

import android.content.Intent
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Direction
import com.example.macrobenchmark.benchmark.util.findOrFail
import com.example.macrobenchmark.benchmark.util.waitAndFind
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@Ignore // TODO causing stale object excpetion on CI .. why?
@RunWith(AndroidJUnit4::class)
class ComposeActivityBaselineProfileGenerator : BaselineProfileGeneratorScaffold() {
@RunWith(AndroidJUnit4ClassRunner::class)
class ComposeActivityBaselineProfileGenerator {

override fun MacrobenchmarkScope.profileBlock() {
// Start into the Compose Activity
startActivityAndWait(Intent("$TARGET_PACKAGE.COMPOSE_ACTIVITY"))
@get:Rule
val rule = BaselineProfileRule()

// Scrolling through the Compose journey
device.waitAndFind(By.res("myLazyColumn")).also {
it.setGestureMargin(device.displayWidth / 10)
it.fling(Direction.DOWN)
}
@Test
fun generate() {
rule.collect(
packageName = TARGET_PACKAGE,
maxIterations = 15,
stableIterations = 3
) {
// Start into the Compose Activity
startActivityAndWait(Intent("$TARGET_PACKAGE.COMPOSE_ACTIVITY"))

// Scrolling through the Compose journey
device.waitAndFind(By.res("myLazyColumn")).also {
it.setGestureMargin(device.displayWidth / 10)
it.fling(Direction.DOWN)
}

device.findOrFail(By.res("myLazyColumn")).fling(Direction.UP)
device.findOrFail(By.res("myLazyColumn")).fling(Direction.UP)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,31 @@
package com.example.macrobenchmark.baselineprofile

import android.content.Intent
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import androidx.test.uiautomator.By
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

class LoginBaselineProfileGenerator : BaselineProfileGeneratorScaffold() {
@RunWith(AndroidJUnit4ClassRunner::class)
class LoginBaselineProfileGenerator {

override fun MacrobenchmarkScope.profileBlock() {
startActivityAndWait(Intent("$packageName.LOGIN_ACTIVITY"))
device.findObject(By.res("userName")).text = "user"
device.findObject(By.res("password")).text = "password"
device.findObject(By.res("login")).click()
device.waitForIdle()
@get:Rule
val rule = BaselineProfileRule()

@Test
fun generate() {
rule.collect(
packageName = TARGET_PACKAGE,
maxIterations = 15,
stableIterations = 3
) {
startActivityAndWait(Intent("$packageName.LOGIN_ACTIVITY"))
device.findObject(By.res("userName")).text = "user"
device.findObject(By.res("password")).text = "password"
device.findObject(By.res("login")).click()
device.waitForIdle()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,38 @@
package com.example.macrobenchmark.baselineprofile

import android.content.Intent
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Direction
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@Ignore // TODO flinging not working, ignore for now to test the pipeline
@RunWith(AndroidJUnit4::class)
class RecyclerViewActivityBaselineProfileGenerator : BaselineProfileGeneratorScaffold() {
@RunWith(AndroidJUnit4ClassRunner::class)
class RecyclerViewActivityBaselineProfileGenerator {

override fun MacrobenchmarkScope.profileBlock() {
// Start into the RecyclerViewActivity
startActivityAndWait(Intent("$TARGET_PACKAGE.RECYCLER_VIEW_ACTIVITY"))
@get:Rule
val rule = BaselineProfileRule()

// Scrolling RecyclerView journey
device.findObject(By.res(packageName, "recycler")).also {
it.setGestureMargin(device.displayWidth / 10)
it.fling(Direction.DOWN)
it.fling(Direction.UP)
@Test
fun generate() {
rule.collect(
packageName = TARGET_PACKAGE,
maxIterations = 15,
stableIterations = 3
) {
// Start into the RecyclerViewActivity
startActivityAndWait(Intent("$TARGET_PACKAGE.RECYCLER_VIEW_ACTIVITY"))

// Scrolling RecyclerView journey
device.findObject(By.res(packageName, "recycler")).also {
it.setGestureMargin(device.displayWidth / 10)
it.fling(Direction.DOWN)
it.fling(Direction.UP)
}
}
}
}

This file was deleted.

0 comments on commit 26651e0

Please sign in to comment.