Skip to content

Commit 47a975d

Browse files
Improve error reporting for dumpsys meminfo (flutter#187254)
Improve error reporting for dumpsys meminfo parsing in devicelab Partially Addresses flutter#74085 ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [X] I updated/added relevant documentation (doc comments with `///`). - [X] I added new tests to check the change I am making, or this PR is [test-exempt]. - [X] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [X] All existing and new tests are passing. --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent fbc705f commit 47a975d

2 files changed

Lines changed: 19 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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,21 @@ void main() {
263263
),
264264
]);
265265
});
266+
267+
test('getMemoryStats throws DeviceException if dumpsys meminfo fails to parse', () {
268+
FakeDevice.output = 'Some garbage output';
269+
expect(device.getMemoryStats('com.example'), throwsA(isA<DeviceException>()));
270+
});
271+
272+
test('getMemoryStats returns memory stats if dumpsys meminfo parses successfully', () async {
273+
FakeDevice.resetLog();
274+
FakeDevice.output = 'TOTAL 12345';
275+
final Map<String, dynamic> stats = await device.getMemoryStats('com.example');
276+
expect(stats, <String, dynamic>{'total_kb': 12345});
277+
expectLog(const <CommandArgs>[
278+
CommandArgs(command: 'dumpsys', arguments: <String>['meminfo', 'com.example']),
279+
]);
280+
});
266281
});
267282
});
268283
}

0 commit comments

Comments
 (0)