From b2b8311980546166839e004c568e83bf5ace6dcd Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Wed, 28 Feb 2024 19:10:17 -0800 Subject: [PATCH] The `adb logcat` filtering will continue until morale improves. (flutter/engine#51069) Closes https://github.com/flutter/flutter/issues/144346. --- .../bin/utils/adb_logcat_filtering.dart | 14 +++++-- .../test/adb_log_filter_test.dart | 38 +++++++++++++++---- .../test/src/fake_adb_logcat.dart | 4 +- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/engine/src/flutter/testing/scenario_app/bin/utils/adb_logcat_filtering.dart b/engine/src/flutter/testing/scenario_app/bin/utils/adb_logcat_filtering.dart index cc73cdb10b..f029f136dc 100644 --- a/engine/src/flutter/testing/scenario_app/bin/utils/adb_logcat_filtering.dart +++ b/engine/src/flutter/testing/scenario_app/bin/utils/adb_logcat_filtering.dart @@ -68,14 +68,20 @@ extension type const AdbLogLine._(Match _match) { /// Tries to parse the process that was started, if the log line is about it. String? tryParseProcess() { - if (name == 'ActivityManager' && message.startsWith('Start proc')) { - // Start proc 6840:d - final RegExpMatch? match = RegExp(r'Start proc (\d+):').firstMatch(message); + if (name == activityManagerTag && message.startsWith('Start proc')) { + // ActivityManager: Start proc 4475:dev.flutter.scenarios/u0a190 for added application ... + final RegExpMatch? match = RegExp('Start proc (\\d+):$flutterProcessName').firstMatch(message); return match?.group(1); } return null; } + @visibleForTesting + static const String activityManagerTag = 'ActivityManager'; + + @visibleForTesting + static const String flutterProcessName = 'dev.flutter.scenarios'; + @visibleForTesting static const Set knownNoiseTags = { 'CCodec', @@ -95,7 +101,7 @@ extension type const AdbLogLine._(Match _match) { @visibleForTesting static const Set knownUsefulTags = { - 'ActivityManager', + activityManagerTag }; @visibleForTesting diff --git a/engine/src/flutter/testing/scenario_app/test/adb_log_filter_test.dart b/engine/src/flutter/testing/scenario_app/test/adb_log_filter_test.dart index e6d6a7e199..c1e573157f 100644 --- a/engine/src/flutter/testing/scenario_app/test/adb_log_filter_test.dart +++ b/engine/src/flutter/testing/scenario_app/test/adb_log_filter_test.dart @@ -21,7 +21,7 @@ void main() { test('should always retain fatal logs', () { final FakeAdbLogcat logcat = FakeAdbLogcat(); - final FakeAdbProcess process = logcat.withProcess(); + final FakeAdbProcess process = logcat.process(); process.fatal('Something', 'A bad thing happened'); final Iterable filtered = filter(logcat.drain()); @@ -31,7 +31,7 @@ void main() { test('should never retain debug logs', () { final FakeAdbLogcat logcat = FakeAdbLogcat(); - final FakeAdbProcess process = logcat.withProcess(); + final FakeAdbProcess process = logcat.process(); final String tag = AdbLogLine.knownNoiseTags.first; process.debug(tag, 'A debug message'); @@ -41,7 +41,7 @@ void main() { test('should never retain logs from known "noise" tags', () { final FakeAdbLogcat logcat = FakeAdbLogcat(); - final FakeAdbProcess process = logcat.withProcess(); + final FakeAdbProcess process = logcat.process(); final String tag = AdbLogLine.knownNoiseTags.first; process.info(tag, 'Flutter flutter flutter'); @@ -51,7 +51,7 @@ void main() { test('should always retain logs from known "useful" tags', () { final FakeAdbLogcat logcat = FakeAdbLogcat(); - final FakeAdbProcess process = logcat.withProcess(); + final FakeAdbProcess process = logcat.process(); final String tag = AdbLogLine.knownUsefulTags.first; process.info(tag, 'A useful message'); @@ -62,7 +62,7 @@ void main() { test('if a process ID is passed, retain the log', () { final FakeAdbLogcat logcat = FakeAdbLogcat(); - final FakeAdbProcess process = logcat.withProcess(); + final FakeAdbProcess process = logcat.process(); process.info('SomeTag', 'A message'); final Iterable filtered = filter(logcat.drain(), filterProcessId: process.processId); @@ -72,7 +72,7 @@ void main() { test('even if a process ID passed, retain logs containing "flutter"', () { final FakeAdbLogcat logcat = FakeAdbLogcat(); - final FakeAdbProcess process = logcat.withProcess(); + final FakeAdbProcess process = logcat.process(); process.info('SomeTag', 'A message with flutter'); final Iterable filtered = filter(logcat.drain(), filterProcessId: process.processId); @@ -82,7 +82,7 @@ void main() { test('should retain E-level flags from known "useful" error tags', () { final FakeAdbLogcat logcat = FakeAdbLogcat(); - final FakeAdbProcess process = logcat.withProcess(); + final FakeAdbProcess process = logcat.process(); final String tag = AdbLogLine.knownUsefulErrorTags.first; process.error(tag, 'An error message'); process.info(tag, 'An info message'); @@ -94,7 +94,7 @@ void main() { test('should filter out error logs from unimportant processes', () { final FakeAdbLogcat logcat = FakeAdbLogcat(); - final FakeAdbProcess process = logcat.withProcess(); + final FakeAdbProcess process = logcat.process(); // I hate this one. const String tag = 'gs.intelligence'; @@ -103,4 +103,26 @@ void main() { final Iterable filtered = filter(logcat.drain()); expect(filtered, isEmpty); }); + + test('should filter the flutter-launched process, not just any process', () { + final FakeAdbLogcat logcat = FakeAdbLogcat(); + + final FakeAdbProcess device = logcat.process(); + final FakeAdbProcess unrelated = logcat.process(); + final FakeAdbProcess flutter = logcat.process(); + + device.info(AdbLogLine.activityManagerTag, 'Start proc ${unrelated.processId}:com.example.unrelated'); + + List rawLines = logcat.drain(); + expect(rawLines, hasLength(1)); + AdbLogLine parsedLogLine = AdbLogLine.tryParse(rawLines.single)!; + expect(parsedLogLine.tryParseProcess(), isNull); + + device.info(AdbLogLine.activityManagerTag, 'Start proc ${flutter.processId}:${AdbLogLine.flutterProcessName}'); + + rawLines = logcat.drain(); + expect(rawLines, hasLength(1)); + parsedLogLine = AdbLogLine.tryParse(rawLines.single)!; + expect(parsedLogLine.tryParseProcess(), '${flutter.processId}'); + }); } diff --git a/engine/src/flutter/testing/scenario_app/test/src/fake_adb_logcat.dart b/engine/src/flutter/testing/scenario_app/test/src/fake_adb_logcat.dart index f064d48618..a96d7db8eb 100644 --- a/engine/src/flutter/testing/scenario_app/test/src/fake_adb_logcat.dart +++ b/engine/src/flutter/testing/scenario_app/test/src/fake_adb_logcat.dart @@ -61,7 +61,7 @@ final class FakeAdbLogcat { /// /// Optionally specify a [processId] to use for the process, otherwise a /// simple default is used (sequential numbers starting from 1000). - FakeAdbProcess withProcess({int? processId}) { + FakeAdbProcess process({int? processId}) { processId ??= 1000 + _processById.length; return _processById.putIfAbsent( processId, @@ -76,7 +76,7 @@ final class FakeAdbLogcat { /// A stateful fixture that represents a fake process writing to `adb logcat`. /// -/// See [FakeAdbLogcat.withProcess] for how to create this fixture. +/// See [FakeAdbLogcat.process] for how to create this fixture. final class FakeAdbProcess { const FakeAdbProcess._( this._logcat, {