diff --git a/runtime/tests/vm/dart/ama_test.dart b/runtime/tests/vm/dart/ama_test.dart new file mode 100644 index 00000000000..dd70e475f4f --- /dev/null +++ b/runtime/tests/vm/dart/ama_test.dart @@ -0,0 +1,69 @@ +// Copyright (c) 2023, 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. + +import "dart:io"; + +import 'package:expect/expect.dart'; +import 'package:native_stack_traces/elf.dart'; +import 'package:path/path.dart' as path; + +import 'use_flag_test_helper.dart'; + +main(List args) async { + if (!isAOTRuntime) { + print('Skipping test due to AOT runtime not being available'); + return; // Running in JIT: AOT binaries not available. + } + + if (Platform.isAndroid) { + print('Skipping test due to being on Android where needed tools are not ' + 'available.'); + return; // SDK tree and gen_snapshot not available on the test device. + } + + // These are the tools we need to be available to run on a given platform: + if (!await testExecutable(genSnapshot)) { + throw "Cannot run test as $genSnapshot not available"; + } + if (!await testExecutable(dartPrecompiledRuntime)) { + throw "Cannot run test as $dartPrecompiledRuntime not available"; + } + if (!File(platformDill).existsSync()) { + throw "Cannot run test as $platformDill does not exist"; + } + + await withElfSnapshot((Elf elf) { + // NOTE: These tests validate properties we should strive to maintain. + // Please reach out to go/dart-ama before changing them. + final Symbol? symbol = + elf.dynamicSymbolFor('_kDartIsolateSnapshotInstructions'); + Expect.isTrue(symbol != null && symbol.value > 0); + }); +} + +Future withElfSnapshot(Function(Elf) fun) async { + await withTempDir('ama-test', (String tempDir) async { + final scriptDart = path.join(tempDir, 'script.dart'); + final scriptDill = path.join(tempDir, 'script.dill'); + final scriptElf = path.join(tempDir, 'script.elf'); + File(scriptDart).writeAsStringSync('main() => print("script");'); + + await run(genKernel, [ + '--aot', + '--platform=$platformDill', + '-o', + scriptDill, + scriptDart, + ]); + + await run(genSnapshot, [ + '--snapshot-kind=app-aot-elf', + '--elf=$scriptElf', + scriptDill, + ]); + + final elf = Elf.fromFile(scriptElf)!; + await fun(elf); + }); +} diff --git a/runtime/vm/ama_test.cc b/runtime/vm/ama_test.cc new file mode 100644 index 00000000000..edecd862644 --- /dev/null +++ b/runtime/vm/ama_test.cc @@ -0,0 +1,26 @@ +// Copyright (c) 2023, 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. + +#include "platform/assert.h" +#include "platform/globals.h" + +#include "include/dart_api.h" + +#include "vm/constants.h" +#include "vm/unit_test.h" + +namespace dart { + +TEST_CASE(AMA_Test) { + // NOTE: These are expectations we should strive to maintain. Please reach out + // to go/dart-ama before changing them. +#if defined(TARGET_ARCH_ARM64) + COMPILE_ASSERT(R27 == PP); + COMPILE_ASSERT(R15 == SPREG); + COMPILE_ASSERT(R26 == THR); + COMPILE_ASSERT(R21 == DISPATCH_TABLE_REG); +#endif +} + +} // namespace dart diff --git a/runtime/vm/vm_sources.gni b/runtime/vm/vm_sources.gni index edced357b81..e300215802e 100644 --- a/runtime/vm/vm_sources.gni +++ b/runtime/vm/vm_sources.gni @@ -385,6 +385,7 @@ vm_sources = [ vm_sources_tests = [ "allocation_test.cc", + "ama_test.cc", "assert_test.cc", "atomic_test.cc", "base64_test.cc",