Skip to content

Commit 87d5b75

Browse files
[ Device Lab ] Add regression testing for flutter#174952 (flutter#174956)
Also switches to using a regex group to match the device state instead of splitting the matched string on '='. Fixes flutter#174952 --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent dbc119c commit 87d5b75

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

dev/devicelab/lib/framework/devices.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,10 @@ class AndroidDevice extends Device {
685685
final String powerInfo = await shellEval('dumpsys', <String>['power']);
686686
// A motoG4 phone returns `mWakefulness=Awake`.
687687
// A Samsung phone returns `getWakefullnessLocked()=Awake`.
688-
final RegExp wakefulnessRegexp = RegExp(r'(?:mWakefulness|getWakefulnessLocked\(\))=[a-zA-Z]+');
689-
final String wakefulness = grep(wakefulnessRegexp, from: powerInfo).single.split('=')[1].trim();
690-
return wakefulness;
688+
final RegExp wakefulnessRegexp = RegExp(
689+
r'(?:mWakefulness|getWakefulnessLocked\(\))=\s*([a-zA-Z]+)',
690+
);
691+
return wakefulnessRegexp.allMatches(powerInfo).single.group(1)!;
691692
}
692693

693694
Future<bool> isArm64() async {

dev/devicelab/test/adb_test.dart

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ void main() {
2323
device = FakeDevice(deviceId: 'fakeDeviceId');
2424
});
2525

26-
tearDown(() {});
26+
tearDown(() {
27+
FakeDevice.resetLog();
28+
});
2729

2830
group('cpu check', () {
2931
test('arm64', () async {
@@ -325,20 +327,38 @@ class FakeDevice extends AndroidDevice {
325327
}
326328

327329
static void pretendAwake() {
330+
// Emit an integer value in addition to the state string to ensure only
331+
// the state string is matched.
332+
//
333+
// Regression testing for https://github.com/flutter/flutter/issues/174952.
328334
output = '''
335+
mWakefulness=1
329336
mWakefulness=Awake
337+
330338
''';
331339
}
332340

333341
static void pretendAwakeSamsung() {
342+
// Emit an integer value in addition to the state string to ensure only
343+
// the state string is matched.
344+
//
345+
// Regression testing for https://github.com/flutter/flutter/issues/174952.
334346
output = '''
347+
getWakefulnessLocked()=1
335348
getWakefulnessLocked()=Awake
349+
336350
''';
337351
}
338352

339353
static void pretendAsleep() {
354+
// Emit an integer value in addition to the state string to ensure only
355+
// the state string is matched.
356+
//
357+
// Regression testing for https://github.com/flutter/flutter/issues/174952.
340358
output = '''
359+
mWakefulness=0
341360
mWakefulness=Asleep
361+
342362
''';
343363
}
344364

0 commit comments

Comments
 (0)