Skip to content

Commit c124f45

Browse files
alexmarkovCommit Queue
authored andcommitted
[vm,test_runner] Run vm/* tests against interpreter
Introduce Dart_LoadLibraryFromBytecode to support loading unit test libraries from bytecode. TEST=ci Change-Id: I7706fdb2acaf906f01f27f671e7193b9755efe0f Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439080 Reviewed-by: Slava Egorov <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent 76468a6 commit c124f45

File tree

9 files changed

+63
-10
lines changed

9 files changed

+63
-10
lines changed

pkg/test_runner/lib/src/compiler_configuration.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,9 +1575,14 @@ class FastaCompilerConfiguration extends CompilerConfiguration {
15751575
class BytecodeCompilerConfiguration extends CompilerConfiguration {
15761576
BytecodeCompilerConfiguration(super.configuration) : super._subclass();
15771577

1578+
bool get _isAot => _configuration.runtime == Runtime.dartPrecompiled;
1579+
15781580
@override
15791581
String computeCompilerPath() => dartAotRuntime();
15801582

1583+
@override
1584+
bool get hasCompiler => _isAot;
1585+
15811586
@override
15821587
bool get runRuntimeDespiteMissingCompileTimeError => true;
15831588

@@ -1658,18 +1663,16 @@ class BytecodeCompilerConfiguration extends CompilerConfiguration {
16581663
List<String> vmOptions,
16591664
List<String> originalArguments,
16601665
CommandArtifact? artifact) {
1661-
var filename = artifact!.filename;
1662-
16631666
return [
16641667
if (_enableAsserts) '--enable_asserts',
16651668
...vmOptions,
16661669
...testFile.sharedOptions,
16671670
..._configuration.sharedOptions,
16681671
..._experimentsArgument(_configuration, testFile),
1669-
if (_configuration.runtime == Runtime.dartPrecompiled) ...[
1672+
if (_isAot) ...[
16701673
..._replaceDartFiles(originalArguments,
16711674
'${_configuration.buildDirectory}/dynamic_module_runner.snapshot'),
1672-
filename,
1675+
artifact!.filename,
16731676
] else ...[
16741677
'--interpreter',
16751678
...originalArguments,

pkg/test_runner/lib/src/test_configurations.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ Future testConfigurations(List<TestConfiguration> configurations) async {
138138
for (var key in configuration.selectors.keys) {
139139
if (key == 'co19') {
140140
testSuites.add(Co19TestSuite(configuration, key));
141-
} else if (configuration.compiler == Compiler.dartk &&
141+
} else if ((configuration.compiler == Compiler.dartk ||
142+
configuration.compiler == Compiler.dart2bytecode) &&
142143
configuration.runtime == Runtime.vm &&
143144
key == 'vm') {
144145
// vm tests contain both cc tests (added here) and dart tests (added

pkg/test_runner/lib/src/test_suite.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ abstract class TestSuite {
7272
'FIREFOX_PATH':
7373
Uri.base.resolve(configuration.firefoxPath!).toFilePath(),
7474
if (configuration.useQemu)
75-
'QEMU_LD_PREFIX':
76-
QemuConfig.all[configuration.architecture]!
77-
.elfInterpreterPrefix,
75+
'QEMU_LD_PREFIX': QemuConfig
76+
.all[configuration.architecture]!.elfInterpreterPrefix,
7877
};
7978

8079
Map<String, String> get environmentOverrides => _environmentOverrides;
@@ -353,6 +352,7 @@ class VMTestSuite extends TestSuite {
353352
if (expectations.contains(Expectation.crash)) '--suppress-core-dump',
354353
if (experiments.isNotEmpty)
355354
'--enable-experiment=${experiments.join(",")}',
355+
if (configuration.compiler == Compiler.dart2bytecode) '--interpreter',
356356
...configuration.standardOptions,
357357
...configuration.vmOptions,
358358
test.name

runtime/bin/dart_api_win.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ typedef Dart_Handle (*Dart_LookupLibraryType)(Dart_Handle);
376376
typedef Dart_Handle (*Dart_LibraryHandleErrorType)(Dart_Handle, Dart_Handle);
377377
typedef Dart_Handle (*Dart_LoadLibraryFromKernelType)(const uint8_t*, intptr_t);
378378
typedef Dart_Handle (*Dart_LoadLibraryType)(Dart_Handle);
379+
typedef Dart_Handle (*Dart_LoadLibraryFromBytecodeType)(Dart_Handle);
379380
typedef Dart_Handle (*Dart_FinalizeLoadingType)(bool);
380381
typedef Dart_Handle (*Dart_GetPeerType)(Dart_Handle, void**);
381382
typedef Dart_Handle (*Dart_SetPeerType)(Dart_Handle, void*);
@@ -714,6 +715,7 @@ static Dart_LookupLibraryType Dart_LookupLibraryFn = NULL;
714715
static Dart_LibraryHandleErrorType Dart_LibraryHandleErrorFn = NULL;
715716
static Dart_LoadLibraryFromKernelType Dart_LoadLibraryFromKernelFn = NULL;
716717
static Dart_LoadLibraryType Dart_LoadLibraryFn = NULL;
718+
static Dart_LoadLibraryFromBytecodeType Dart_LoadLibraryFromBytecodeFn = NULL;
717719
static Dart_FinalizeLoadingType Dart_FinalizeLoadingFn = NULL;
718720
static Dart_GetPeerType Dart_GetPeerFn = NULL;
719721
static Dart_SetPeerType Dart_SetPeerFn = NULL;
@@ -1270,6 +1272,9 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
12701272
process, "Dart_LoadLibraryFromKernel");
12711273
Dart_LoadLibraryFn =
12721274
(Dart_LoadLibraryType)GetProcAddress(process, "Dart_LoadLibrary");
1275+
Dart_LoadLibraryFromBytecodeFn =
1276+
(Dart_LoadLibraryFromBytecodeType)GetProcAddress(
1277+
process, "Dart_LoadLibraryFromBytecode");
12731278
Dart_FinalizeLoadingFn = (Dart_FinalizeLoadingType)GetProcAddress(
12741279
process, "Dart_FinalizeLoading");
12751280
Dart_GetPeerFn = (Dart_GetPeerType)GetProcAddress(process, "Dart_GetPeer");
@@ -2469,6 +2474,10 @@ Dart_Handle Dart_LoadLibrary(Dart_Handle kernel_buffer) {
24692474
return Dart_LoadLibraryFn(kernel_buffer);
24702475
}
24712476

2477+
Dart_Handle Dart_LoadLibraryFromBytecode(Dart_Handle bytecode_buffer) {
2478+
return Dart_LoadLibraryFromBytecodeFn(bytecode_buffer);
2479+
}
2480+
24722481
Dart_Handle Dart_FinalizeLoading(bool complete_futures) {
24732482
return Dart_FinalizeLoadingFn(complete_futures);
24742483
}

runtime/include/dart_api.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3746,6 +3746,17 @@ Dart_LoadLibraryFromKernel(const uint8_t* kernel_buffer,
37463746
DART_EXPORT DART_API_WARN_UNUSED_RESULT Dart_Handle
37473747
Dart_LoadLibrary(Dart_Handle kernel_buffer);
37483748

3749+
/**
3750+
* Called by the embedder to load a partial program. Does not set the root
3751+
* library.
3752+
*
3753+
* \param bytecode_buffer An external typed data containing bytecode binary.
3754+
*
3755+
* \return A handle to the main library of the compilation unit, or an error.
3756+
*/
3757+
DART_EXPORT DART_API_WARN_UNUSED_RESULT Dart_Handle
3758+
Dart_LoadLibraryFromBytecode(Dart_Handle bytecode_buffer);
3759+
37493760
/**
37503761
* Indicates that all outstanding load requests have been satisfied.
37513762
* This finalizes all the new classes loaded and optionally completes

runtime/tests/vm/dart/exported_symbols_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ main() {
231231
"Dart_ListSetAt",
232232
"Dart_LoadingUnitLibraryUris",
233233
"Dart_LoadLibrary",
234+
"Dart_LoadLibraryFromBytecode",
234235
"Dart_LoadLibraryFromKernel",
235236
"Dart_LoadScriptFromBytecode",
236237
"Dart_LoadScriptFromKernel",

runtime/vm/dart_api_impl.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5845,6 +5845,29 @@ DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle kernel_buffer) {
58455845
#endif // defined(DART_PRECOMPILED_RUNTIME)
58465846
}
58475847

5848+
DART_EXPORT Dart_Handle
5849+
Dart_LoadLibraryFromBytecode(Dart_Handle bytecode_buffer) {
5850+
#if defined(DART_DYNAMIC_MODULES)
5851+
DARTSCOPE(Thread::Current());
5852+
const ExternalTypedData& td =
5853+
Api::UnwrapExternalTypedDataHandle(Z, bytecode_buffer);
5854+
if (td.IsNull()) {
5855+
RETURN_TYPE_ERROR(Z, bytecode_buffer, ExternalTypedData);
5856+
}
5857+
SafepointWriteRwLocker ml(T, T->isolate_group()->program_lock());
5858+
bytecode::BytecodeLoader loader(T, td);
5859+
const Function& function = Function::Handle(loader.LoadBytecode());
5860+
if (function.IsNull()) {
5861+
return Api::Null();
5862+
}
5863+
return Api::NewHandle(T, Class::Handle(function.Owner()).library());
5864+
#else
5865+
return Api::NewError(
5866+
"%s: Cannot load bytecode as dynamic modules are disabled.",
5867+
CURRENT_FUNC);
5868+
#endif // defined(DART_DYNAMIC_MODULES)
5869+
}
5870+
58485871
// Finalizes classes and invokes Dart core library function that completes
58495872
// futures of loadLibrary calls (deferred library loading).
58505873
DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) {

runtime/vm/unit_test.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,9 @@ Dart_Handle TestCase::LoadTestLibrary(const char* lib_uri,
456456
kernel_buffer_size, const_cast<uint8_t*>(kernel_buffer),
457457
kernel_buffer_size, MallocFinalizer);
458458
EXPECT_VALID(td);
459-
Dart_Handle lib = Dart_LoadLibrary(td);
459+
Dart_Handle lib = Dart_IsBytecode(kernel_buffer, kernel_buffer_size)
460+
? Dart_LoadLibraryFromBytecode(td)
461+
: Dart_LoadLibrary(td);
460462
EXPECT_VALID(lib);
461463

462464
// TODO(32618): Kernel doesn't correctly represent the root library.
@@ -495,7 +497,9 @@ Dart_Handle TestCase::LoadTestScriptWithDFE(int sourcefiles_count,
495497
kernel_buffer_size, const_cast<uint8_t*>(kernel_buffer),
496498
kernel_buffer_size, MallocFinalizer);
497499
EXPECT_VALID(td);
498-
Dart_Handle lib = Dart_LoadLibrary(td);
500+
Dart_Handle lib = Dart_IsBytecode(kernel_buffer, kernel_buffer_size)
501+
? Dart_LoadLibraryFromBytecode(td)
502+
: Dart_LoadLibrary(td);
499503
EXPECT_VALID(lib);
500504

501505
// BOGUS: Kernel doesn't correctly represent the root library.

tools/bots/test_matrix.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,7 @@
13241324
"-nvm-dyn-${system}-${mode}-${arch}",
13251325
"corelib",
13261326
"language",
1327+
"vm",
13271328
"pkg/vm_service/"
13281329
],
13291330
"fileset": "vm",

0 commit comments

Comments
 (0)