|
| 1 | +// Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'dart:async' show Completer, StreamSubscription; |
| 6 | +import 'dart:io' show Directory, Process; |
| 7 | + |
| 8 | +import 'package:flutter_devicelab/framework/devices.dart' |
| 9 | + show Device, DeviceOperatingSystem, deviceOperatingSystem, devices; |
| 10 | +import 'package:flutter_devicelab/framework/framework.dart' show task; |
| 11 | +import 'package:flutter_devicelab/framework/task_result.dart' show TaskResult; |
| 12 | +import 'package:flutter_devicelab/framework/utils.dart' |
| 13 | + show dir, flutter, flutterDirectory, inDirectory, startFlutter; |
| 14 | +import 'package:path/path.dart' as path; |
| 15 | + |
| 16 | +Future<TaskResult> run() async { |
| 17 | + deviceOperatingSystem = DeviceOperatingSystem.android; |
| 18 | + final Device device = await devices.workingDevice; |
| 19 | + await device.unlock(); |
| 20 | + final Directory appDir = |
| 21 | + dir(path.join(flutterDirectory.path, 'examples/hello_world')); |
| 22 | + |
| 23 | + bool isUsingValidationLayers = false; |
| 24 | + bool hasValidationErrors = false; |
| 25 | + int impellerBackendCount = 0; |
| 26 | + final Completer<void> didReceiveBackendMessage = Completer<void>(); |
| 27 | + |
| 28 | + await inDirectory(appDir, () async { |
| 29 | + await flutter('packages', options: <String>['get']); |
| 30 | + |
| 31 | + final StreamSubscription<String> adb = device.logcat.listen( |
| 32 | + (String data) { |
| 33 | + if (data.contains('Using the Impeller rendering backend')) { |
| 34 | + // Sometimes more than one of these will be printed out if there is a |
| 35 | + // fallback. |
| 36 | + if (!didReceiveBackendMessage.isCompleted) { |
| 37 | + didReceiveBackendMessage.complete(); |
| 38 | + } |
| 39 | + impellerBackendCount += 1; |
| 40 | + } |
| 41 | + if (data.contains( |
| 42 | + 'Using the Impeller rendering backend (Vulkan with Validation Layers)')) { |
| 43 | + isUsingValidationLayers = true; |
| 44 | + } |
| 45 | + // "ImpellerValidationBreak" comes from the engine: |
| 46 | + // https://github.com/flutter/engine/blob/4160ebacdae2081d6f3160432f5f0dd87dbebec1/impeller/base/validation.cc#L40 |
| 47 | + if (data.contains('ImpellerValidationBreak')) { |
| 48 | + hasValidationErrors = true; |
| 49 | + } |
| 50 | + }, |
| 51 | + ); |
| 52 | + |
| 53 | + final Process process = await startFlutter( |
| 54 | + 'run', |
| 55 | + options: <String>[ |
| 56 | + '--enable-impeller', |
| 57 | + '-d', |
| 58 | + device.deviceId, |
| 59 | + ], |
| 60 | + ); |
| 61 | + |
| 62 | + await didReceiveBackendMessage.future; |
| 63 | + // Since we are waiting for the lack of errors, there is no determinate |
| 64 | + // amount of time we can wait. |
| 65 | + await Future<void>.delayed(const Duration(seconds: 30)); |
| 66 | + process.stdin.write('q'); |
| 67 | + await adb.cancel(); |
| 68 | + }); |
| 69 | + |
| 70 | + if (!isUsingValidationLayers || impellerBackendCount != 1) { |
| 71 | + return TaskResult.failure('Not using Vulkan validation layers.'); |
| 72 | + } |
| 73 | + if (hasValidationErrors){ |
| 74 | + return TaskResult.failure('Impeller validation errors detected.'); |
| 75 | + } |
| 76 | + return TaskResult.success(null); |
| 77 | +} |
| 78 | + |
| 79 | +Future<void> main() async { |
| 80 | + await task(run); |
| 81 | +} |
0 commit comments