Skip to content

Commit 7caa7c9

Browse files
committed
Resolve issue flutter#74085: Improve error reporting for dumpsys meminfo parsing in devicelab
1 parent 3fb2fe0 commit 7caa7c9

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎dev/devicelab/lib/framework/devices.dart‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,10 @@ class AndroidDevice extends Device {
765765
Future<Map<String, dynamic>> getMemoryStats(String packageName) async {
766766
final String meminfo = await shellEval('dumpsys', <String>['meminfo', packageName]);
767767
final Match? match = RegExp(r'TOTAL\s+(\d+)').firstMatch(meminfo);
768-
assert(match != null, 'could not parse dumpsys meminfo output');
769-
return <String, dynamic>{'total_kb': int.parse(match!.group(1)!)};
768+
if (match == null) {
769+
throw DeviceException('could not parse dumpsys meminfo output for $packageName: $meminfo');
770+
}
771+
return <String, dynamic>{'total_kb': int.parse(match.group(1)!)};
770772
}
771773

772774
@override

‎dev/devicelab/test/adb_test.dart‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@ void main() {
263263
),
264264
]);
265265
});
266+
267+
test('getMemoryStats throws DeviceException if dumpsys meminfo fails to parse', () async {
268+
FakeDevice.output = 'Some garbage output';
269+
expect(
270+
() async => await device.getMemoryStats('com.example'),
271+
throwsA(isA<DeviceException>()),
272+
);
273+
});
266274
});
267275
});
268276
}

0 commit comments

Comments
 (0)