-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better filtering for Android scenario_app
runner.
#50937
Merged
matanlurey
merged 8 commits into
flutter:main
from
matanlurey:scenario_app-better-filtering
Feb 26, 2024
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
84cef7b
Actually list all sources for scenario_app target.
matanlurey 794caf7
Start work on better filtering.
matanlurey 22f83c3
Finish filtering.
matanlurey 68a5de9
++
matanlurey 2b16508
++
matanlurey 18bcbc3
Merge remote-tracking branch 'upstream/main' into scenario_app-better…
matanlurey 34a5f3e
++
matanlurey 14f7bd9
++
matanlurey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,48 +47,52 @@ void main(List<String> args) async { | |
..addOption( | ||
'adb', | ||
help: 'Path to the adb tool', | ||
defaultsTo: engine != null ? join( | ||
engine.srcDir.path, | ||
'third_party', | ||
'android_tools', | ||
'sdk', | ||
'platform-tools', | ||
'adb', | ||
) : null, | ||
defaultsTo: engine != null | ||
? join( | ||
engine.srcDir.path, | ||
'third_party', | ||
'android_tools', | ||
'sdk', | ||
'platform-tools', | ||
'adb', | ||
) | ||
: null, | ||
) | ||
..addOption( | ||
'ndk-stack', | ||
help: 'Path to the ndk-stack tool', | ||
defaultsTo: engine != null ? join( | ||
engine.srcDir.path, | ||
'third_party', | ||
'android_tools', | ||
'ndk', | ||
'prebuilt', | ||
() { | ||
if (Platform.isLinux) { | ||
return 'linux-x86_64'; | ||
} else if (Platform.isMacOS) { | ||
return 'darwin-x86_64'; | ||
} else if (Platform.isWindows) { | ||
return 'windows-x86_64'; | ||
} else { | ||
throw UnsupportedError('Unsupported platform: ${Platform.operatingSystem}'); | ||
} | ||
}(), | ||
'bin', | ||
'ndk-stack', | ||
) : null, | ||
defaultsTo: engine != null | ||
? join( | ||
engine.srcDir.path, | ||
'third_party', | ||
'android_tools', | ||
'ndk', | ||
'prebuilt', | ||
() { | ||
if (Platform.isLinux) { | ||
return 'linux-x86_64'; | ||
} else if (Platform.isMacOS) { | ||
return 'darwin-x86_64'; | ||
} else if (Platform.isWindows) { | ||
return 'windows-x86_64'; | ||
} else { | ||
throw UnsupportedError('Unsupported platform: ${Platform.operatingSystem}'); | ||
} | ||
}(), | ||
'bin', | ||
'ndk-stack', | ||
) | ||
: null, | ||
) | ||
..addOption( | ||
'out-dir', | ||
help: 'Out directory', | ||
defaultsTo: | ||
engine?. | ||
outputs(). | ||
where((Output o) => basename(o.path.path).startsWith('android_')). | ||
firstOrNull?. | ||
path.path, | ||
defaultsTo: engine | ||
?.outputs() | ||
.where((Output o) => basename(o.path.path).startsWith('android_')) | ||
.firstOrNull | ||
?.path | ||
.path, | ||
) | ||
..addOption( | ||
'smoke-test', | ||
|
@@ -106,14 +110,16 @@ void main(List<String> args) async { | |
..addOption( | ||
'output-contents-golden', | ||
help: 'Path to a file that contains the expected filenames of golden files.', | ||
defaultsTo: engine != null ? join( | ||
engine.srcDir.path, | ||
'flutter', | ||
'testing', | ||
'scenario_app', | ||
'android', | ||
'expected_golden_output.txt', | ||
) : null, | ||
defaultsTo: engine != null | ||
? join( | ||
engine.srcDir.path, | ||
'flutter', | ||
'testing', | ||
'scenario_app', | ||
'android', | ||
'expected_golden_output.txt', | ||
) | ||
: null, | ||
) | ||
..addOption( | ||
'impeller-backend', | ||
|
@@ -124,8 +130,8 @@ void main(List<String> args) async { | |
..addOption( | ||
'logs-dir', | ||
help: 'The directory to store the logs and screenshots. Defaults to ' | ||
'the value of the FLUTTER_LOGS_DIR environment variable, if set, ' | ||
'otherwise it defaults to a path within out-dir.', | ||
'the value of the FLUTTER_LOGS_DIR environment variable, if set, ' | ||
'otherwise it defaults to a path within out-dir.', | ||
defaultsTo: Platform.environment['FLUTTER_LOGS_DIR'], | ||
); | ||
|
||
|
@@ -153,7 +159,10 @@ void main(List<String> args) async { | |
final String? contentsGolden = results['output-contents-golden'] as String?; | ||
final _ImpellerBackend? impellerBackend = _ImpellerBackend.tryParse(results['impeller-backend'] as String?); | ||
if (enableImpeller && impellerBackend == null) { | ||
panic(<String>['invalid graphics-backend', results['impeller-backend'] as String? ?? '<null>']); | ||
panic(<String>[ | ||
'invalid graphics-backend', | ||
results['impeller-backend'] as String? ?? '<null>' | ||
]); | ||
} | ||
final Directory logsDir = Directory(results['logs-dir'] as String? ?? join(outDir.path, 'scenario_app', 'logs')); | ||
final String? ndkStack = results['ndk-stack'] as String?; | ||
|
@@ -215,7 +224,10 @@ Future<void> _run({ | |
const ProcessManager pm = LocalProcessManager(); | ||
|
||
if (!outDir.existsSync()) { | ||
panic(<String>['out-dir does not exist: $outDir', 'make sure to build the selected engine variant']); | ||
panic(<String>[ | ||
'out-dir does not exist: $outDir', | ||
'make sure to build the selected engine variant' | ||
]); | ||
} | ||
|
||
if (!adb.existsSync()) { | ||
|
@@ -236,19 +248,25 @@ Future<void> _run({ | |
log('writing logs and screenshots to ${logsDir.path}'); | ||
|
||
if (!testApk.existsSync()) { | ||
panic(<String>['test apk does not exist: ${testApk.path}', 'make sure to build the selected engine variant']); | ||
panic(<String>[ | ||
'test apk does not exist: ${testApk.path}', | ||
'make sure to build the selected engine variant' | ||
]); | ||
} | ||
|
||
if (!appApk.existsSync()) { | ||
panic(<String>['app apk does not exist: ${appApk.path}', 'make sure to build the selected engine variant']); | ||
panic(<String>[ | ||
'app apk does not exist: ${appApk.path}', | ||
'make sure to build the selected engine variant' | ||
]); | ||
} | ||
|
||
// Start a TCP socket in the host, and forward it to the device that runs the tests. | ||
// This allows the test process to start a connection with the host, and write the bytes | ||
// for the screenshots. | ||
// On LUCI, the host uploads the screenshots to Skia Gold. | ||
SkiaGoldClient? skiaGoldClient; | ||
late ServerSocket server; | ||
late ServerSocket server; | ||
final List<Future<void>> pendingComparisons = <Future<void>>[]; | ||
await step('Starting server...', () async { | ||
server = await ServerSocket.bind(InternetAddress.anyIPv4, _tcpPort); | ||
|
@@ -259,7 +277,8 @@ Future<void> _run({ | |
if (verbose) { | ||
stdout.writeln('client connected ${client.remoteAddress.address}:${client.remotePort}'); | ||
} | ||
client.transform(const ScreenshotBlobTransformer()).listen((Screenshot screenshot) { | ||
client.transform(const ScreenshotBlobTransformer()).listen( | ||
(Screenshot screenshot) { | ||
final String fileName = screenshot.filename; | ||
final Uint8List fileContent = screenshot.fileContent; | ||
if (verbose) { | ||
|
@@ -277,18 +296,15 @@ Future<void> _run({ | |
} | ||
if (isSkiaGoldClientAvailable) { | ||
final Future<void> comparison = skiaGoldClient! | ||
.addImg(fileName, goldenFile, | ||
screenshotSize: screenshot.pixelCount) | ||
.catchError((dynamic err) { | ||
panic(<String>['skia gold comparison failed: $err']); | ||
}); | ||
.addImg(fileName, goldenFile, screenshotSize: screenshot.pixelCount) | ||
.catchError((dynamic err) { | ||
panic(<String>['skia gold comparison failed: $err']); | ||
}); | ||
pendingComparisons.add(comparison); | ||
} | ||
}, | ||
onError: (dynamic err) { | ||
}, onError: (dynamic err) { | ||
panic(<String>['error while receiving bytes: $err']); | ||
}, | ||
cancelOnError: true); | ||
}, cancelOnError: true); | ||
}); | ||
}); | ||
|
||
|
@@ -311,27 +327,26 @@ Future<void> _run({ | |
final (Future<int> logcatExitCode, Stream<String> logcatOutput) = getProcessStreams(logcatProcess); | ||
|
||
logcatProcessExitCode = logcatExitCode; | ||
String? filterToProcessId; | ||
|
||
logcatOutput.listen((String line) { | ||
// Always write to the full log. | ||
logcat.writeln(line); | ||
|
||
// Conditionally parse and write to stderr. | ||
final AdbLogLine? adbLogLine = AdbLogLine.tryParse(line); | ||
switch (adbLogLine?.process) { | ||
case null: | ||
break; | ||
case 'ActivityManager': | ||
// These are mostly noise, i.e. "D ActivityManager: freezing 24632 com.blah". | ||
if (adbLogLine!.severity == 'D') { | ||
break; | ||
} | ||
// TODO(matanlurey): Figure out why this isn't 'flutter.scenario' or similar. | ||
// Also, why is there two different names? | ||
case 'utter.scenario': | ||
case 'utter.scenarios': | ||
case 'flutter': | ||
case 'FlutterJNI': | ||
log('[adb] $line'); | ||
if (verbose || adbLogLine == null) { | ||
log(line); | ||
return; | ||
} | ||
|
||
filterToProcessId ??= adbLogLine.tryParseProcess(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the intention is no printing until we've parsed a process? It might be worth adding a comment here for that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, done. |
||
if (filterToProcessId != null) { | ||
adbLogLine.printFormatted(hideVerbose: !verbose, filterToProcessId: filterToProcessId!); | ||
} | ||
}, onError: (Object? err) { | ||
if (verbose) { | ||
logWarning('logcat stream error: $err'); | ||
} | ||
}); | ||
}); | ||
|
@@ -364,10 +379,7 @@ Future<void> _run({ | |
log('using dimensions: ${json.encode(dimensions)}'); | ||
skiaGoldClient = SkiaGoldClient( | ||
outDir, | ||
dimensions: <String, String>{ | ||
'AndroidAPILevel': connectedDeviceAPILevel, | ||
'GraphicsBackend': enableImpeller ? 'impeller-${impellerBackend!.name}' : 'skia', | ||
}, | ||
dimensions: dimensions, | ||
); | ||
}); | ||
|
||
|
@@ -412,11 +424,9 @@ Future<void> _run({ | |
'am', | ||
'instrument', | ||
'-w', | ||
if (smokeTestFullPath != null) | ||
'-e class $smokeTestFullPath', | ||
if (smokeTestFullPath != null) '-e class $smokeTestFullPath', | ||
'dev.flutter.scenarios.test/dev.flutter.TestRunner', | ||
if (enableImpeller) | ||
'-e enable-impeller', | ||
if (enableImpeller) '-e enable-impeller', | ||
if (impellerBackend != null) | ||
'-e impeller-backend ${impellerBackend.name}', | ||
]); | ||
|
@@ -465,22 +475,25 @@ Future<void> _run({ | |
final int exitCode = await pm.runAndForward(<String>[ | ||
adb.path, | ||
'reverse', | ||
'--remove', 'tcp:3000', | ||
'--remove', | ||
'tcp:3000', | ||
]); | ||
if (exitCode != 0) { | ||
panic(<String>['could not unforward port']); | ||
} | ||
}); | ||
|
||
await step('Uninstalling app APK...', () async { | ||
final int exitCode = await pm.runAndForward(<String>[adb.path, 'uninstall', 'dev.flutter.scenarios']); | ||
final int exitCode = await pm.runAndForward( | ||
<String>[adb.path, 'uninstall', 'dev.flutter.scenarios']); | ||
if (exitCode != 0) { | ||
panic(<String>['could not uninstall app apk']); | ||
} | ||
}); | ||
|
||
await step('Uninstalling test APK...', () async { | ||
final int exitCode = await pm.runAndForward(<String>[adb.path, 'uninstall', 'dev.flutter.scenarios.test']); | ||
final int exitCode = await pm.runAndForward( | ||
<String>[adb.path, 'uninstall', 'dev.flutter.scenarios.test']); | ||
if (exitCode != 0) { | ||
panic(<String>['could not uninstall app apk']); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this name really confusing. The gist is that it is the process id we are filtering for right
filterProcessId
seems more clear to me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree, cleaned it up a bit and added comments.