mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 16:41:07 +00:00
![Leaf Petersen](/assets/img/avatar_default.png)
Change-Id: Ib33169c3e0ffc870915c189404074a1dea472546 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196548 Reviewed-by: Bob Nystrom <rnystrom@google.com> Commit-Queue: Leaf Petersen <leafp@google.com>
47 lines
1.4 KiB
Dart
47 lines
1.4 KiB
Dart
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
//
|
|
// Test for DynamicLibrary.open behavior on multiple isolates.
|
|
//
|
|
// SharedObjects=ffi_test_functions
|
|
|
|
// @dart = 2.9
|
|
|
|
import 'dart:ffi';
|
|
import 'dart:io';
|
|
import 'dart:isolate';
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
import 'dylib_utils.dart';
|
|
|
|
void main() async {
|
|
final dl = dlopenPlatformSpecific('ffi_test_functions');
|
|
final dl2 = dlopenPlatformSpecific('ffi_test_functions');
|
|
Expect.equals(dl, dl2);
|
|
Expect.isFalse(identical(dl, dl2));
|
|
|
|
final setGlobalVar = dl
|
|
.lookupFunction<Void Function(Int32), void Function(int)>('SetGlobalVar');
|
|
final getGlobalVar =
|
|
dl.lookupFunction<Int32 Function(), int Function()>('GetGlobalVar');
|
|
setGlobalVar(123);
|
|
Expect.equals(123, getGlobalVar());
|
|
|
|
final receivePort = ReceivePort();
|
|
Isolate.spawn(secondIsolateMain, receivePort.sendPort);
|
|
await receivePort.first;
|
|
if (!Platform.isIOS /* Static linking causes different behavior. */) {
|
|
Expect.equals(42, getGlobalVar());
|
|
}
|
|
}
|
|
|
|
void secondIsolateMain(SendPort sendPort) {
|
|
final dl = dlopenPlatformSpecific('ffi_test_functions');
|
|
final setGlobalVar = dl
|
|
.lookupFunction<Void Function(Int32), void Function(int)>('SetGlobalVar');
|
|
setGlobalVar(42);
|
|
sendPort.send('done');
|
|
}
|