Skip to content
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

Refactor how SkiaGoldClient is used #144047

Closed
matanlurey opened this issue Feb 23, 2024 · 5 comments
Closed

Refactor how SkiaGoldClient is used #144047

matanlurey opened this issue Feb 23, 2024 · 5 comments
Labels
c: tech-debt Technical debt, code quality, testing, etc. e: scenario-app The `testing/scenario_app` fixture in the engine engine flutter/engine repository. See also e: labels. P3 Issues that are less important to the Flutter project platform-android Android applications specifically team-engine Owned by Engine team triaged-engine Triaged by Engine team

Comments

@matanlurey
Copy link
Contributor

This is some of the most confusing/scariest code in the Android scenario_app runner:

// 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;
final List<Future<void>> pendingComparisons = <Future<void>>[];
await step('Starting server...', () async {
  server = await ServerSocket.bind(InternetAddress.anyIPv4, _tcpPort);
  if (verbose) {
    stdout.writeln('listening on host ${server.address.address}:${server.port}');
  }
  server.listen((Socket client) {
    if (verbose) {
      stdout.writeln('client connected ${client.remoteAddress.address}:${client.remotePort}');
    }
    client.transform(const ScreenshotBlobTransformer()).listen((Screenshot screenshot) {
      final String fileName = screenshot.filename;
      final Uint8List fileContent = screenshot.fileContent;
      if (verbose) {
        log('host received ${fileContent.lengthInBytes} bytes for screenshot `$fileName`');
      }
      assert(skiaGoldClient != null, 'expected Skia Gold client');
      late File goldenFile;
      try {
        goldenFile = File(join(screenshotPath, fileName))..writeAsBytesSync(fileContent, flush: true);
      } on FileSystemException catch (err) {
        panic(<String>['failed to create screenshot $fileName: $err']);
      }
      if (verbose) {
        log('wrote ${goldenFile.absolute.path}');
      }
      if (isSkiaGoldClientAvailable) {
        final Future<void> comparison = skiaGoldClient!
          .addImg(fileName, goldenFile,
                  screenshotSize: screenshot.pixelCount)
          .catchError((dynamic err) {
            panic(<String>['skia gold comparison failed: $err']);
          });
        pendingComparisons.add(comparison);
      }
    },
    onError: (dynamic err) {
      panic(<String>['error while receiving bytes: $err']);
    },
    cancelOnError: true);
  });
});
@matanlurey matanlurey added platform-android Android applications specifically engine flutter/engine repository. See also e: labels. P1 High-priority issues at the top of the work list c: tech-debt Technical debt, code quality, testing, etc. fyi-android For the attention of Android platform team team-engine Owned by Engine team e: scenario-app The `testing/scenario_app` fixture in the engine labels Feb 23, 2024
@jonahwilliams
Copy link
Member

If we could save the files on device, then we could use something like adb pull. I'm not actually sure if that code ends up being simpler though, since we may need to request storage permission to do so.

@matanlurey
Copy link
Contributor Author

Interesting. I'm down for whatever is simpler, let's chat (maybe include @gaaclarke) next week!

@matanlurey matanlurey added P3 Issues that are less important to the Flutter project and removed P1 High-priority issues at the top of the work list labels Feb 23, 2024
auto-submit bot pushed a commit to flutter/engine that referenced this issue Feb 23, 2024
…#50922)

Closes flutter/flutter#144045.

There is still more work I want to do, like pulling args parsing into it's own class, and potentially cleanup the [golden file collection](flutter/flutter#144047), but those seem reasonable for future (lower priority) PRs.
@jonahwilliams jonahwilliams added the triaged-engine Triaged by Engine team label Feb 26, 2024
@reidbaker reidbaker added the triaged-android Triaged by Android platform team label Mar 14, 2024
@reidbaker
Copy link
Contributor

Do we need to be the ones saving the files though? Can we have adb do the screenshot logic? adb exec-out screencap -p

@flutter-triage-bot flutter-triage-bot bot removed fyi-android For the attention of Android platform team triaged-android Triaged by Android platform team labels Mar 14, 2024
@matanlurey
Copy link
Contributor Author

Do we need to be the ones saving the files though? Can we have adb do the screenshot logic? adb exec-out screencap -p

This is a good question. I had an informal chat with @jonahwilliams about this, /cc @gaaclarke.

If we only ever take screenshots at the end of a test, and it the tests were declarative in some way, we could entirely rely on taking a single adb exec-out screenpap -p at the end, and vastly simplify how we're doing things. However, in practice, we don't have the mechanisms to indicate that, and we have an imperative screenshot API.

Another option would be adding some sort of channel back and forth, so that tests could indicate to the runner to take a screenshot. In other words, ScreenshotUtil.capture() would send a message to the runner, which would use ADB on it's behalf, and so on.

That all being said, the current workflow (a) works and (b) seems to be working well enough.

I'll close this as unplanned for now - any of you feel free to re-open if we should re-consider.

@matanlurey matanlurey closed this as not planned Won't fix, can't repro, duplicate, stale Mar 14, 2024
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: tech-debt Technical debt, code quality, testing, etc. e: scenario-app The `testing/scenario_app` fixture in the engine engine flutter/engine repository. See also e: labels. P3 Issues that are less important to the Flutter project platform-android Android applications specifically team-engine Owned by Engine team triaged-engine Triaged by Engine team
Projects
None yet
Development

No branches or pull requests

3 participants