dart-sdk/tests/ffi_2/has_symbol_test.dart
Daco Harkes c04673f44b [vm/ffi] Support DynamicLibrary.process() on Windows
Support looking up a symbol in the process on Windows by using the
Windows Process Status API to iterate over all loaded Modules.

TEST=tests/ffi/has_symbol_test.dart
TEST=tests/ffi/vmspecific_dynamic_library_test.dart

Change-Id: I1029f1c7dae9a193b662d942388affb681842c90
Cq-Include-Trybots: luci.dart.try:vm-kernel-win-debug-x64c-try,vm-kernel-win-debug-x64-try,vm-kernel-nnbd-win-debug-x64-try,vm-kernel-precomp-win-debug-x64c-try,dart-sdk-win-try,vm-kernel-win-release-x64-try,vm-kernel-win-release-ia32-try,vm-kernel-precomp-win-product-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260760
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2022-09-27 08:42:03 +00:00

37 lines
1 KiB
Dart

// Copyright (c) 2021, 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.
//
// SharedObjects=ffi_test_functions
// @dart=2.9
import 'dart:ffi';
import 'dart:io';
import 'package:expect/expect.dart';
import 'ffi_test_helpers.dart';
void main() {
testHasSymbol();
}
void testHasSymbol() {
Expect.isTrue(ffiTestFunctions.providesSymbol('ReturnMaxUint8'));
Expect.isFalse(ffiTestFunctions.providesSymbol('SymbolNotInLibrary'));
final p = DynamicLibrary.process();
Expect.isFalse(p.providesSymbol('symbol_that_does_not_exist_in_process'));
if (Platform.isWindows) {
Expect.isTrue(p.providesSymbol('HeapAlloc'));
Expect.isTrue(p.providesSymbol('CoTaskMemAlloc'));
} else {
Expect.isTrue(p.providesSymbol('dlopen'));
}
final e = DynamicLibrary.executable();
Expect.isTrue(e.providesSymbol('Dart_Invoke'));
Expect.isFalse(e.providesSymbol('symbol_that_does_not_exist_in_executable'));
}