[ Device Lab ] Add regression testing for flutter/flutter#174952 (#174956)

Also switches to using a regex group to match the device state instead
of splitting the matched string on '='.

Fixes https://github.com/flutter/flutter/issues/174952

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
Ben Konyi 2025-09-05 11:40:29 -04:00 committed by GitHub
parent dbc119c5f5
commit 87d5b75319
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 4 deletions

View File

@ -685,9 +685,10 @@ class AndroidDevice extends Device {
final String powerInfo = await shellEval('dumpsys', <String>['power']);
// A motoG4 phone returns `mWakefulness=Awake`.
// A Samsung phone returns `getWakefullnessLocked()=Awake`.
final RegExp wakefulnessRegexp = RegExp(r'(?:mWakefulness|getWakefulnessLocked\(\))=[a-zA-Z]+');
final String wakefulness = grep(wakefulnessRegexp, from: powerInfo).single.split('=')[1].trim();
return wakefulness;
final RegExp wakefulnessRegexp = RegExp(
r'(?:mWakefulness|getWakefulnessLocked\(\))=\s*([a-zA-Z]+)',
);
return wakefulnessRegexp.allMatches(powerInfo).single.group(1)!;
}
Future<bool> isArm64() async {

View File

@ -23,7 +23,9 @@ void main() {
device = FakeDevice(deviceId: 'fakeDeviceId');
});
tearDown(() {});
tearDown(() {
FakeDevice.resetLog();
});
group('cpu check', () {
test('arm64', () async {
@ -325,20 +327,38 @@ class FakeDevice extends AndroidDevice {
}
static void pretendAwake() {
// Emit an integer value in addition to the state string to ensure only
// the state string is matched.
//
// Regression testing for https://github.com/flutter/flutter/issues/174952.
output = '''
mWakefulness=1
mWakefulness=Awake
''';
}
static void pretendAwakeSamsung() {
// Emit an integer value in addition to the state string to ensure only
// the state string is matched.
//
// Regression testing for https://github.com/flutter/flutter/issues/174952.
output = '''
getWakefulnessLocked()=1
getWakefulnessLocked()=Awake
''';
}
static void pretendAsleep() {
// Emit an integer value in addition to the state string to ensure only
// the state string is matched.
//
// Regression testing for https://github.com/flutter/flutter/issues/174952.
output = '''
mWakefulness=0
mWakefulness=Asleep
''';
}