Files
sdk/pkg/dynamic_modules/test/common/testing.dart
T
Nate Biggs a4a4ca8a41 [dart2wasm] Dynamic modules
Missing from this implementation:
- Closure/dynamic calls with differing signatures
- Overrides with extra optional parameters
- Records with same shape defined in different dynamic modules
- Avoiding running TFA on dynamic module.
- Recompilation of only updateable functions from main module.
- Persist wasm def types from main module.

Testing is currently done locally via the dynamic_modules package test suite:
dart pkg/dynamic_modules/test/runner/main.dart --runtime=dart2wasm

Immediately after this lands we can introduce a new step to one of the wasm test matrix configurations that runs the above test suite (the VM has a similar configuration).

Change-Id: I3386d84be11b773842d45f4268a62a54c47e352b
Tested: Tested via new tests in dynamic_modules package. Tests run locally but will add to existing config.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397721
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2025-02-11 13:59:46 -08:00

51 lines
1.9 KiB
Dart

// Copyright (c) 2024, 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.
/// A library used by dynamic module tests to simulate the loading process and
/// provide information to the test harness.
library;
import 'dart:typed_data' show Uint8List;
import 'package:dynamic_modules/dynamic_modules.dart';
import 'read_bytes.dart' if (dart.library.io) 'read_bytes_aot.dart';
/// Load a module and invoke it's entrypoint.
///
/// The module is identified by the name of its entrypoint file within the
/// `modules/` subfolder.
///
/// Optional [transformBytes] callback can be used to tweak dynamic modules
/// bytes if underlying implementation loads dynamic modules from bytes.
Future<Object?> load(String moduleName,
{Uint8List Function(Uint8List)? transformBytes}) {
if (const bool.fromEnvironment('dart.library.html')) {
// DDC implementation
return loadModuleFromUri(Uri(scheme: '', path: moduleName));
}
if (const bool.fromEnvironment('dart.library.io')) {
var bytes = readBytes('modules/$moduleName.bytecode');
if (transformBytes != null) {
bytes = transformBytes(bytes);
}
return loadModuleFromBytes(bytes);
}
// Dart2wasm implementation
return loadModuleFromUri(Uri(scheme: '', path: 'modules/$moduleName.wasm'));
}
/// Notify the test harness that the test has run to completion.
void done() {
print(successToken);
}
/// Token used by the tests to ensure they are run to completion. This mimics
/// a similar 'unit-test-done` token used by the langugage test framework.
///
/// Unit tests should call [done]. This constant is public only to ensure the
/// token is shared with the test runner, but it is not meant to be used
/// directly by tests.
const successToken = 'TOKEN!**ALL TEST EXECUTED**!!';