[fuchsia] Fix tests; remove fuchsia dart SDK deps (flutter/engine#43461)

Dart is being removed from the Fuchsia SDK, so remove references to it
here.

Also remove references to workstation_eng and replace with terminal.
workstation_eng is no longer a thing.
This commit is contained in:
David Worsham
2023-07-08 09:37:34 +10:00
committed by GitHub
parent ea932582ff
commit b400037017
48 changed files with 890 additions and 876 deletions

View File

@@ -282,6 +282,7 @@
../../../flutter/shell/platform/fuchsia/dart_runner/.gitignore
../../../flutter/shell/platform/fuchsia/dart_runner/README.md
../../../flutter/shell/platform/fuchsia/dart_runner/embedder/pubspec.yaml
../../../flutter/shell/platform/fuchsia/dart_runner/fidl/meta.json
../../../flutter/shell/platform/fuchsia/dart_runner/kernel/libraries.json
../../../flutter/shell/platform/fuchsia/dart_runner/kernel/libraries.yaml
../../../flutter/shell/platform/fuchsia/dart_runner/tests

View File

@@ -2886,6 +2886,7 @@ ORIGIN: ../../../flutter/shell/platform/fuchsia/dart_runner/embedder/shim.dart +
ORIGIN: ../../../flutter/shell/platform/fuchsia/dart_runner/embedder/snapshot.cc.tmpl + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/fuchsia/dart_runner/embedder/snapshot.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/fuchsia/dart_runner/embedder/snapshot.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/fuchsia/dart_runner/fidl/echo.fidl + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/fuchsia/dart_runner/logging.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/fuchsia/dart_runner/main.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/fuchsia/dart_runner/meta/common.shard.cml + ../../../flutter/LICENSE
@@ -5588,6 +5589,7 @@ FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/embedder/shim.dart
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/embedder/snapshot.cc.tmpl
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/embedder/snapshot.dart
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/embedder/snapshot.h
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/fidl/echo.fidl
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/logging.h
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/main.cc
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/meta/common.shard.cml

View File

@@ -90,6 +90,7 @@ if (enable_unittests) {
testonly = true
deps = [
"dart-pkg/zircon:tests",
"dart_runner:tests",
"flutter:tests",
]

View File

@@ -4,6 +4,9 @@
import("//build/fuchsia/sdk.gni")
import("//flutter/testing/testing.gni")
import("//flutter/tools/fuchsia/dart/dart_library.gni")
import("//flutter/tools/fuchsia/flutter/flutter_component.gni")
import("//flutter/tools/fuchsia/gn-sdk/package.gni")
config("zircon_config") {
include_dirs = [ "." ]
@@ -37,9 +40,54 @@ source_set("zircon") {
]
}
dart_library("zircon_lib") {
testonly = true
package_name = "zircon"
language_version = "2.12"
source_dir = "lib"
sources = [
"src/handle.dart",
"src/handle_disposition.dart",
"src/handle_waiter.dart",
"src/init.dart",
"src/system.dart",
"src/zd_channel.dart",
"src/zd_handle.dart",
"zircon.dart",
]
}
dart_library("zircon_tests_lib") {
testonly = true
package_name = "zircon_tests"
language_version = "2.12"
source_dir = "."
package_root = "test"
sources = [ "zircon_tests.dart" ]
deps = [ "//flutter/shell/platform/fuchsia/dart:litetest" ]
}
flutter_component("zircon_tests_component") {
testonly = true
main_package = "zircon_tests"
component_name = "zircon_tests"
main_dart = "zircon_tests.dart"
manifest = rebase_path("test/meta/zircon_tests.cml")
deps = [ ":zircon_tests_lib" ]
}
fuchsia_package("zircon_tests_package") {
testonly = true
package_name = "zircon_tests"
deps = [ ":zircon_tests_component" ]
}
if (enable_unittests) {
source_set("test") {
source_set("tests") {
testonly = true
deps = [ "test" ]
deps = [ ":zircon_tests_package" ]
}
}

View File

@@ -1,60 +0,0 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/fuchsia/sdk.gni")
import("//flutter/tools/fuchsia/dart/dart_library.gni")
import("//flutter/tools/fuchsia/flutter/flutter_component.gni")
import("//flutter/tools/fuchsia/gn-sdk/package.gni")
dart_library("dart_library") {
testonly = true
package_name = "channel_test"
language_version = "2.12"
source_dir = "."
sources = [
"channel_test.dart",
"eventpair_test.dart",
"handle_disposition_test.dart",
"handle_test.dart",
"socket_test.dart",
"vmo_test.dart",
]
deps = [
"//flutter/shell/platform/fuchsia/dart:litetest",
"//flutter/tools/fuchsia/dart:zircon",
]
}
flutter_component("channel_test_flutter_component") {
testonly = true
main_package = "channel_test"
component_name = "channel_test"
main_dart = "channel_test.dart"
manifest = rebase_path("meta/channel_test.cml")
deps = [ ":dart_library" ]
}
# TODO(richkadel): The target name is set differently compared to fuchsia.git's flutter_app().
# Unlike in fuchsia.git's version of fuchsia_component, the Fuchsia GN SDK
# version passes the component name to fuchsia_component via it's target_name only.
# GN SDK's fuchsia_component doesn't have a `component_name` argument! So I'm forced to set
# the component name via "target_name". This is a problem in fuchsia_package, which uses
# the target_name to name the fuchsia_pm_tool target, creating duplicate target IDs!
# So I have to change the fuchsia_package name to something that is NOT the component name,
# and then set the package_name (which fuchsia_package does support).
fuchsia_package("channel_test_package") {
testonly = true
package_name = "channel_test"
deps = [ ":channel_test_flutter_component" ]
}
group("test") {
testonly = true
deps = [ ":channel_test_package" ]
}

View File

@@ -1,241 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
import 'package:litetest/litetest.dart';
import 'package:zircon/zircon.dart';
/// Helper method to turn a [String] into a [ByteData] containing the
/// text of the string encoded as UTF-8.
ByteData utf8Bytes(final String text) {
return ByteData.view(Uint8List.fromList(utf8.encode(text)).buffer);
}
void main() {
test('create channel', () {
final HandlePairResult pair = System.channelCreate();
expect(pair.status, equals(ZX.OK));
expect(pair.first.isValid, isTrue);
expect(pair.second.isValid, isTrue);
});
test('[ffi] create channel', () {
final ZDChannel? channel = ZDChannel.create();
expect(channel, isNotNull);
final ZDHandlePair pair = channel!.handlePair;
expect(pair.left.isValid(), isTrue);
expect(pair.right.isValid(), isTrue);
});
test('close channel', () {
final HandlePairResult pair = System.channelCreate();
expect(pair.first.close(), equals(0));
expect(pair.first.isValid, isFalse);
expect(pair.second.isValid, isTrue);
expect(System.channelWrite(pair.first, ByteData(1), <Handle>[]),
equals(ZX.ERR_BAD_HANDLE));
expect(System.channelWrite(pair.second, ByteData(1), <Handle>[]),
equals(ZX.ERR_PEER_CLOSED));
});
test('[ffi] close channel', () {
final ZDChannel? channel = ZDChannel.create();
final ZDHandlePair pair = channel!.handlePair;
expect(pair.left.close(), isTrue);
expect(pair.left.isValid, isFalse);
expect(pair.right.isValid, isTrue);
expect(channel.writeLeft(ByteData(1), <ZDHandle>[]),
equals(ZX.ERR_BAD_HANDLE));
expect(channel.writeRight(ByteData(1), <ZDHandle>[]),
equals(ZX.ERR_PEER_CLOSED));
});
test('channel bytes', () {
final HandlePairResult pair = System.channelCreate();
// When no data is available, ZX.ERR_SHOULD_WAIT is returned.
expect(System.channelQueryAndRead(pair.second).status,
equals(ZX.ERR_SHOULD_WAIT));
// Write bytes.
final ByteData data = utf8Bytes('Hello, world');
final int status = System.channelWrite(pair.first, data, <Handle>[]);
expect(status, equals(ZX.OK));
// Read bytes.
final ReadResult readResult = System.channelQueryAndRead(pair.second);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals(data.lengthInBytes));
expect(readResult.bytes.lengthInBytes, equals(data.lengthInBytes));
expect(readResult.bytesAsUTF8String(), equals('Hello, world'));
expect(readResult.handles.length, equals(0));
});
test('channel handles', () {
final HandlePairResult pair = System.channelCreate();
final ByteData data = utf8Bytes('');
final HandlePairResult eventPair = System.eventpairCreate();
final int status =
System.channelWrite(pair.first, data, <Handle>[eventPair.first]);
expect(status, equals(ZX.OK));
expect(eventPair.first.isValid, isFalse);
final ReadResult readResult = System.channelQueryAndRead(pair.second);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals(0));
expect(readResult.bytes.lengthInBytes, equals(0));
expect(readResult.bytesAsUTF8String(), equals(''));
expect(readResult.handles.length, equals(1));
expect(readResult.handles[0].isValid, isTrue);
});
group('etc functions', () {
test('moved handle', () {
final HandlePairResult pair = System.channelCreate();
final ByteData data = utf8Bytes('');
final HandlePairResult transferred = System.channelCreate();
final HandleDisposition disposition = HandleDisposition(ZX.HANDLE_OP_MOVE,
transferred.first, ZX.OBJ_TYPE_CHANNEL, ZX.RIGHTS_IO);
final int status = System.channelWriteEtc(
pair.first, data, <HandleDisposition>[disposition]);
expect(status, equals(ZX.OK));
expect(disposition.result, equals(ZX.OK));
expect(transferred.first.isValid, isFalse);
final ReadEtcResult readResult =
System.channelQueryAndReadEtc(pair.second);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals(0));
expect(readResult.bytes.lengthInBytes, equals(0));
expect(readResult.bytesAsUTF8String(), equals(''));
expect(readResult.handleInfos.length, equals(1));
final HandleInfo handleInfo = readResult.handleInfos[0];
expect(handleInfo.handle.isValid, isTrue);
expect(handleInfo.type, equals(ZX.OBJ_TYPE_CHANNEL));
expect(handleInfo.rights, equals(ZX.RIGHTS_IO));
});
test('copied handle', () {
final HandlePairResult pair = System.channelCreate();
final ByteData data = utf8Bytes('');
final HandleResult vmo = System.vmoCreate(0);
final HandleDisposition disposition = HandleDisposition(
ZX.HANDLE_OP_DUPLICATE,
vmo.handle,
ZX.OBJ_TYPE_VMO,
ZX.RIGHT_SAME_RIGHTS);
final int status = System.channelWriteEtc(
pair.first, data, <HandleDisposition>[disposition]);
expect(status, equals(ZX.OK));
expect(disposition.result, equals(ZX.OK));
expect(vmo.handle.isValid, isTrue);
final ReadEtcResult readResult =
System.channelQueryAndReadEtc(pair.second);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals(0));
expect(readResult.bytes.lengthInBytes, equals(0));
expect(readResult.bytesAsUTF8String(), equals(''));
expect(readResult.handleInfos.length, equals(1));
final HandleInfo handleInfo = readResult.handleInfos[0];
expect(handleInfo.handle.isValid, isTrue);
expect(handleInfo.type, equals(ZX.OBJ_TYPE_VMO));
expect(handleInfo.rights, equals(ZX.DEFAULT_VMO_RIGHTS));
});
test('closed handle should error', () {
final HandlePairResult pair = System.channelCreate();
final ByteData data = utf8Bytes('');
final HandlePairResult closed = System.channelCreate();
final HandleDisposition disposition = HandleDisposition(ZX.HANDLE_OP_MOVE,
closed.first, ZX.OBJ_TYPE_CHANNEL, ZX.RIGHT_SAME_RIGHTS);
closed.first.close();
final int status = System.channelWriteEtc(
pair.first, data, <HandleDisposition>[disposition]);
expect(status, equals(ZX.ERR_BAD_HANDLE));
expect(disposition.result, equals(ZX.ERR_BAD_HANDLE));
expect(closed.first.isValid, isFalse);
final ReadEtcResult readResult =
System.channelQueryAndReadEtc(pair.second);
expect(readResult.status, equals(ZX.ERR_SHOULD_WAIT));
});
test('multiple handles', () {
final HandlePairResult pair = System.channelCreate();
final ByteData data = utf8Bytes('');
final HandlePairResult transferred = System.channelCreate();
final HandleResult vmo = System.vmoCreate(0);
final List<HandleDisposition> dispositions = [
HandleDisposition(ZX.HANDLE_OP_MOVE, transferred.first,
ZX.OBJ_TYPE_CHANNEL, ZX.RIGHTS_IO),
HandleDisposition(ZX.HANDLE_OP_DUPLICATE, vmo.handle, ZX.OBJ_TYPE_VMO,
ZX.RIGHT_SAME_RIGHTS)
];
final int status = System.channelWriteEtc(pair.first, data, dispositions);
expect(status, equals(ZX.OK));
expect(dispositions[0].result, equals(ZX.OK));
expect(dispositions[1].result, equals(ZX.OK));
expect(transferred.first.isValid, isFalse);
expect(vmo.handle.isValid, isTrue);
final ReadEtcResult readResult =
System.channelQueryAndReadEtc(pair.second);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals(0));
expect(readResult.bytes.lengthInBytes, equals(0));
expect(readResult.bytesAsUTF8String(), equals(''));
expect(readResult.handleInfos.length, equals(2));
final HandleInfo handleInfo = readResult.handleInfos[0];
expect(handleInfo.handle.isValid, isTrue);
expect(handleInfo.type, equals(ZX.OBJ_TYPE_CHANNEL));
expect(handleInfo.rights, equals(ZX.RIGHTS_IO));
final HandleInfo vmoInfo = readResult.handleInfos[1];
expect(vmoInfo.handle.isValid, isTrue);
expect(vmoInfo.type, equals(ZX.OBJ_TYPE_VMO));
expect(vmoInfo.rights, equals(ZX.DEFAULT_VMO_RIGHTS));
});
});
test('async wait channel read', () async {
final HandlePairResult pair = System.channelCreate();
final Completer<List<int>> completer = Completer<List<int>>();
pair.first.asyncWait(ZX.CHANNEL_READABLE, (int status, int pending) {
completer.complete(<int>[status, pending]);
});
expect(completer.isCompleted, isFalse);
System.channelWrite(pair.second, utf8Bytes('Hi'), <Handle>[]);
final List<int> result = await completer.future;
expect(result[0], equals(ZX.OK)); // status
expect(result[1] & ZX.CHANNEL_READABLE,
equals(ZX.CHANNEL_READABLE)); // pending
});
test('async wait channel closed', () async {
final HandlePairResult pair = System.channelCreate();
final Completer<int> completer = Completer<int>();
pair.first.asyncWait(ZX.CHANNEL_PEER_CLOSED, (int status, int pending) {
completer.complete(status);
});
expect(completer.isCompleted, isFalse);
pair.second.close();
final int status = await completer.future;
expect(status, equals(ZX.OK));
});
}

View File

@@ -1,53 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:test/test.dart';
import 'package:zircon/zircon.dart';
void main() {
group('eventpair: ', () {
test('create', () {
final HandlePairResult pair = System.eventpairCreate();
expect(pair.status, equals(ZX.OK));
expect(pair.first.isValid, isTrue);
expect(pair.second.isValid, isTrue);
});
test('duplicate', () {
final HandlePairResult pair = System.eventpairCreate();
expect(pair.status, equals(ZX.OK));
expect(pair.first.isValid, isTrue);
expect(pair.second.isValid, isTrue);
expect(pair.first.duplicate(ZX.RIGHT_SAME_RIGHTS).isValid, isTrue);
expect(pair.second.duplicate(ZX.RIGHT_SAME_RIGHTS).isValid, isTrue);
});
test('close', () {
final HandlePairResult pair = System.eventpairCreate();
expect(pair.first.close(), equals(0));
expect(pair.first.isValid, isFalse);
expect(pair.second.isValid, isTrue);
expect(pair.second.close(), equals(0));
expect(pair.second.isValid, isFalse);
});
test('async wait peer closed', () async {
final HandlePairResult pair = System.eventpairCreate();
final Completer<int> completer = Completer<int>();
pair.first.asyncWait(EventPair.PEER_CLOSED, (int status, int pending) {
completer.complete(status);
});
expect(completer.isCompleted, isFalse);
pair.second.close();
final int status = await completer.future;
expect(status, equals(ZX.OK));
});
});
}

View File

@@ -1,18 +0,0 @@
// Copyright 2021 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:test/test.dart';
import 'package:zircon/zircon.dart';
void main() {
test('store the disposition arguments correctly', () {
final Handle handle = System.channelCreate().first;
final HandleDisposition disposition = HandleDisposition(1, handle, 2, 3);
expect(disposition.operation, equals(1));
expect(disposition.handle, equals(handle));
expect(disposition.type, equals(2));
expect(disposition.rights, equals(3));
expect(disposition.result, equals(ZX.OK));
});
}

View File

@@ -1,168 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:convert';
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:zircon/zircon.dart';
/// Helper method to turn a [String] into a [ByteData] containing the
/// text of the string encoded as UTF-8.
ByteData utf8Bytes(final String text) {
return ByteData.view(Uint8List.fromList(utf8.encode(text)).buffer);
}
void main() {
group('duplicated handle', () {
test('create and duplicate handles', () {
final HandlePairResult pair = System.eventpairCreate();
expect(pair.status, equals(ZX.OK));
expect(pair.first.isValid, isTrue);
expect(pair.second.isValid, isTrue);
final Handle duplicate = pair.first.duplicate(ZX.RIGHT_SAME_RIGHTS);
expect(duplicate.isValid, isTrue);
final Handle failedDuplicate = pair.first.duplicate(-1);
expect(failedDuplicate.isValid, isFalse);
});
test('failure invalid rights', () {
final HandleResult vmo = System.vmoCreate(0);
expect(vmo.status, equals(ZX.OK));
final Handle failedDuplicate = vmo.handle.duplicate(-1);
expect(failedDuplicate.isValid, isFalse);
expect(vmo.handle.isValid, isTrue);
});
test('failure invalid handle', () {
final Handle handle = Handle.invalid();
final Handle duplicate = handle.duplicate(ZX.RIGHT_SAME_RIGHTS);
expect(duplicate.isValid, isFalse);
});
test('duplicated handle should have same koid', () {
final HandlePairResult pair = System.eventpairCreate();
expect(pair.status, equals(ZX.OK));
expect(pair.first.isValid, isTrue);
expect(pair.second.isValid, isTrue);
final Handle duplicate = pair.first.duplicate(ZX.RIGHT_SAME_RIGHTS);
expect(duplicate.isValid, isTrue);
expect(pair.first.koid, duplicate.koid);
});
// TODO(fxbug.dev/77599): Simplify once zx_object_get_info is available.
test('reduced rights', () {
// Set up handle.
final HandleResult vmo = System.vmoCreate(2);
expect(vmo.status, equals(ZX.OK));
// Duplicate the first handle.
final Handle duplicate = vmo.handle.duplicate(ZX.RIGHTS_BASIC);
expect(duplicate.isValid, isTrue);
// Write bytes to the original handle.
final ByteData data1 = utf8Bytes('a');
final int status1 = System.vmoWrite(vmo.handle, 0, data1);
expect(status1, equals(ZX.OK));
// Write bytes to the duplicated handle.
final ByteData data2 = utf8Bytes('b');
final int status2 = System.vmoWrite(duplicate, 1, data2);
expect(status2, equals(ZX.ERR_ACCESS_DENIED));
// Read bytes.
final ReadResult readResult = System.vmoRead(vmo.handle, 0, 2);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals(2));
expect(readResult.bytes.lengthInBytes, equals(2));
expect(readResult.bytesAsUTF8String(), equals('a\x00'));
});
});
group('replaced handle', () {
test('create and replace handles', () {
final HandlePairResult pair = System.eventpairCreate();
expect(pair.status, equals(ZX.OK));
expect(pair.first.isValid, isTrue);
expect(pair.second.isValid, isTrue);
final Handle replaced = pair.first.replace(ZX.RIGHT_SAME_RIGHTS);
expect(replaced.isValid, isTrue);
expect(pair.first.isValid, isFalse);
});
test('failure invalid rights', () {
final HandleResult vmo = System.vmoCreate(0);
expect(vmo.status, equals(ZX.OK));
final Handle failedDuplicate = vmo.handle.replace(-1);
expect(failedDuplicate.isValid, isFalse);
expect(vmo.handle.isValid, isFalse);
});
test('failure invalid handle', () {
final Handle handle = Handle.invalid();
final Handle replaced = handle.replace(ZX.RIGHT_SAME_RIGHTS);
expect(handle.isValid, isFalse);
expect(replaced.isValid, isFalse);
});
test('transferred handle should have same koid', () {
final HandlePairResult pair = System.eventpairCreate();
expect(pair.status, equals(ZX.OK));
expect(pair.first.isValid, isTrue);
expect(pair.second.isValid, isTrue);
final int koid = pair.first.koid;
final Handle replaced = pair.first.replace(ZX.RIGHT_SAME_RIGHTS);
expect(replaced.isValid, isTrue);
expect(koid, replaced.koid);
});
// TODO(fxbug.dev/77599): Simplify once zx_object_get_info is available.
test('reduced rights', () {
// Set up handle.
final HandleResult vmo = System.vmoCreate(2);
expect(vmo.status, equals(ZX.OK));
// Replace the first handle.
final Handle duplicate =
vmo.handle.replace(ZX.RIGHTS_BASIC | ZX.RIGHT_READ);
expect(duplicate.isValid, isTrue);
// Write bytes to the original handle.
final ByteData data1 = utf8Bytes('a');
final int status1 = System.vmoWrite(vmo.handle, 0, data1);
expect(status1, equals(ZX.ERR_BAD_HANDLE));
// Write bytes to the duplicated handle.
final ByteData data2 = utf8Bytes('b');
final int status2 = System.vmoWrite(duplicate, 1, data2);
expect(status2, equals(ZX.ERR_ACCESS_DENIED));
// Read bytes.
final ReadResult readResult = System.vmoRead(duplicate, 0, 2);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals(2));
expect(readResult.bytes.lengthInBytes, equals(2));
expect(readResult.bytesAsUTF8String(), equals('\x00\x00'));
});
});
test('cache koid and invalidate', () {
final HandleResult vmo = System.vmoCreate(0);
expect(vmo.status, equals(ZX.OK));
int originalKoid = vmo.handle.koid;
expect(originalKoid, isNot(equals(ZX.KOID_INVALID)));
// Cached koid should be same value.
expect(originalKoid, equals(vmo.handle.koid));
vmo.handle.close();
// koid should be invalidated.
expect(vmo.handle.koid, equals(ZX.KOID_INVALID));
});
}

View File

@@ -1,5 +0,0 @@
{
program: {
data: "data/channel_test",
},
}

View File

@@ -0,0 +1,6 @@
{
program: {
data: "data/zircon_tests",
runner: "dart_jit_runner",
},
}

View File

@@ -1,129 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:zircon/zircon.dart';
/// Helper method to turn a [String] into a [ByteData] containing the
/// text of the string encoded as UTF-8.
ByteData utf8Bytes(final String text) {
return ByteData.view(Uint8List.fromList(utf8.encode(text)).buffer);
}
void main() {
// NOTE: This only tests stream sockets.
// We should add tests for datagram sockets.
test('create socket', () {
final HandlePairResult pair = System.socketCreate();
expect(pair.status, equals(ZX.OK));
expect(pair.first.isValid, isTrue);
expect(pair.second.isValid, isTrue);
});
test('close socket', () {
final HandlePairResult pair = System.socketCreate();
expect(pair.first.close(), equals(0));
expect(pair.first.isValid, isFalse);
expect(pair.second.isValid, isTrue);
final WriteResult firstResult =
System.socketWrite(pair.first, ByteData(1), 0);
expect(firstResult.status, equals(ZX.ERR_BAD_HANDLE));
final WriteResult secondResult =
System.socketWrite(pair.second, ByteData(1), 0);
expect(secondResult.status, equals(ZX.ERR_PEER_CLOSED));
});
test('read write socket', () {
final HandlePairResult pair = System.socketCreate();
// When no data is available, ZX.ERR_SHOULD_WAIT is returned.
expect(
System.socketRead(pair.second, 1).status, equals(ZX.ERR_SHOULD_WAIT));
final ByteData data = utf8Bytes('Hello, world');
final WriteResult writeResult = System.socketWrite(pair.first, data, 0);
expect(writeResult.status, equals(ZX.OK));
final ReadResult readResult =
System.socketRead(pair.second, data.lengthInBytes);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals(data.lengthInBytes));
expect(readResult.bytes.lengthInBytes, equals(data.lengthInBytes));
expect(readResult.bytesAsUTF8String(), equals('Hello, world'));
});
test('partial read socket', () {
final HandlePairResult pair = System.socketCreate();
final ByteData data = utf8Bytes('Hello, world');
final WriteResult writeResult = System.socketWrite(pair.first, data, 0);
expect(writeResult.status, equals(ZX.OK));
const int shortLength = 'Hello'.length;
final ReadResult shortReadResult =
System.socketRead(pair.second, shortLength);
expect(shortReadResult.status, equals(ZX.OK));
expect(shortReadResult.numBytes, equals(shortLength));
expect(shortReadResult.bytes.lengthInBytes, equals(shortLength));
expect(shortReadResult.bytesAsUTF8String(), equals('Hello'));
final int longLength = data.lengthInBytes * 2;
final ReadResult longReadResult =
System.socketRead(pair.second, longLength);
expect(longReadResult.status, equals(ZX.OK));
expect(longReadResult.numBytes, equals(data.lengthInBytes - shortLength));
expect(longReadResult.bytes.lengthInBytes, equals(longLength));
expect(longReadResult.bytesAsUTF8String(), equals(', world'));
});
test('partial write socket', () {
final HandlePairResult pair = System.socketCreate();
final WriteResult writeResult1 =
System.socketWrite(pair.first, utf8Bytes('Hello, '), 0);
expect(writeResult1.status, equals(ZX.OK));
final WriteResult writeResult2 =
System.socketWrite(pair.first, utf8Bytes('world'), 0);
expect(writeResult2.status, equals(ZX.OK));
final ReadResult readResult = System.socketRead(pair.second, 100);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals('Hello, world'.length));
expect(readResult.bytes.lengthInBytes, equals(100));
expect(readResult.bytesAsUTF8String(), equals('Hello, world'));
});
test('async wait socket read', () async {
final HandlePairResult pair = System.socketCreate();
final Completer<int> completer = Completer<int>();
pair.first.asyncWait(ZX.SOCKET_READABLE, (int status, int pending) {
completer.complete(status);
});
expect(completer.isCompleted, isFalse);
System.socketWrite(pair.second, utf8Bytes('Hi'), 0);
final int status = await completer.future;
expect(status, equals(ZX.OK));
});
test('async wait socket closed', () async {
final HandlePairResult pair = System.socketCreate();
final Completer<int> completer = Completer<int>();
pair.first.asyncWait(ZX.SOCKET_PEER_CLOSED, (int status, int pending) {
completer.complete(status);
});
expect(completer.isCompleted, isFalse);
pair.second.close();
final int status = await completer.future;
expect(status, equals(ZX.OK));
});
}

View File

@@ -1,43 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:zircon/zircon.dart';
void main() {
group('test vmo', () {
test('fromFile', () {
const String fuchsia = 'Fuchsia';
File f = File('tmp/testdata')
..createSync()
..writeAsStringSync(fuchsia);
String readFuchsia = f.readAsStringSync();
expect(readFuchsia, equals(fuchsia));
SizedVmo fileVmo = SizedVmo.fromFile('tmp/testdata');
Uint8List fileData = fileVmo.map();
String fileString = utf8.decode(fileData.sublist(0, fileVmo.size));
expect(fileString, equals(fuchsia));
});
test('duplicate', () {
const String fuchsia = 'Fuchsia';
Uint8List data = Uint8List.fromList(fuchsia.codeUnits);
SizedVmo vmo = SizedVmo.fromUint8List(data);
final Vmo duplicate =
vmo.duplicate(ZX.RIGHTS_BASIC | ZX.RIGHT_READ | ZX.RIGHT_MAP);
expect(duplicate.isValid, isTrue);
// Read from the duplicate.
final duplicatedVmo = SizedVmo(duplicate.handle, fuchsia.length);
Uint8List vmoData = duplicatedVmo.map();
String vmoString = utf8.decode(vmoData.sublist(0, vmo.size));
expect(vmoString, equals(fuchsia));
});
});
}

View File

@@ -0,0 +1,618 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'dart:zircon';
import 'package:litetest/litetest.dart';
/// Helper method to turn a [String] into a [ByteData] containing the
/// text of the string encoded as UTF-8.
ByteData utf8Bytes(final String text) {
return ByteData.view(Uint8List.fromList(utf8.encode(text)).buffer);
}
// Take from zircon constants in zircon/errors.h, zircon/rights.h, zircon/types.h
abstract class ZX {
ZX._();
static const int OK = 0;
static const int KOID_INVALID = 0;
static const int ERR_BAD_HANDLE = -11;
static const int ERR_SHOULD_WAIT = -22;
static const int ERR_PEER_CLOSED = -24;
static const int ERR_ACCESS_DENIED = -30;
static const int EVENTPAIR_PEER_CLOSED = __ZX_OBJECT_PEER_CLOSED;
static const int CHANNEL_READABLE = __ZX_OBJECT_READABLE;
static const int CHANNEL_PEER_CLOSED = __ZX_OBJECT_PEER_CLOSED;
static const int SOCKET_READABLE = __ZX_OBJECT_READABLE;
static const int SOCKET_PEER_CLOSED = __ZX_OBJECT_PEER_CLOSED;
static const int RIGHT_DUPLICATE = 1 << 0;
static const int RIGHT_TRANSFER = 1 << 1;
static const int RIGHT_READ = 1 << 2;
static const int RIGHT_WRITE = 1 << 3;
static const int RIGHT_GET_PROPERTY = 1 << 6;
static const int RIGHT_SET_PROPERTY = 1 << 7;
static const int RIGHT_MAP = 1 << 5;
static const int RIGHT_SIGNAL = 1 << 12;
static const int RIGHT_WAIT = 1 << 14;
static const int RIGHT_INSPECT = 1 << 15;
static const int RIGHT_SAME_RIGHTS = 1 << 31;
static const int RIGHTS_BASIC = RIGHT_TRANSFER | RIGHT_DUPLICATE |
RIGHT_WAIT | RIGHT_INSPECT;
static const int RIGHTS_IO = RIGHT_READ | RIGHT_WRITE;
static const int RIGHTS_PROPERTY = RIGHT_GET_PROPERTY | RIGHT_SET_PROPERTY;
static const int DEFAULT_VMO_RIGHTS = RIGHTS_BASIC | RIGHTS_IO |
RIGHTS_PROPERTY | RIGHT_MAP |
RIGHT_SIGNAL;
static const int OBJ_TYPE_VMO = 3;
static const int OBJ_TYPE_CHANNEL = 4;
static const int HANDLE_OP_MOVE = 0;
static const int HANDLE_OP_DUPLICATE = 1;
static const int __ZX_OBJECT_READABLE = 1 << 0;
static const int __ZX_OBJECT_PEER_CLOSED = 1 << 2;
}
void main() {
group('handle', () {
test('create and duplicate handles', () {
final HandlePairResult pair = System.eventpairCreate();
expect(pair.status, equals(ZX.OK));
expect(pair.first.isValid, isTrue);
expect(pair.second.isValid, isTrue);
final Handle duplicate = pair.first.duplicate(ZX.RIGHT_SAME_RIGHTS);
expect(duplicate.isValid, isTrue);
final Handle failedDuplicate = pair.first.duplicate(-1);
expect(failedDuplicate.isValid, isFalse);
});
test('failure invalid rights', () {
final HandleResult vmo = System.vmoCreate(0);
expect(vmo.status, equals(ZX.OK));
final Handle failedDuplicate = vmo.handle.duplicate(-1);
expect(failedDuplicate.isValid, isFalse);
expect(vmo.handle.isValid, isTrue);
});
test('failure invalid handle', () {
final Handle handle = Handle.invalid();
final Handle duplicate = handle.duplicate(ZX.RIGHT_SAME_RIGHTS);
expect(duplicate.isValid, isFalse);
});
test('duplicated handle should have same koid', () {
final HandlePairResult pair = System.eventpairCreate();
expect(pair.status, equals(ZX.OK));
expect(pair.first.isValid, isTrue);
expect(pair.second.isValid, isTrue);
final Handle duplicate = pair.first.duplicate(ZX.RIGHT_SAME_RIGHTS);
expect(duplicate.isValid, isTrue);
expect(pair.first.koid, duplicate.koid);
});
// TODO(fxbug.dev/77599): Simplify once zx_object_get_info is available.
test('reduced rights', () {
// Set up handle.
final HandleResult vmo = System.vmoCreate(2);
expect(vmo.status, equals(ZX.OK));
// Duplicate the first handle.
final Handle duplicate = vmo.handle.duplicate(ZX.RIGHTS_BASIC);
expect(duplicate.isValid, isTrue);
// Write bytes to the original handle.
final ByteData data1 = utf8Bytes('a');
final int status1 = System.vmoWrite(vmo.handle, 0, data1);
expect(status1, equals(ZX.OK));
// Write bytes to the duplicated handle.
final ByteData data2 = utf8Bytes('b');
final int status2 = System.vmoWrite(duplicate, 1, data2);
expect(status2, equals(ZX.ERR_ACCESS_DENIED));
// Read bytes.
final ReadResult readResult = System.vmoRead(vmo.handle, 0, 2);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals(2));
expect(readResult.bytes.lengthInBytes, equals(2));
expect(readResult.bytesAsUTF8String(), equals('a\x00'));
});
test('create and replace handles', () {
final HandlePairResult pair = System.eventpairCreate();
expect(pair.status, equals(ZX.OK));
expect(pair.first.isValid, isTrue);
expect(pair.second.isValid, isTrue);
final Handle replaced = pair.first.replace(ZX.RIGHT_SAME_RIGHTS);
expect(replaced.isValid, isTrue);
expect(pair.first.isValid, isFalse);
});
test('failure invalid rights', () {
final HandleResult vmo = System.vmoCreate(0);
expect(vmo.status, equals(ZX.OK));
final Handle failedDuplicate = vmo.handle.replace(-1);
expect(failedDuplicate.isValid, isFalse);
expect(vmo.handle.isValid, isFalse);
});
test('failure invalid handle', () {
final Handle handle = Handle.invalid();
final Handle replaced = handle.replace(ZX.RIGHT_SAME_RIGHTS);
expect(handle.isValid, isFalse);
expect(replaced.isValid, isFalse);
});
test('transferred handle should have same koid', () {
final HandlePairResult pair = System.eventpairCreate();
expect(pair.status, equals(ZX.OK));
expect(pair.first.isValid, isTrue);
expect(pair.second.isValid, isTrue);
final int koid = pair.first.koid;
final Handle replaced = pair.first.replace(ZX.RIGHT_SAME_RIGHTS);
expect(replaced.isValid, isTrue);
expect(koid, replaced.koid);
});
// TODO(fxbug.dev/77599): Simplify once zx_object_get_info is available.
test('reduced rights', () {
// Set up handle.
final HandleResult vmo = System.vmoCreate(2);
expect(vmo.status, equals(ZX.OK));
// Replace the first handle.
final Handle duplicate =
vmo.handle.replace(ZX.RIGHTS_BASIC | ZX.RIGHT_READ);
expect(duplicate.isValid, isTrue);
// Write bytes to the original handle.
final ByteData data1 = utf8Bytes('a');
final int status1 = System.vmoWrite(vmo.handle, 0, data1);
expect(status1, equals(ZX.ERR_BAD_HANDLE));
// Write bytes to the duplicated handle.
final ByteData data2 = utf8Bytes('b');
final int status2 = System.vmoWrite(duplicate, 1, data2);
expect(status2, equals(ZX.ERR_ACCESS_DENIED));
// Read bytes.
final ReadResult readResult = System.vmoRead(duplicate, 0, 2);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals(2));
expect(readResult.bytes.lengthInBytes, equals(2));
expect(readResult.bytesAsUTF8String(), equals('\x00\x00'));
});
test('cache koid and invalidate', () {
final HandleResult vmo = System.vmoCreate(0);
expect(vmo.status, equals(ZX.OK));
int originalKoid = vmo.handle.koid;
expect(originalKoid, notEquals(ZX.KOID_INVALID));
// Cached koid should be same value.
expect(originalKoid, equals(vmo.handle.koid));
vmo.handle.close();
// koid should be invalidated.
expect(vmo.handle.koid, equals(ZX.KOID_INVALID));
});
test('store the disposition arguments correctly', () {
final Handle handle = System.channelCreate().first;
final HandleDisposition disposition = HandleDisposition(1, handle, 2, 3);
expect(disposition.operation, equals(1));
expect(disposition.handle, equals(handle));
expect(disposition.type, equals(2));
expect(disposition.rights, equals(3));
expect(disposition.result, equals(ZX.OK));
});
});
group('channel', () {
test('create channel', () {
final HandlePairResult pair = System.channelCreate();
expect(pair.status, equals(ZX.OK));
expect(pair.first.isValid, isTrue);
expect(pair.second.isValid, isTrue);
});
test('close channel', () {
final HandlePairResult pair = System.channelCreate();
expect(pair.first.close(), equals(0));
expect(pair.first.isValid, isFalse);
expect(pair.second.isValid, isTrue);
expect(System.channelWrite(pair.first, ByteData(1), <Handle>[]),
equals(ZX.ERR_BAD_HANDLE));
expect(System.channelWrite(pair.second, ByteData(1), <Handle>[]),
equals(ZX.ERR_PEER_CLOSED));
});
test('channel bytes', () {
final HandlePairResult pair = System.channelCreate();
// When no data is available, ZX.ERR_SHOULD_WAIT is returned.
expect(System.channelQueryAndRead(pair.second).status,
equals(ZX.ERR_SHOULD_WAIT));
// Write bytes.
final ByteData data = utf8Bytes('Hello, world');
final int status = System.channelWrite(pair.first, data, <Handle>[]);
expect(status, equals(ZX.OK));
// Read bytes.
final ReadResult readResult = System.channelQueryAndRead(pair.second);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals(data.lengthInBytes));
expect(readResult.bytes.lengthInBytes, equals(data.lengthInBytes));
expect(readResult.bytesAsUTF8String(), equals('Hello, world'));
expect(readResult.handles.length, equals(0));
});
test('channel handles', () {
final HandlePairResult pair = System.channelCreate();
final ByteData data = utf8Bytes('');
final HandlePairResult eventPair = System.eventpairCreate();
final int status =
System.channelWrite(pair.first, data, <Handle>[eventPair.first]);
expect(status, equals(ZX.OK));
expect(eventPair.first.isValid, isFalse);
final ReadResult readResult = System.channelQueryAndRead(pair.second);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals(0));
expect(readResult.bytes.lengthInBytes, equals(0));
expect(readResult.bytesAsUTF8String(), equals(''));
expect(readResult.handles.length, equals(1));
expect(readResult.handles[0].isValid, isTrue);
});
test('async wait channel read', () async {
final HandlePairResult pair = System.channelCreate();
final Completer<List<int>> completer = Completer<List<int>>();
pair.first.asyncWait(ZX.CHANNEL_READABLE, (int status, int pending) {
completer.complete(<int>[status, pending]);
});
expect(completer.isCompleted, isFalse);
System.channelWrite(pair.second, utf8Bytes('Hi'), <Handle>[]);
final List<int> result = await completer.future;
expect(result[0], equals(ZX.OK)); // status
expect(result[1] & ZX.CHANNEL_READABLE,
equals(ZX.CHANNEL_READABLE)); // pending
});
test('async wait channel closed', () async {
final HandlePairResult pair = System.channelCreate();
final Completer<int> completer = Completer<int>();
pair.first.asyncWait(ZX.CHANNEL_PEER_CLOSED, (int status, int pending) {
completer.complete(status);
});
expect(completer.isCompleted, isFalse);
pair.second.close();
final int status = await completer.future;
expect(status, equals(ZX.OK));
});
});
group('channel etc functions', () {
test('moved handle', () {
final HandlePairResult pair = System.channelCreate();
final ByteData data = utf8Bytes('');
final HandlePairResult transferred = System.channelCreate();
final HandleDisposition disposition = HandleDisposition(ZX.HANDLE_OP_MOVE,
transferred.first, ZX.OBJ_TYPE_CHANNEL, ZX.RIGHTS_IO);
final int status = System.channelWriteEtc(
pair.first, data, <HandleDisposition>[disposition]);
expect(status, equals(ZX.OK));
expect(disposition.result, equals(ZX.OK));
expect(transferred.first.isValid, isFalse);
final ReadEtcResult readResult =
System.channelQueryAndReadEtc(pair.second);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals(0));
expect(readResult.bytes.lengthInBytes, equals(0));
expect(readResult.bytesAsUTF8String(), equals(''));
expect(readResult.handleInfos.length, equals(1));
final HandleInfo handleInfo = readResult.handleInfos[0];
expect(handleInfo.handle.isValid, isTrue);
expect(handleInfo.type, equals(ZX.OBJ_TYPE_CHANNEL));
expect(handleInfo.rights, equals(ZX.RIGHTS_IO));
});
test('copied handle', () {
final HandlePairResult pair = System.channelCreate();
final ByteData data = utf8Bytes('');
final HandleResult vmo = System.vmoCreate(0);
final HandleDisposition disposition = HandleDisposition(
ZX.HANDLE_OP_DUPLICATE,
vmo.handle,
ZX.OBJ_TYPE_VMO,
ZX.RIGHT_SAME_RIGHTS);
final int status = System.channelWriteEtc(
pair.first, data, <HandleDisposition>[disposition]);
expect(status, equals(ZX.OK));
expect(disposition.result, equals(ZX.OK));
expect(vmo.handle.isValid, isTrue);
final ReadEtcResult readResult =
System.channelQueryAndReadEtc(pair.second);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals(0));
expect(readResult.bytes.lengthInBytes, equals(0));
expect(readResult.bytesAsUTF8String(), equals(''));
expect(readResult.handleInfos.length, equals(1));
final HandleInfo handleInfo = readResult.handleInfos[0];
expect(handleInfo.handle.isValid, isTrue);
expect(handleInfo.type, equals(ZX.OBJ_TYPE_VMO));
expect(handleInfo.rights, equals(ZX.DEFAULT_VMO_RIGHTS));
});
test('closed handle should error', () {
final HandlePairResult pair = System.channelCreate();
final ByteData data = utf8Bytes('');
final HandlePairResult closed = System.channelCreate();
final HandleDisposition disposition = HandleDisposition(ZX.HANDLE_OP_MOVE,
closed.first, ZX.OBJ_TYPE_CHANNEL, ZX.RIGHT_SAME_RIGHTS);
closed.first.close();
final int status = System.channelWriteEtc(
pair.first, data, <HandleDisposition>[disposition]);
expect(status, equals(ZX.ERR_BAD_HANDLE));
expect(disposition.result, equals(ZX.ERR_BAD_HANDLE));
expect(closed.first.isValid, isFalse);
final ReadEtcResult readResult =
System.channelQueryAndReadEtc(pair.second);
expect(readResult.status, equals(ZX.ERR_SHOULD_WAIT));
});
test('multiple handles', () {
final HandlePairResult pair = System.channelCreate();
final ByteData data = utf8Bytes('');
final HandlePairResult transferred = System.channelCreate();
final HandleResult vmo = System.vmoCreate(0);
final List<HandleDisposition> dispositions = [
HandleDisposition(ZX.HANDLE_OP_MOVE, transferred.first,
ZX.OBJ_TYPE_CHANNEL, ZX.RIGHTS_IO),
HandleDisposition(ZX.HANDLE_OP_DUPLICATE, vmo.handle, ZX.OBJ_TYPE_VMO,
ZX.RIGHT_SAME_RIGHTS)
];
final int status = System.channelWriteEtc(pair.first, data, dispositions);
expect(status, equals(ZX.OK));
expect(dispositions[0].result, equals(ZX.OK));
expect(dispositions[1].result, equals(ZX.OK));
expect(transferred.first.isValid, isFalse);
expect(vmo.handle.isValid, isTrue);
final ReadEtcResult readResult =
System.channelQueryAndReadEtc(pair.second);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals(0));
expect(readResult.bytes.lengthInBytes, equals(0));
expect(readResult.bytesAsUTF8String(), equals(''));
expect(readResult.handleInfos.length, equals(2));
final HandleInfo handleInfo = readResult.handleInfos[0];
expect(handleInfo.handle.isValid, isTrue);
expect(handleInfo.type, equals(ZX.OBJ_TYPE_CHANNEL));
expect(handleInfo.rights, equals(ZX.RIGHTS_IO));
final HandleInfo vmoInfo = readResult.handleInfos[1];
expect(vmoInfo.handle.isValid, isTrue);
expect(vmoInfo.type, equals(ZX.OBJ_TYPE_VMO));
expect(vmoInfo.rights, equals(ZX.DEFAULT_VMO_RIGHTS));
});
});
group('eventpair', () {
test('create', () {
final HandlePairResult pair = System.eventpairCreate();
expect(pair.status, equals(ZX.OK));
expect(pair.first.isValid, isTrue);
expect(pair.second.isValid, isTrue);
});
test('duplicate', () {
final HandlePairResult pair = System.eventpairCreate();
expect(pair.status, equals(ZX.OK));
expect(pair.first.isValid, isTrue);
expect(pair.second.isValid, isTrue);
expect(pair.first.duplicate(ZX.RIGHT_SAME_RIGHTS).isValid, isTrue);
expect(pair.second.duplicate(ZX.RIGHT_SAME_RIGHTS).isValid, isTrue);
});
test('close', () {
final HandlePairResult pair = System.eventpairCreate();
expect(pair.first.close(), equals(0));
expect(pair.first.isValid, isFalse);
expect(pair.second.isValid, isTrue);
expect(pair.second.close(), equals(0));
expect(pair.second.isValid, isFalse);
});
test('async wait peer closed', () async {
final HandlePairResult pair = System.eventpairCreate();
final Completer<int> completer = Completer<int>();
pair.first.asyncWait(ZX.EVENTPAIR_PEER_CLOSED, (int status, int pending) {
completer.complete(status);
});
expect(completer.isCompleted, isFalse);
pair.second.close();
final int status = await completer.future;
expect(status, equals(ZX.OK));
});
});
// NOTE: This only tests stream sockets.
// We should add tests for datagram sockets.
group('socket', () {
test('create socket', () {
final HandlePairResult pair = System.socketCreate();
expect(pair.status, equals(ZX.OK));
expect(pair.first.isValid, isTrue);
expect(pair.second.isValid, isTrue);
});
test('close socket', () {
final HandlePairResult pair = System.socketCreate();
expect(pair.first.close(), equals(0));
expect(pair.first.isValid, isFalse);
expect(pair.second.isValid, isTrue);
final WriteResult firstResult =
System.socketWrite(pair.first, ByteData(1), 0);
expect(firstResult.status, equals(ZX.ERR_BAD_HANDLE));
final WriteResult secondResult =
System.socketWrite(pair.second, ByteData(1), 0);
expect(secondResult.status, equals(ZX.ERR_PEER_CLOSED));
});
test('read write socket', () {
final HandlePairResult pair = System.socketCreate();
// When no data is available, ZX.ERR_SHOULD_WAIT is returned.
expect(
System.socketRead(pair.second, 1).status, equals(ZX.ERR_SHOULD_WAIT));
final ByteData data = utf8Bytes('Hello, world');
final WriteResult writeResult = System.socketWrite(pair.first, data, 0);
expect(writeResult.status, equals(ZX.OK));
final ReadResult readResult =
System.socketRead(pair.second, data.lengthInBytes);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals(data.lengthInBytes));
expect(readResult.bytes.lengthInBytes, equals(data.lengthInBytes));
expect(readResult.bytesAsUTF8String(), equals('Hello, world'));
});
test('partial read socket', () {
final HandlePairResult pair = System.socketCreate();
final ByteData data = utf8Bytes('Hello, world');
final WriteResult writeResult = System.socketWrite(pair.first, data, 0);
expect(writeResult.status, equals(ZX.OK));
const int shortLength = 'Hello'.length;
final ReadResult shortReadResult =
System.socketRead(pair.second, shortLength);
expect(shortReadResult.status, equals(ZX.OK));
expect(shortReadResult.numBytes, equals(shortLength));
expect(shortReadResult.bytes.lengthInBytes, equals(shortLength));
expect(shortReadResult.bytesAsUTF8String(), equals('Hello'));
final int longLength = data.lengthInBytes * 2;
final ReadResult longReadResult =
System.socketRead(pair.second, longLength);
expect(longReadResult.status, equals(ZX.OK));
expect(longReadResult.numBytes, equals(data.lengthInBytes - shortLength));
expect(longReadResult.bytes.lengthInBytes, equals(longLength));
expect(longReadResult.bytesAsUTF8String(), equals(', world'));
});
test('partial write socket', () {
final HandlePairResult pair = System.socketCreate();
final WriteResult writeResult1 =
System.socketWrite(pair.first, utf8Bytes('Hello, '), 0);
expect(writeResult1.status, equals(ZX.OK));
final WriteResult writeResult2 =
System.socketWrite(pair.first, utf8Bytes('world'), 0);
expect(writeResult2.status, equals(ZX.OK));
final ReadResult readResult = System.socketRead(pair.second, 100);
expect(readResult.status, equals(ZX.OK));
expect(readResult.numBytes, equals('Hello, world'.length));
expect(readResult.bytes.lengthInBytes, equals(100));
expect(readResult.bytesAsUTF8String(), equals('Hello, world'));
});
test('async wait socket read', () async {
final HandlePairResult pair = System.socketCreate();
final Completer<int> completer = Completer<int>();
pair.first.asyncWait(ZX.SOCKET_READABLE, (int status, int pending) {
completer.complete(status);
});
expect(completer.isCompleted, isFalse);
System.socketWrite(pair.second, utf8Bytes('Hi'), 0);
final int status = await completer.future;
expect(status, equals(ZX.OK));
});
test('async wait socket closed', () async {
final HandlePairResult pair = System.socketCreate();
final Completer<int> completer = Completer<int>();
pair.first.asyncWait(ZX.SOCKET_PEER_CLOSED, (int status, int pending) {
completer.complete(status);
});
expect(completer.isCompleted, isFalse);
pair.second.close();
final int status = await completer.future;
expect(status, equals(ZX.OK));
});
});
group('vmo', () {
test('fromFile', () {
const String fuchsia = 'Fuchsia';
File f = File('tmp/testdata')
..createSync()
..writeAsStringSync(fuchsia);
String readFuchsia = f.readAsStringSync();
expect(readFuchsia, equals(fuchsia));
FromFileResult fileResult = System.vmoFromFile('tmp/testdata');
expect(fileResult.status, equals(ZX.OK));
MapResult mapResult = System.vmoMap(fileResult.handle);
expect(mapResult.status, equals(ZX.OK));
Uint8List fileData = UnmodifiableUint8ListView(mapResult.data);
String fileString = utf8.decode(fileData.sublist(0, fileResult.numBytes));
expect(fileString, equals(fuchsia));
});
test('duplicate', () {
const String fuchsia = 'Fuchsia';
Uint8List data = Uint8List.fromList(fuchsia.codeUnits);
HandleResult createResult = System.vmoCreate(data.length);
expect(createResult.status, equals(ZX.OK));
int writeResult = System.vmoWrite(createResult.handle, 0,
data.buffer.asByteData());
expect(writeResult, equals(ZX.OK));
Handle duplicate = createResult.handle.duplicate(ZX.RIGHTS_BASIC |
ZX.RIGHT_READ |
ZX.RIGHT_MAP);
expect(duplicate.isValid, isTrue);
// Read from the duplicate.
MapResult mapResult = System.vmoMap(duplicate);
expect(mapResult.status, equals(ZX.OK));
Uint8List vmoData = UnmodifiableUint8ListView(mapResult.data);
String vmoString = utf8.decode(vmoData.sublist(0, data.length));
expect(vmoString, equals(fuchsia));
});
});
}

View File

@@ -96,6 +96,7 @@ dart_library("expect") {
deps = [ ":meta" ]
sources = [
"config.dart",
"expect.dart",
"minitest.dart",
]

View File

@@ -65,6 +65,7 @@ template("runner_sources") {
"$fuchsia_sdk_root/pkg:trace",
"$fuchsia_sdk_root/pkg:vfs_cpp",
"$fuchsia_sdk_root/pkg:zx",
"fidl:dart_test",
"//flutter/common",
"//flutter/shell/platform/fuchsia/dart-pkg/fuchsia",
"//flutter/shell/platform/fuchsia/dart-pkg/zircon",

View File

@@ -15,6 +15,8 @@
#include <lib/fidl/cpp/string.h>
#include <lib/sys/cpp/service_directory.h>
#include <lib/syslog/global.h>
#include <lib/vfs/cpp/composed_service_dir.h>
#include <lib/vfs/cpp/remote_dir.h>
#include <lib/zx/clock.h>
#include <lib/zx/thread.h>
#include <sys/stat.h>
@@ -25,6 +27,7 @@
#include <regex>
#include <utility>
#include "dart_api.h"
#include "runtime/dart/utils/files.h"
#include "runtime/dart/utils/handle_exception.h"
#include "runtime/dart/utils/inlines.h"
@@ -104,10 +107,13 @@ DartComponentController::DartComponentController(
controller)
: loop_(new async::Loop(&kLoopConfig)),
label_(GetLabelFromUrl(start_info.resolved_url())),
url_(std::move(start_info.resolved_url())),
runner_incoming_services_(runner_incoming_services),
url_(start_info.resolved_url()),
runner_incoming_services_(std::move(runner_incoming_services)),
dart_outgoing_dir_(new vfs::PseudoDir()),
start_info_(std::move(start_info)),
binding_(this) {
binding_(this, std::move(controller)) {
binding_.set_error_handler([this](zx_status_t status) { Kill(); });
// TODO(fxb/84537): This data path is configured based how we build Flutter
// applications in tree currently, but the way we build the Flutter
// application may change. We should avoid assuming the data path and let the
@@ -115,14 +121,6 @@ DartComponentController::DartComponentController(
const std::string component_name = GetComponentNameFromUrl(url_);
data_path_ = "pkg/data/" + component_name;
if (controller.is_valid()) {
binding_.Bind(std::move(controller));
binding_.set_error_handler([this](zx_status_t status) { Kill(); });
} else {
FX_LOG(ERROR, LOG_TAG,
"Fuchsia component controller endpoint is not valid.");
}
zx_status_t idle_timer_status =
zx::timer::create(ZX_TIMER_SLACK_LATE, ZX_CLOCK_MONOTONIC, &idle_timer_);
if (idle_timer_status != ZX_OK) {
@@ -213,6 +211,84 @@ bool DartComponentController::CreateAndBindNamespace() {
}
}
dart_outgoing_dir_request_ = dart_outgoing_dir_ptr_.NewRequest();
fuchsia::io::DirectoryHandle dart_public_dir;
// TODO(anmittal): when fixing enumeration using new c++ vfs, make sure that
// flutter_public_dir is only accessed once we receive OnOpen Event.
// That will prevent FL-175 for public directory
fdio_service_connect_at(dart_outgoing_dir_ptr_.channel().get(), "svc",
dart_public_dir.NewRequest().TakeChannel().release());
auto composed_service_dir = std::make_unique<vfs::ComposedServiceDir>();
composed_service_dir->set_fallback(std::move(dart_public_dir));
// Clone and check if client is servicing the directory.
dart_outgoing_dir_ptr_->Clone(
fuchsia::io::OpenFlags::DESCRIBE |
fuchsia::io::OpenFlags::CLONE_SAME_RIGHTS,
dart_outgoing_dir_ptr_to_check_on_open_.NewRequest());
// Collect our standard set of directories.
std::vector<std::string> other_dirs = {"debug", "ctrl", "diagnostics"};
dart_outgoing_dir_ptr_to_check_on_open_.events().OnOpen =
[this, other_dirs](zx_status_t status, auto unused) {
dart_outgoing_dir_ptr_to_check_on_open_.Unbind();
if (status != ZX_OK) {
FML_LOG(ERROR) << "could not bind out directory for dart component("
<< label_ << "): " << zx_status_get_string(status);
return;
}
// add other directories as RemoteDirs.
for (auto& dir_str : other_dirs) {
fuchsia::io::DirectoryHandle dir;
auto request = dir.NewRequest().TakeChannel();
auto status = fdio_open_at(
dart_outgoing_dir_ptr_.channel().get(), dir_str.c_str(),
static_cast<uint32_t>(fuchsia::io::OpenFlags::DIRECTORY |
fuchsia::io::OpenFlags::RIGHT_READABLE),
request.release());
if (status == ZX_OK) {
dart_outgoing_dir_->AddEntry(
dir_str.c_str(),
std::make_unique<vfs::RemoteDir>(dir.TakeChannel()));
} else {
FML_LOG(ERROR) << "could not add out directory entry(" << dir_str
<< ") for flutter component(" << label_
<< "): " << zx_status_get_string(status);
}
}
};
dart_outgoing_dir_ptr_to_check_on_open_.set_error_handler(
[this](zx_status_t status) {
dart_outgoing_dir_ptr_to_check_on_open_.Unbind();
});
// Expose the "Echo" service here on behalf of the running dart program, so
// that integration tests can make use of it.
//
// The flutter/engine repository doesn't support connecting to FIDL from Dart,
// so for the tests sake we connect to the FIDL from C++ here and proxy the
// Echo to dart using native hooks.
composed_service_dir->AddService(
dart::test::Echo::Name_,
std::make_unique<vfs::Service>([this](zx::channel channel,
async_dispatcher_t* dispatcher) {
echo_binding_.AddBinding(
this, fidl::InterfaceRequest<dart::test::Echo>(std::move(channel)));
}));
dart_outgoing_dir_->AddEntry("svc", std::move(composed_service_dir));
if (start_info_.has_outgoing_dir()) {
dart_outgoing_dir_->Serve(
fuchsia::io::OpenFlags::RIGHT_READABLE |
fuchsia::io::OpenFlags::RIGHT_WRITABLE |
fuchsia::io::OpenFlags::DIRECTORY,
start_info_.mutable_outgoing_dir()->TakeChannel());
}
return true;
}
@@ -390,11 +466,9 @@ bool DartComponentController::RunDartMain() {
stdout_fd_ = fileno(stdout);
stderr_fd_ = fileno(stderr);
fidl::InterfaceRequest<fuchsia::io::Directory> outgoing_dir =
std::move(*start_info_.mutable_outgoing_dir());
InitBuiltinLibrariesForIsolate(
url_, namespace_, stdout_fd_, stderr_fd_, nullptr /* environment */,
outgoing_dir.TakeChannel(), false /* service_isolate */);
dart_outgoing_dir_request_.TakeChannel(), false /* service_isolate */);
Dart_ExitScope();
Dart_ExitIsolate();
@@ -463,6 +537,29 @@ bool DartComponentController::RunDartMain() {
return true;
}
void DartComponentController::EchoString(fidl::StringPtr value,
EchoStringCallback callback) {
Dart_EnterScope();
Dart_Handle builtin_lib = Dart_LookupLibrary(ToDart("dart:fuchsia.builtin"));
FML_CHECK(!tonic::CheckAndHandleError(builtin_lib));
Dart_Handle receive_echo_string = ToDart("_receiveEchoString");
Dart_Handle string_to_echo =
value.has_value() ? tonic::ToDart(*value) : Dart_Null();
Dart_Handle result =
Dart_Invoke(builtin_lib, receive_echo_string, 1, &string_to_echo);
FML_CHECK(!tonic::CheckAndHandleError(result));
fidl::StringPtr echo_string;
if (!Dart_IsNull(result)) {
echo_string = tonic::StdStringFromDart(result);
}
callback(std::move(echo_string));
Dart_ExitScope();
}
void DartComponentController::Kill() {
if (Dart_CurrentIsolate()) {
tonic::DartMicrotaskQueue* queue =
@@ -482,6 +579,10 @@ void DartComponentController::Kill() {
}
}
void DartComponentController::Stop() {
Kill();
}
void DartComponentController::MessageEpilogue(Dart_Handle result) {
auto dart_state = tonic::DartState::Current();
// If the Dart program has set a return code, then it is intending to shut
@@ -510,10 +611,6 @@ void DartComponentController::MessageEpilogue(Dart_Handle result) {
}
}
void DartComponentController::Stop() {
Kill();
}
void DartComponentController::OnIdleTimer(async_dispatcher_t* dispatcher,
async::WaitBase* wait,
zx_status_t status,

View File

@@ -5,18 +5,22 @@
#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_RUNNER_DART_COMPONENT_CONTROLLER_H_
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_RUNNER_DART_COMPONENT_CONTROLLER_H_
#include <memory>
#include <dart/test/cpp/fidl.h>
#include <fuchsia/component/runner/cpp/fidl.h>
#include <fuchsia/sys/cpp/fidl.h>
#include <lib/async-loop/cpp/loop.h>
#include <lib/async/cpp/wait.h>
#include <lib/fdio/namespace.h>
#include <lib/fidl/cpp/binding.h>
#include <lib/fidl/cpp/binding_set.h>
#include <lib/fidl/cpp/string.h>
#include <lib/sys/cpp/component_context.h>
#include <lib/sys/cpp/service_directory.h>
#include <lib/vfs/cpp/pseudo_dir.h>
#include <lib/zx/timer.h>
#include "lib/fidl/cpp/binding.h"
#include <memory>
#include "runtime/dart/utils/mapped_resource.h"
#include "third_party/dart/runtime/include/dart_api.h"
@@ -24,7 +28,8 @@ namespace dart_runner {
/// Starts a Dart component written in CFv2.
class DartComponentController
: public fuchsia::component::runner::ComponentController {
: public dart::test::Echo,
public fuchsia::component::runner::ComponentController {
public:
DartComponentController(
fuchsia::component::runner::ComponentStartInfo start_info,
@@ -59,6 +64,9 @@ class DartComponentController
bool CreateIsolate(const uint8_t* isolate_snapshot_data,
const uint8_t* isolate_snapshot_instructions);
// |Echo|
void EchoString(fidl::StringPtr value, EchoStringCallback callback) override;
// |ComponentController|
void Kill() override;
void Stop() override;
@@ -76,12 +84,17 @@ class DartComponentController
std::string label_;
std::string url_;
std::shared_ptr<sys::ServiceDirectory> runner_incoming_services_;
std::string data_path_;
std::shared_ptr<sys::ServiceDirectory> runner_incoming_services_;
std::unique_ptr<sys::ComponentContext> context_;
std::unique_ptr<vfs::PseudoDir> dart_outgoing_dir_;
fuchsia::io::DirectoryPtr dart_outgoing_dir_ptr_;
fidl::InterfaceRequest<fuchsia::io::Directory> dart_outgoing_dir_request_;
fuchsia::io::NodePtr dart_outgoing_dir_ptr_to_check_on_open_;
fuchsia::component::runner::ComponentStartInfo start_info_;
fidl::Binding<fuchsia::component::runner::ComponentController> binding_;
fidl::BindingSet<dart::test::Echo> echo_binding_;
fdio_ns_t* namespace_ = nullptr;
int stdout_fd_ = -1;

View File

@@ -50,3 +50,11 @@ _setupHooks() {
@pragma('vm:entry-point')
_getPrintClosure() => _print;
typedef EchoStringCallback = String? Function(String? str);
late EchoStringCallback? receiveEchoStringCallback;
@pragma('vm:entry-point')
String? _receiveEchoString(String? str) {
return receiveEchoStringCallback?.call(str);
}

View File

@@ -5,8 +5,8 @@
import("//build/fuchsia/sdk.gni")
import("//flutter/tools/fuchsia/fidl/fidl.gni")
fidl("echo") {
name = "flutter.example.echo"
meta = "//flutter/shell/platform/fuchsia/dart_runner/tests/fidl/flutter.example.echo/meta.json"
fidl("dart_test") {
name = "dart.test"
meta = "meta.json"
sources = [ "echo.fidl" ]
}

View File

@@ -1,8 +1,8 @@
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
library flutter.example.echo;
library dart.test;
const MAX_STRING_LENGTH uint64 = 32;

View File

@@ -0,0 +1,9 @@
{
"deps": [],
"name": "dart.test",
"root": "dart.test",
"sources": [
"../../../flutter/shell/platform/fuchsia/dart_runner/fidl/echo.fidl"
],
"type": "fidl_library"
}

View File

@@ -1,3 +0,0 @@
# Echo FIDL
This FIDL protocol allows the Dart integration tests to communicate with a Dart Echo server (a test Dart component that echoes back a request).

View File

@@ -1,9 +0,0 @@
{
"deps": [],
"name": "flutter.example.echo",
"root": "fidl/flutter.example.echo",
"sources": [
"../../../flutter/shell/platform/fuchsia/dart_runner/tests/fidl/flutter.example.echo/echo.fidl"
],
"type": "fidl_library"
}

View File

@@ -31,9 +31,9 @@ executable("dart-aot-runner-integration-test-bin") {
"$fuchsia_sdk_root/pkg:fidl_cpp",
"$fuchsia_sdk_root/pkg:sys_component_cpp_testing",
"$fuchsia_sdk_root/pkg:zx",
"../dart_echo_server:aot_echo_package",
"//flutter/fml",
"//flutter/shell/platform/fuchsia/dart_runner/tests/fidl/flutter.example.echo:echo",
"//flutter/shell/platform/fuchsia/dart_runner/tests/startup_integration_test/dart_echo_server:aot_echo_package",
"//flutter/shell/platform/fuchsia/dart_runner/fidl:dart_test",
"//third_party/googletest:gtest",
"//third_party/googletest:gtest_main",
]

View File

@@ -6,7 +6,7 @@ Contains the integration test for the Dart AOT runner.
<!-- TODO(erkln): Replace steps once test runner script is updated to run Dart runner tests -->
#### Setup emulator and PM serve
```
fx set workstation_eng.qemu-x64
fx set terminal.qemu-x64
ffx emu start --headless
fx serve
@@ -20,11 +20,11 @@ ninja -C $ENGINE_DIR/out/fuchsia_profile_x64 flutter/shell/platform/fuchsia fuch
#### Publish files to PM
```
$FUCHSIA_DIR/.jiri_root/bin/fx pm publish -a -repo $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files -f $ENGINE_DIR/out/fuchsia_profile_x64/dart-aot-runner-integration-test-0.far
$FUCHSIA_DIR/.jiri_root/bin/ffx repository publish $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files --package-archive $ENGINE_DIR/out/fuchsia_profile_x64/dart-aot-runner-integration-test-0.far
$FUCHSIA_DIR/.jiri_root/bin/fx pm publish -a -repo $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files -f $ENGINE_DIR/out/fuchsia_profile_x64/oot_dart_aot_runner-0.far
$FUCHSIA_DIR/.jiri_root/bin/ffx repository publish $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files --package-archive $ENGINE_DIR/out/fuchsia_profile_x64/oot_dart_aot_runner-0.far
$FUCHSIA_DIR/.jiri_root/bin/fx pm publish -a -repo $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files -f $ENGINE_DIR/out/fuchsia_profile_x64/gen/flutter/shell/platform/fuchsia/dart_runner/tests/startup_integration_test/dart_echo_server/dart_aot_echo_server/dart_aot_echo_server.far
$FUCHSIA_DIR/.jiri_root/bin/ffx repository publish $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files --package-archive $ENGINE_DIR/out/fuchsia_profile_x64/gen/flutter/shell/platform/fuchsia/dart_runner/tests/startup_integration_test/dart_echo_server/dart_aot_echo_server/dart_aot_echo_server.far
```
#### Run test
@@ -33,4 +33,4 @@ ffx test run "fuchsia-pkg://fuchsia.com/dart-aot-runner-integration-test#meta/da
```
## Notes
The `profile` runtime should be used when running the `dart_aot_runner` integration test. Snapshots will fail to generate or generate incorrectly if the wrong runtime is used.
The `profile` runtime should be used when running the `dart_aot_runner` integration test. Snapshots will fail to generate or generate incorrectly if the wrong runtime is used.

View File

@@ -2,11 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The generated C++ bindings for the Echo FIDL protocol
#include <flutter/shell/platform/fuchsia/dart_runner/tests/fidl/flutter.example.echo/flutter/example/echo/cpp/fidl.h>
#include <dart/test/cpp/fidl.h>
#include <fuchsia/tracing/provider/cpp/fidl.h>
#include <lib/async-loop/testing/cpp/real_loop.h>
#include <lib/sys/component/cpp/testing/realm_builder.h>
#include <lib/sys/component/cpp/testing/realm_builder_types.h>
@@ -92,16 +89,15 @@ TEST_F(RealmBuilderTest, DartRunnerStartsUp) {
// Route the Echo FIDL protocol, this allows the Dart echo server to
// communicate with the Realm Builder
realm_builder.AddRoute(
Route{.capabilities = {Protocol{"flutter.example.echo.Echo"}},
.source = kDartAotEchoServerRef,
.targets = {ParentRef()}});
realm_builder.AddRoute(Route{.capabilities = {Protocol{"dart.test.Echo"}},
.source = kDartAotEchoServerRef,
.targets = {ParentRef()}});
// Build the Realm with the provided child and protocols
auto realm = realm_builder.Build(dispatcher());
FML_LOG(INFO) << "Realm built: " << realm.component().GetChildName();
// Connect to the Dart echo server
auto echo = realm.component().ConnectSync<flutter::example::echo::Echo>();
auto echo = realm.component().ConnectSync<dart::test::Echo>();
fidl::StringPtr response;
// Attempt to ping the Dart echo server for a response
echo->EchoString("hello", &response);

View File

@@ -15,14 +15,6 @@ dart_library("lib") {
source_dir = "."
sources = [ "main.dart" ]
deps = [
"//flutter/shell/platform/fuchsia/dart_runner/tests/fidl/flutter.example.echo:echo",
"//flutter/tools/fuchsia/dart:fidl",
"//flutter/tools/fuchsia/dart:fuchsia_services",
"//flutter/tools/fuchsia/fidl:fuchsia.logger",
"//flutter/tools/fuchsia/fidl:fuchsia.test",
]
}
# Dart component that serves the test Echo FIDL protocol, built using the Dart AOT runner

View File

@@ -2,47 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The server uses async code to be able to listen for incoming Echo requests and connections
// asynchronously.
import 'dart:async';
import 'dart:fuchsia.builtin';
// The fidl package contains general utility code for using FIDL in Dart.
import 'package:fidl/fidl.dart' as fidl;
// The generated Dart bindings for the Echo FIDL protocol
import 'package:fidl_flutter_example_echo/fidl_async.dart' as fidl_echo;
// The fuchsia_services package interfaces with the Fuchsia system. In particular, it is used
// to expose a service to other components
import 'package:fuchsia_services/services.dart' as sys;
// Create an implementation for the Echo protocol by overriding the
// fidl_echo.Echo class from the bindings
class _EchoImpl extends fidl_echo.Echo {
// The stream controller for the stream of OnString events
final _onStringStreamController = StreamController<String>();
// Implementation of EchoString that just echoes the request value back
@override
Future<String?> echoString(String? value) async {
return value;
}
String? OnEchoString(String? str) {
print('Got echo string: $str');
return str;
}
void main(List<String> args) {
// Create the component context. We should not serve outgoing before we add
// the services.
final context = sys.ComponentContext.create();
// Each FIDL protocol class has an accompanying Binding class, which takes
// an implementation of the protocol and a channel, and dispatches incoming
// requests on the channel to the protocol implementation.
final binding = fidl_echo.EchoBinding();
// Serves the implementation by passing it a handler for incoming requests,
// and the name of the protocol it is providing.
final echo = _EchoImpl();
// Add the outgoing service, and then serve the outgoing directory.
context.outgoing
..addPublicService<fidl_echo.Echo>(
(fidl.InterfaceRequest<fidl_echo.Echo> serverEnd) =>
binding.bind(echo, serverEnd),
fidl_echo.Echo.$serviceName)
..serveFromStartupInfo();
receiveEchoStringCallback = OnEchoString;
}

View File

@@ -10,11 +10,11 @@
},
// Capabilities provided by this component.
capabilities: [
{ protocol: "flutter.example.echo.Echo" },
{ protocol: "dart.test.Echo" },
],
expose: [
{
protocol: "flutter.example.echo.Echo",
protocol: "dart.test.Echo",
from: "self",
},
],

View File

@@ -10,11 +10,11 @@
},
// Capabilities provided by this component.
capabilities: [
{ protocol: "flutter.example.echo.Echo" },
{ protocol: "dart.test.Echo" },
],
expose: [
{
protocol: "flutter.example.echo.Echo",
protocol: "dart.test.Echo",
from: "self",
},
],

View File

@@ -31,9 +31,9 @@ executable("dart-jit-runner-integration-test-bin") {
"$fuchsia_sdk_root/pkg:fidl_cpp",
"$fuchsia_sdk_root/pkg:sys_component_cpp_testing",
"$fuchsia_sdk_root/pkg:zx",
"../dart_echo_server:jit_echo_package",
"//flutter/fml",
"//flutter/shell/platform/fuchsia/dart_runner/tests/fidl/flutter.example.echo:echo",
"//flutter/shell/platform/fuchsia/dart_runner/tests/startup_integration_test/dart_echo_server:jit_echo_package",
"//flutter/shell/platform/fuchsia/dart_runner/fidl:dart_test",
"//third_party/googletest:gtest",
"//third_party/googletest:gtest_main",
]

View File

@@ -6,7 +6,7 @@ Contains the integration test for the Dart JIT runner.
<!-- TODO(erkln): Replace steps once test runner script is updated to run Dart runner tests -->
#### Setup emulator and PM serve
```
fx set workstation_eng.qemu-x64
fx set terminal.qemu-x64
ffx emu start --headless
fx serve
@@ -20,11 +20,11 @@ ninja -C $ENGINE_DIR/out/fuchsia_debug_x64 flutter/shell/platform/fuchsia fuchsi
#### Publish files to PM
```
$FUCHSIA_DIR/.jiri_root/bin/fx pm publish -a -repo $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files -f $ENGINE_DIR/out/fuchsia_debug_x64/dart-jit-runner-integration-test-0.far
$FUCHSIA_DIR/.jiri_root/bin/ffx repository publish $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files --package-archive $ENGINE_DIR/out/fuchsia_debug_x64/dart-jit-runner-integration-test-0.far
$FUCHSIA_DIR/.jiri_root/bin/fx pm publish -a -repo $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files -f $ENGINE_DIR/out/fuchsia_debug_x64/oot_dart_jit_runner-0.far
$FUCHSIA_DIR/.jiri_root/bin/ffx repository publish $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files --package-archive $ENGINE_DIR/out/fuchsia_debug_x64/oot_dart_jit_runner-0.far
$FUCHSIA_DIR/.jiri_root/bin/fx pm publish -a -repo $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files -f $ENGINE_DIR/out/fuchsia_debug_x64/gen/flutter/shell/platform/fuchsia/dart_runner/tests/startup_integration_test/dart_echo_server/dart_jit_echo_server/dart_jit_echo_server.far
$FUCHSIA_DIR/.jiri_root/bin/ffx repository publish $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files --package-archive $ENGINE_DIR/out/fuchsia_debug_x64/gen/flutter/shell/platform/fuchsia/dart_runner/tests/startup_integration_test/dart_echo_server/dart_jit_echo_server/dart_jit_echo_server.far
```
#### Run test
@@ -33,4 +33,4 @@ ffx test run "fuchsia-pkg://fuchsia.com/dart-jit-runner-integration-test#meta/da
```
## Notes
The `debug` runtime should be used when running the `dart_jit_runner` integration test. Snapshots will fail to generate or generate incorrectly if the wrong runtime is used.
The `debug` runtime should be used when running the `dart_jit_runner` integration test. Snapshots will fail to generate or generate incorrectly if the wrong runtime is used.

View File

@@ -2,11 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The generated C++ bindings for the Echo FIDL protocol
#include <flutter/shell/platform/fuchsia/dart_runner/tests/fidl/flutter.example.echo/flutter/example/echo/cpp/fidl.h>
#include <dart/test/cpp/fidl.h>
#include <fuchsia/tracing/provider/cpp/fidl.h>
#include <lib/async-loop/testing/cpp/real_loop.h>
#include <lib/sys/component/cpp/testing/realm_builder.h>
#include <lib/sys/component/cpp/testing/realm_builder_types.h>
@@ -90,16 +87,15 @@ TEST_F(RealmBuilderTest, DartRunnerStartsUp) {
// Route the Echo FIDL protocol, this allows the Dart echo server to
// communicate with the Realm Builder
realm_builder.AddRoute(
Route{.capabilities = {Protocol{"flutter.example.echo.Echo"}},
.source = kDartJitEchoServerRef,
.targets = {ParentRef()}});
realm_builder.AddRoute(Route{.capabilities = {Protocol{"dart.test.Echo"}},
.source = kDartJitEchoServerRef,
.targets = {ParentRef()}});
// Build the Realm with the provided child and protocols
auto realm = realm_builder.Build(dispatcher());
FML_LOG(INFO) << "Realm built: " << realm.component().GetChildName();
// Connect to the Dart echo server
auto echo = realm.component().ConnectSync<flutter::example::echo::Echo>();
auto echo = realm.component().ConnectSync<dart::test::Echo>();
fidl::StringPtr response;
// Attempt to ping the Dart echo server for a response
echo->EchoString("hello", &response);

View File

@@ -14,8 +14,6 @@ dart_library("lib") {
deps = [
"//flutter/shell/platform/fuchsia/dart:args",
"//flutter/shell/platform/fuchsia/dart:vector_math",
"//flutter/tools/fuchsia/dart:fuchsia_services",
"//flutter/tools/fuchsia/dart:zircon",
"//flutter/tools/fuchsia/fidl:fuchsia.sys",
"//flutter/tools/fuchsia/fidl:fuchsia.ui.app",
"//flutter/tools/fuchsia/fidl:fuchsia.ui.views",

View File

@@ -10,7 +10,6 @@ import 'dart:ui';
import 'package:args/args.dart';
import 'package:vector_math/vector_math_64.dart' as vector_math_64;
import 'package:zircon/zircon.dart';
final _argsCsvFilePath = '/config/data/args.csv';

View File

@@ -1,8 +1,8 @@
# mouse-input
`mouse-input-test` exercises mouse input through a child view (in this case, the `mouse-input-view` Dart component) and
asserting the location as well as what button was used (mouse down, mouse up, wheel, etc) during the event. We do this by
attaching the child view, injecting mouse input, and validating that the view reports the event back with the expected
`mouse-input-test` exercises mouse input through a child view (in this case, the `mouse-input-view` Dart component) and
asserting the location as well as what button was used (mouse down, mouse up, wheel, etc) during the event. We do this by
attaching the child view, injecting mouse input, and validating that the view reports the event back with the expected
payload.
```shell
@@ -24,9 +24,9 @@ Reference the Flutter integration test [documentation](https://github.com/flutte
## Playing around with `mouse-input-view`
Build Fuchsia with `workstation_eng.qemu-x64`
Build Fuchsia with `terminal.qemu-x64`
```shell
fx set workstation_eng.qemu-x64 && fx build
fx set terminal.qemu-x64 && fx build
```
Build flutter/engine

View File

@@ -12,10 +12,7 @@ dart_library("lib") {
package_name = "mouse-input-view"
sources = [ "mouse-input-view.dart" ]
deps = [
"//flutter/shell/platform/fuchsia/dart:args",
"//flutter/tools/fuchsia/dart:zircon",
]
deps = [ "//flutter/shell/platform/fuchsia/dart:args" ]
}
flutter_component("component") {

View File

@@ -5,8 +5,7 @@
import 'dart:convert';
import 'dart:typed_data';
import 'dart:ui';
import 'package:zircon/zircon.dart';
import 'dart:zircon';
void main() {
print('Launching mouse-input-view');

View File

@@ -41,9 +41,9 @@ Reference the Flutter integration test [documentation](https://github.com/flutte
## Playing around with `touch-input-view`
Build Fuchsia with `workstation_eng.qemu-x64`
Build Fuchsia with `terminal.qemu-x64`
```shell
fx set workstation_eng.qemu-x64 && fx build
fx set terminal.qemu-x64 && fx build
```
Build flutter/engine

View File

@@ -15,7 +15,6 @@ dart_library("lib") {
deps = [
"//flutter/shell/platform/fuchsia/dart:args",
"//flutter/shell/platform/fuchsia/dart:vector_math",
"//flutter/tools/fuchsia/dart:zircon",
]
}

View File

@@ -7,10 +7,10 @@ import 'dart:convert';
import 'dart:typed_data';
import 'dart:io';
import 'dart:ui';
import 'dart:zircon';
import 'package:args/args.dart';
import 'package:vector_math/vector_math_64.dart' as vector_math_64;
import 'package:zircon/zircon.dart';
final _argsCsvFilePath = '/config/data/args.csv';

View File

@@ -12,10 +12,7 @@ dart_library("lib") {
package_name = "touch-input-view"
sources = [ "touch-input-view.dart" ]
deps = [
"//flutter/shell/platform/fuchsia/dart:args",
"//flutter/tools/fuchsia/dart:zircon",
]
deps = [ "//flutter/shell/platform/fuchsia/dart:args" ]
}
flutter_component("component") {

View File

@@ -5,8 +5,7 @@
import 'dart:convert';
import 'dart:typed_data';
import 'dart:ui';
import 'package:zircon/zircon.dart';
import 'dart:zircon';
void main() {
print('Launching touch-input-view');

View File

@@ -1,12 +1,6 @@
# This configuration file specifies several test suites with their package and
# test command for femu_test.py.
- test_command: test run fuchsia-pkg://fuchsia.com/flutter-embedder-test#meta/flutter-embedder-test.cm
packages:
- flutter-embedder-test-0.far
- oot_flutter_jit_runner-0.far
- gen/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/child-view/child-view/child-view.far
- gen/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/parent-view/parent-view/parent-view.far
- test_command: test run fuchsia-pkg://fuchsia.com/dart_runner_tests#meta/dart_runner_tests.cm
package: dart_runner_tests-0.far
- test_command: test run fuchsia-pkg://fuchsia.com/flutter_runner_tests#meta/flutter_runner_tests.cm
@@ -54,6 +48,12 @@
emulator_arch:
- 'x64'
- 'arm64'
- test_command: test run fuchsia-pkg://fuchsia.com/flutter-embedder-test#meta/flutter-embedder-test.cm
packages:
- flutter-embedder-test-0.far
- oot_flutter_jit_runner-0.far
- gen/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/child-view/child-view/child-view.far
- gen/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/parent-view/parent-view/parent-view.far
- test_command: test run fuchsia-pkg://fuchsia.com/touch-input-test#meta/touch-input-test.cm
packages:
- touch-input-test-0.far

View File

@@ -154,9 +154,9 @@ if [[ "${fuchsia_cpu}" == x64 ]]
then
if [[ "${runtime_mode}" == debug ]]
then
echo " fx set workstation_eng.x64"
echo " fx set terminal.x64"
else
echo " fx set workstation_eng.x64 --release"
echo " fx set terminal.x64 --release"
fi
fi
echo ' fx build'

View File

@@ -205,7 +205,7 @@ fi
for test_package_path in "${test_package_paths[@]}"
do
engine-info "... Publishing $test_package_path to package repository ($fx_build_dir/amber-files)..."
"$jiri_bin"/fx pm publish -a -repo "$fx_build_dir/amber-files/" -f "$test_package_path"
"$jiri_bin"/ffx repository publish "$fx_build_dir/amber-files/" --package-archive "$test_package_path"
done
test_package_name_for_url="$(echo "${test_packages[0]}" | sed "s/\-0.far//")"

View File

@@ -92,7 +92,7 @@ test_names=()
for test_package in $test_packages
do
engine-info "... publishing ${test_package} ..."
$ENGINE_DIR/fuchsia/sdk/linux/tools/x64/pm publish -a -r $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files -f "${test_package}"
${FUCHSIA_DIR}/.jiri_root/bin/ffx repository publish $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files --package-archive "${test_package}"
test_names+=("$(basename ${test_package} | sed -e "s/-0.far//")")
done