[vm] Add tests verifying AMA assumptions
See go/dart-ama TEST=vm/cc/AMA_Test Change-Id: If593825b7505fb8ab8ef7a74567523f43489f9be Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304960 Reviewed-by: Slava Egorov <vegorov@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com>
This commit is contained in:
committed by
Commit Queue
parent
e9b9e195a9
commit
cfcc0ca04e
@@ -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<String> 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, <String>[
|
||||
'--aot',
|
||||
'--platform=$platformDill',
|
||||
'-o',
|
||||
scriptDill,
|
||||
scriptDart,
|
||||
]);
|
||||
|
||||
await run(genSnapshot, <String>[
|
||||
'--snapshot-kind=app-aot-elf',
|
||||
'--elf=$scriptElf',
|
||||
scriptDill,
|
||||
]);
|
||||
|
||||
final elf = Elf.fromFile(scriptElf)!;
|
||||
await fun(elf);
|
||||
});
|
||||
}
|
||||
@@ -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
|
||||
@@ -385,6 +385,7 @@ vm_sources = [
|
||||
|
||||
vm_sources_tests = [
|
||||
"allocation_test.cc",
|
||||
"ama_test.cc",
|
||||
"assert_test.cc",
|
||||
"atomic_test.cc",
|
||||
"base64_test.cc",
|
||||
|
||||
Reference in New Issue
Block a user