Skip to content

Conversation

@matanlurey
Copy link
Contributor

@matanlurey matanlurey commented Jul 23, 2024

Closes #152189.

I have next to no clue how to configure this to run on CI, so bear with me as I rediscover the wheel.

@github-actions github-actions bot added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. labels Jul 23, 2024
@matanlurey matanlurey marked this pull request as ready for review July 23, 2024 23:01
.ci.yaml Outdated
- .ci.yaml

- name: Linux_android_emu flutter_driver_android_test
recipe: devicelab/devicelab_drone
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the devicelab_drone recipe invokes the //dev/devicelab/bin/test_runner.dart entrypoint: https://flutter.googlesource.com/recipes/+/refs/heads/main/recipes/devicelab/devicelab_drone.py#44 and not the test.dart one. I think you will need to either:

  1. make your test a devicelab task; or
  2. make this target use the flutter/flutter_drone recipe, and set the shard property field, which is what test.dart uses for the key in that hash map you updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ... see. Let me try the latter and see what happens I guess.

}

@override
Future<NativeScreenshot> screenshot() async {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it's recreating a lot of the logic we've already added to flutter_tools. Have we considered communicating more between flutter_driver and FlutterDriverService so it can do the device poking it already knows how to do? I need to look more into the specifics of your proposal, but we have similar logic in so many places already in flutter/ it would be great to not have yet another that needs to be maintained by the platform teams (for example, the way screenshotting worked totally broke in iOS 2 years ago and we still haven't been able to totally replace it).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a valid critique of what is available so far (though, there will be lots of things that have no parallel in flutter_tools, such as navigating through applications or trimming memory).

We don't have, to my knowledge, a good model for sharing code between these different packages (for example, I'm also going to need to re-implement matchesGolden, which currently depends on dart:ui existing).

Some ideas:

  • Try to cobble together a flutter_common (?) package used by tools, test, driver
  • Consider having driver import from tool
  • Consider having tool import from driver

I'm not planning on immediately resolving this, but I am aware that this is duplication of at least some effort and will be a tax on platform teams (though, at least for Android, platform teams also need the functionality produced here, so maybe it's less of a tax and more of a trade?)

/cc @johnmccutchan for visibility.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out https://github.com/flutter/flutter/blob/main/packages/flutter_tools/lib/src/ios/core_devices.dart for the various data that is accessible host-side about an iOS device. The logic in that file would have to be duplicated over to flutter_driver unless there's a shared library, as you say, or unless the driver service is poking back to the host flutter_tool to delegate it to do these host-side operations.

  • Try to cobble together a flutter_common (?) package used by tools, test, driver

And devicelab harness (there's even tap() logic in there)

Future<List<String>> discoverDevices() async {
final List<String> output = (await eval(adbPath, <String>['devices', '-l']))

Future<void> shellExec(String command, List<String> arguments, { Map<String, String>? environment, bool silent = false }) async {
await adb(<String>['shell', command, ...arguments], environment: environment, silent: silent);

Future<void> home() async {
await shellExec('input', const <String>['keyevent', '3']);
}
/// Sends `KEYCODE_POWER` (26), which causes the device to toggle its mode
/// between awake and asleep.
@override
Future<void> togglePower() async {
await shellExec('input', const <String>['keyevent', '26']);
}
/// Unlocks the device by sending `KEYCODE_MENU` (82).
///
/// This only works when the device doesn't have a secure unlock pattern.
@override
Future<void> unlock() async {
await wakeUp();
await shellExec('input', const <String>['keyevent', '82']);
}
@override
Future<void> tap(int x, int y) async {
await shellExec('input', <String>['tap', '$x', '$y']);
}

Mostly the devicelab calls back to the tool to do things, like take a screenshot:

if (exitCode != 0 && !canFail) {
await _flutterScreenshot(workingDirectory: workingDirectory);
}

Future<void> _flutterScreenshot({ String? workingDirectory }) async {
try {
final Directory? dumpDirectory = hostAgent.dumpDirectory;
if (dumpDirectory == null) {
return;
}
// On command failure try uploading screenshot of failing command.
final String screenshotPath = path.join(
dumpDirectory.path,
'device-screenshot-${DateTime.now().toLocal().toIso8601String()}.png',
);
final String deviceId = (await devices.workingDevice).deviceId;
print('Taking screenshot of working device $deviceId at $screenshotPath');
final List<String> args = _flutterCommandArgs(
'screenshot',
<String>[
'--out',
screenshotPath,
'-d', deviceId,
],
);

I'm not planning on immediately resolving this

Figuring out if this code is going to be a duplicate of flutter_tools seems pretty important for where you start on the larger flutter_driver project. You'll have a lot more available if you start with the ways the tool can interact with a device than if you start from scratch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are super valuable references, thanks for sharing the code snippets!

Sorry, my comment about not resolving this is not self-serving - I'm actually not confident that this approach will work well enough (i.e. on our CI) where investing in this past a series of 1-off "engine validation" tests is an optimal approach, and I want to de-risk this (i.e. spend 1-2 weeks to ensure the next 1-2 months is well spent).

I do agree that, once the prototype is fleshed out (read: running on CI, and showing it's capable of catching the bugs we're writing this system for), it would be good to take a step back and likely sync with @jonahwilliams and @christopherfujino on de-layering/code-sharing - I just think it would be a mistake to do that as a priority while we have ~0 test coverage of critical systems like Android platform views.

(If anything, replacing the device-lab specific code seems like a no-brainer, since it's not even part of a production tool)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other words, I'd say the priorities roughly are:

  1. We can take and compare screenshots of Android platform views on CI, and the tests are stable and useful
  2. We de-duplicate code in dev/devicelab to help prove out this approach is good beyond the prototype tests
  3. We do a proof of concept of an iOS backend
  4. We de-duplicate code in flutter_tools

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chatted offline with Matan; for #4, creating a new //flutter/packages/_flutter_common package SGTM. cc @andrewkolos

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if a better name might be "flutter_target_control" instead of "flutter_common" (which could mean anything).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some other potential sources of duplications are the Dart CLI tools.

We should also look at the work we need to do to modularize platform support in flutter tools. It will result in a bunch of interfaces that abstract the device/target/build system and we can use these interfaces to avoid duplicated effort.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyways, these cleanups are outside the scope of this PR but I agree we need to rationalize this part of the system.

auto-submit bot pushed a commit to flutter/cocoon that referenced this pull request Jul 24, 2024
See flutter/flutter#152194 where I got befuddling error messages:

```txt
Unhandled exception:
Null check operator used on a null value
#0      DeviceLabTestOwner.getTestOwnership (package:cocoon_service/src/request_handlers/test_ownership.dart:60:59)
#1      getTestOwnership (package:cocoon_service/src/request_handlers/flaky_handler_utils.dart:301:20)
#2      validateOwnership (package:cocoon_service/src/foundation/utils.dart:225:27)
#3      remoteCheck (file:///b/s/w/ir/x/w/cocoon/app_dart/bin/validate_task_ownership.dart:31:40)
<asynchronous suspension>
#4      main (file:///b/s/w/ir/x/w/cocoon/app_dart/bin/validate_task_ownership.dart:63:23)
<asynchronous suspension>
```
Copy link
Contributor

@johnmccutchan johnmccutchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interface LGTM

@jmagman
Copy link
Member

jmagman commented Jul 24, 2024

Your test failure is from a PR that was reverted, you can rebase onto f55ab0e

@matanlurey
Copy link
Contributor Author

Filed #152257 to track a future "common" package.

@matanlurey matanlurey added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 24, 2024
@auto-submit auto-submit bot merged commit 0946192 into flutter:master Jul 24, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 26, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 26, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 26, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 26, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 27, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 27, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 28, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 28, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jul 29, 2024
Roll Flutter from 7d5c1c0 to 031dc3d (97 revisions)

flutter/flutter@7d5c1c0...031dc3d

2024-07-26 [email protected] Roll Flutter Engine from 342a42547822 to 354abf2800a0 (7 revisions) (flutter/flutter#152385)
2024-07-26 [email protected] Use more CORS headers for flutter run server (flutter/flutter#152249)
2024-07-26 [email protected] Manual roll Flutter Engine from 8714b54a87c0 to 342a42547822 (6 revisions) (flutter/flutter#152379)
2024-07-26 [email protected] feat: Add drag handle size to be configurable based on given size (flutter/flutter#152085)
2024-07-26 [email protected] Add and use an integration test with native(ADB) screenshots (flutter/flutter#152326)
2024-07-26 [email protected] Roll Packages from 19daf6f to 3d358d9 (4 revisions) (flutter/flutter#152372)
2024-07-26 [email protected] Add test for range_slider.0.dart (flutter/flutter#152152)
2024-07-26 [email protected] Introduce `TabBar.indicatorAnimation` to customize tab indicator animation (flutter/flutter#151746)
2024-07-26 [email protected] Roll Flutter Engine from 21629ece8b72 to 8714b54a87c0 (3 revisions) (flutter/flutter#152351)
2024-07-26 [email protected] Cleanup examples/api web load logic to latest (flutter/flutter#152349)
2024-07-26 [email protected] Adds a call to the `PlatformDispatcher` whenever the focus changes (flutter/flutter#151268)
2024-07-26 [email protected] Roll Flutter Engine from d665bf82dc32 to 21629ece8b72 (4 revisions) (flutter/flutter#152344)
2024-07-25 [email protected] `docImport`s for the widgets library (flutter/flutter#152339)
2024-07-25 [email protected] Set dart defines properly while in debug mode. (flutter/flutter#152262)
2024-07-25 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.25.13 to 3.25.14 (flutter/flutter#152342)
2024-07-25 [email protected] Roll Flutter Engine from 74785a771ae6 to d665bf82dc32 (2 revisions) (flutter/flutter#152340)
2024-07-25 [email protected] Cleanup InputDecoration.collapsed constructor (flutter/flutter#152165)
2024-07-25 [email protected] Add test for expansion_panel_list.expansion_panel_list_radio.0_test.dart (flutter/flutter#151730)
2024-07-25 [email protected] Roll Flutter Engine from f862a620cee4 to 74785a771ae6 (2 revisions) (flutter/flutter#152333)
2024-07-25 [email protected] Roll Packages from 1c319ac to 19daf6f (3 revisions) (flutter/flutter#152327)
2024-07-25 [email protected] Add a more typical / concrete example to IntrinsicHeight / IntrinsicWidth (flutter/flutter#152246)
2024-07-25 [email protected] Roll Flutter Engine from f47b4d8e145a to f862a620cee4 (1 revision) (flutter/flutter#152320)
2024-07-25 [email protected] Roll Flutter Engine from 74737820a8ee to f47b4d8e145a (7 revisions) (flutter/flutter#152314)
2024-07-25 [email protected] Flutter Web App: adds a11y semantic attributes to slider (flutter/flutter#151985)
2024-07-25 [email protected] Manual roll Flutter Engine from eb8fac2b1703 to 74737820a8ee (8 revisions) (flutter/flutter#152305)
2024-07-25 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Roll Flutter Engine from eb8fac2b1703 to a57655cccb55 (6 revisions) (#152293)" (flutter/flutter#152304)
2024-07-25 [email protected] Roll Flutter Engine from eb8fac2b1703 to a57655cccb55 (6 revisions) (flutter/flutter#152293)
2024-07-25 [email protected] Modify stepping integration test to accommodate new DDC async semantics. (flutter/flutter#152204)
2024-07-25 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Roll Flutter Engine from eb8fac2b1703 to e1259b86ba02 (2 revisions) (#152285)" (flutter/flutter#152289)
2024-07-25 [email protected] Update fake_codec.dart to use Future.value instead of SynchronousFuture (flutter/flutter#152182)
2024-07-25 [email protected] Roll Flutter Engine from eb8fac2b1703 to e1259b86ba02 (2 revisions) (flutter/flutter#152285)
2024-07-25 [email protected] Roll Flutter Engine from 4b952093cb99 to eb8fac2b1703 (3 revisions) (flutter/flutter#152278)
2024-07-24 [email protected] [CupertinoAlertDialog] Rewrite (flutter/flutter#150410)
2024-07-24 [email protected] Revert "Make `CupertinoRadio`'s `mouseCursor` a `WidgetStateProperty`" (flutter/flutter#152254)
2024-07-24 [email protected] Fix: A selectable's selection under the active selection should not be cleared on right-click (flutter/flutter#151851)
2024-07-24 [email protected] Marks Mac channels_integration_test to be flaky (flutter/flutter#151882)
2024-07-24 [email protected] Roll Flutter Engine from c2f489d783d6 to 4b952093cb99 (3 revisions) (flutter/flutter#152264)
2024-07-24 [email protected] added Semantics label to TextField with InputDecoration to let user kâ�¦ (flutter/flutter#151996)
2024-07-24 [email protected] feat: Add alignmentOffset to DropdownMenu (flutter/flutter#151731)
2024-07-24 [email protected] Roll Flutter Engine from 490576daf810 to c2f489d783d6 (6 revisions) (flutter/flutter#152260)
2024-07-24 [email protected] Scaffolding for `NativeDriver` and `AndroidNativeDriver` for taking screenshots using `adb`. (flutter/flutter#152194)
2024-07-24 [email protected] `widgets` docImport (flutter/flutter#152146)
2024-07-24 [email protected] Roll Flutter Engine from 3078f6a90e71 to 490576daf810 (1 revision) (flutter/flutter#152239)
2024-07-24 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Use more CORS headers for `flutter run` server (#152048)" (flutter/flutter#152248)
2024-07-24 [email protected] Use more CORS headers for `flutter run` server (flutter/flutter#152048)
2024-07-24 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Enable Swift Package Manager by default on master channel (#152049)" (flutter/flutter#152243)
...
TytaniumDev pushed a commit to TytaniumDev/flutter that referenced this pull request Aug 7, 2024
…creenshots using `adb`. (flutter#152194)

Closes flutter#152189.

I have next to no clue how to configure this to run on CI, so bear with me as I rediscover the wheel.
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
…creenshots using `adb`. (flutter#152194)

Closes flutter#152189.

I have next to no clue how to configure this to run on CI, so bear with me as I rediscover the wheel.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: tests "flutter test", flutter_test, or one of our tests autosubmit Merge PR when tree becomes green via auto submit App framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Take platform screenshots on Android

4 participants