Skip to content

Commit

Permalink
Merge pull request #242 from android/enable-scroll-benchmark
Browse files Browse the repository at this point in the history
Enable ScrollView Benchmark
  • Loading branch information
yenerm committed Jul 12, 2023
2 parents 06d7699 + 22a4296 commit 79e914d
Showing 1 changed file with 27 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2022 The Android Open Source Project
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -14,33 +14,31 @@
* limitations under the License.
*/

package com.example.benchmark.macro.base.scroll
package com.example.macrobenchmark.scroll

import android.content.Intent
import androidx.benchmark.macro.BaselineProfileMode
import androidx.benchmark.macro.CompilationMode
import androidx.benchmark.macro.ExperimentalMetricApi
import androidx.benchmark.macro.FrameTimingMetric
import androidx.benchmark.macro.StartupMode
import androidx.benchmark.macro.StartupTimingMetric
import androidx.benchmark.macro.TraceSectionMetric
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.filters.SdkSuppress
import androidx.test.filters.Suppress
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Direction
import androidx.test.uiautomator.Until
import com.example.benchmark.macro.base.util.DEFAULT_ITERATIONS
import com.example.benchmark.macro.base.util.TARGET_PACKAGE
import junit.framework.TestCase.fail
import junit.framework.TestCase
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

/**
* Scrolls down and up in the default activity.
*/
@RunWith(AndroidJUnit4::class)
// These tests are only useful for apps that have a scrollable view in the benchmarked activity.
@Suppress
@OptIn(ExperimentalMetricApi::class)
class ScrollBenchmark {

@get:Rule
Expand All @@ -53,43 +51,34 @@ class ScrollBenchmark {
@Test
fun defaultCompilation() = scroll(CompilationMode.DEFAULT)

@Test
@SdkSuppress(minSdkVersion = 24)
fun partialBaselineProfileDisabled() =
scroll(
CompilationMode.Partial(
baselineProfileMode = BaselineProfileMode.Disable,
warmupIterations = 3
)
)

@Test
@SdkSuppress(minSdkVersion = 24)
fun partialBaselineProfileRequired() =
scroll(
CompilationMode.Partial(
baselineProfileMode = BaselineProfileMode.Require,
warmupIterations = 3
)
)

@Test
fun full() = scroll(CompilationMode.Full())

private fun scroll(compilationMode: CompilationMode) =
private fun scroll(compilationMode: CompilationMode) {
var firstStart = true
benchmarkRule.measureRepeated(
packageName = TARGET_PACKAGE,
metrics = listOf(StartupTimingMetric(), FrameTimingMetric()),
metrics = listOf(
TraceSectionMetric("ClickTrace"),
StartupTimingMetric(),
FrameTimingMetric()
),
compilationMode = compilationMode,
startupMode = StartupMode.COLD,
iterations = DEFAULT_ITERATIONS
startupMode = null,
iterations = DEFAULT_ITERATIONS,
setupBlock = {
if (firstStart) {
val intent = Intent("$packageName.SCROLL_VIEW_ACTIVITY")
startActivityAndWait(intent)
firstStart = false
}
}
) {
startActivityAndWait()
device.wait(Until.hasObject(By.scrollable(true)), 5_000)

val scrollableObject = device.findObject(By.scrollable(true))
if (scrollableObject == null) {
fail("No scrollable view found in hierarchy")
TestCase.fail("No scrollable view found in hierarchy")
}
scrollableObject.setGestureMargin(device.displayWidth / 10)
scrollableObject?.apply {
Expand All @@ -101,4 +90,5 @@ class ScrollBenchmark {
}
}
}
}
}

0 comments on commit 79e914d

Please sign in to comment.