Unverified Commit 22dd0f42 authored by Jia Hao's avatar Jia Hao Committed by GitHub

[flutter_test] Fix incorrect missed budget count (#95003)

parent df4d851f
......@@ -294,16 +294,21 @@ class FrameTimingSummarizer {
};
}
// The following helper functions require data sorted
// return the 100*p-th percentile of the data
/// Returns the 100*p-th percentile of [data].
///
/// [data] must be sorted in ascending order.
T _findPercentile<T>(List<T> data, double p) {
assert(p >= 0 && p <= 1);
return data[((data.length - 1) * p).round()];
}
// return the number of items in data that > threshold
/// Returns the number of elements in [data] that exceed [threshold].
///
/// [data] must be sorted in ascending order.
int _countExceed<T extends Comparable<T>>(List<T> data, T threshold) {
return data.length -
data.indexWhere((T datum) => datum.compareTo(threshold) > 0);
final int exceedsThresholdIndex = data.indexWhere((T datum) => datum.compareTo(threshold) > 0);
if (exceedsThresholdIndex == -1) {
return 0;
}
return data.length - exceedsThresholdIndex;
}
......@@ -7,7 +7,8 @@ import 'dart:ui';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('Test FrameTimingSummarizer', () {
group(FrameTimingSummarizer, () {
test('calculates all fields', () {
List<int> vsyncTimes = <int>[
for (int i = 0; i < 100; i += 1) 100 * (i + 1),
];
......@@ -54,4 +55,87 @@ void main() {
expect(summary.p99VsyncOverhead.inMicroseconds, 9900);
expect(summary.worstVsyncOverhead.inMicroseconds, 10000);
});
group('missed budget count', () {
test('when single element missed budget', () {
final FrameTimingSummarizer summary = FrameTimingSummarizer(<FrameTiming>[
FrameTiming(
buildStart: 0,
buildFinish: (kBuildBudget + const Duration(microseconds: 1)).inMicroseconds,
vsyncStart: 0,
rasterStart: 0,
rasterFinish: 0,
rasterFinishWallTime: 0,
),
]);
expect(summary.missedFrameBuildBudget, 1);
});
test('when single element within budget', () {
final FrameTimingSummarizer summary = FrameTimingSummarizer(<FrameTiming>[
FrameTiming(
buildStart: 0,
buildFinish: 0,
vsyncStart: 0,
rasterStart: 0,
rasterFinish: 0,
rasterFinishWallTime: 0,
),
]);
expect(summary.missedFrameBuildBudget, 0);
});
test('when single element exactly within budget', () {
final FrameTimingSummarizer summary = FrameTimingSummarizer(<FrameTiming>[
FrameTiming(
buildStart: 0,
buildFinish: kBuildBudget.inMicroseconds,
vsyncStart: 0,
rasterStart: 0,
rasterFinish: 0,
rasterFinishWallTime: 0,
),
]);
expect(summary.missedFrameBuildBudget, 0);
});
test('when many missed budget', () {
final FrameTimingSummarizer summary = FrameTimingSummarizer(<FrameTiming>[
FrameTiming(
buildStart: 0,
buildFinish: 0,
vsyncStart: 0,
rasterStart: 0,
rasterFinish: 0,
rasterFinishWallTime: 0,
),
FrameTiming(
buildStart: 0,
buildFinish: kBuildBudget.inMicroseconds,
vsyncStart: 0,
rasterStart: 0,
rasterFinish: 0,
rasterFinishWallTime: 0,
),
FrameTiming(
buildStart: 0,
buildFinish: (kBuildBudget + const Duration(microseconds: 1)).inMicroseconds,
vsyncStart: 0,
rasterStart: 0,
rasterFinish: 0,
rasterFinishWallTime: 0,
),
FrameTiming(
buildStart: 0,
buildFinish: (kBuildBudget + const Duration(microseconds: 2)).inMicroseconds,
vsyncStart: 0,
rasterStart: 0,
rasterFinish: 0,
rasterFinishWallTime: 0,
),
]);
expect(summary.missedFrameBuildBudget, 2);
});
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment