Workaround the issue that parameterized test don't support @UiThreadTest
When the test infrastructure support it, this change should be reverted. b/30746303 Change-Id: Ice181d93f4f1210bcd2c8566e61c90035fe12ec5
This commit is contained in:
@@ -78,29 +78,31 @@ public class LayoutPerfTest {
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void testLayoutPerf() {
|
||||
assertTrue("We should be running on the main thread",
|
||||
Looper.getMainLooper().getThread() == Thread.currentThread());
|
||||
assertTrue("We should be running on the main thread",
|
||||
Looper.myLooper() == Looper.getMainLooper());
|
||||
public void testLayoutPerf() throws Throwable {
|
||||
mActivityRule.runOnUiThread(() -> {
|
||||
assertTrue("We should be running on the main thread",
|
||||
Looper.getMainLooper().getThread() == Thread.currentThread());
|
||||
assertTrue("We should be running on the main thread",
|
||||
Looper.myLooper() == Looper.getMainLooper());
|
||||
|
||||
Activity activity = mActivityRule.getActivity();
|
||||
activity.setContentView(mLayoutId);
|
||||
Activity activity = mActivityRule.getActivity();
|
||||
activity.setContentView(mLayoutId);
|
||||
|
||||
ViewGroup viewGroup = (ViewGroup) activity.findViewById(mViewId);
|
||||
ViewGroup viewGroup = (ViewGroup) activity.findViewById(mViewId);
|
||||
|
||||
List<View> allNodes = gatherViewTree(viewGroup);
|
||||
BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
|
||||
List<View> allNodes = gatherViewTree(viewGroup);
|
||||
BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
|
||||
|
||||
int length = mMeasureSpecs.length;
|
||||
while (state.keepRunning()) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
// The overhead of this call is ignorable, like within 1% difference.
|
||||
requestLayoutForAllNodes(allNodes);
|
||||
int length = mMeasureSpecs.length;
|
||||
while (state.keepRunning()) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
// The overhead of this call is ignorable, like within 1% difference.
|
||||
requestLayoutForAllNodes(allNodes);
|
||||
|
||||
viewGroup.measure(mMeasureSpecs[i % length], mMeasureSpecs[i % length]);
|
||||
viewGroup.layout(0, 0, viewGroup.getMeasuredWidth(), viewGroup.getMeasuredHeight());
|
||||
viewGroup.measure(mMeasureSpecs[i % length], mMeasureSpecs[i % length]);
|
||||
viewGroup.layout(0, 0, viewGroup.getMeasuredWidth(), viewGroup.getMeasuredHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user