dart-sdk/tests/standalone/check_for_aot_snapshot_jit_test.dart

102 lines
3.3 KiB
Dart
Raw Normal View History

// Copyright (c) 2020, 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:path/path.dart' as path;
final _execSuffix = Platform.isWindows ? '.exe' : '';
final _batchSuffix = Platform.isWindows ? '.bat' : '';
main() {
final buildDir = path.dirname(Platform.executable);
final sdkDir = path.dirname(path.dirname(buildDir));
final platformDill = path.join(buildDir, 'vm_platform_strong.dill');
final genKernel =
path.join(sdkDir, 'pkg', 'vm', 'tool', 'gen_kernel$_batchSuffix');
Expect.isTrue(File(genKernel).existsSync(),
"Can't locate gen_kernel$_batchSuffix on this platform");
Expect.isTrue(File(genKernel).existsSync(),
"Can't locate gen_kernel$_batchSuffix on this platform");
final genSnapshot = path.join(buildDir, 'gen_snapshot$_execSuffix');
Expect.isTrue(File(genSnapshot).existsSync(),
"Can't locate gen_snapshot$_execSuffix on this platform");
final exePath = path.join(buildDir, 'dart$_execSuffix');
Expect.isTrue(File(exePath).existsSync(),
"Can't locate dart$_execSuffix on this platform");
final powTest = path.join(sdkDir, 'tests', 'standalone', 'pow_test.dart');
Expect.isTrue(File(powTest).existsSync(),
"Can't locate dart$_execSuffix on this platform");
final d = Directory.systemTemp.createTempSync('aot_tmp');
final kernelOutput = File.fromUri(d.uri.resolve('pow_test.dill')).path;
final aotOutput = File.fromUri(d.uri.resolve('pow_test.aot')).path;
[vm] Consolidate the *WriteStream hierarchy. All *WriteStream classes are now part of the same hierarchy: class BaseWriteStream : ValueObject; Base class for all *WriteStreams. Provides all the methods from the old WriteStream except for buffer() and SetPosition() (relegated to NonStreamingWriteStreams). Has one pure virtual method Realloc that must be overridden by concrete subclasses. class NonStreamingWriteStream : BaseWriteStream; Base class for all *WriteStreams where the entire stream is available at all times (i.e., no flushing to an external sink). Extends the public BaseWriteStream API with buffer() (for accessing the stream contents) and SetPosition() (for changing the current stream pointer to the given absolute position in the stream). class MallocWriteStream : NonStreamingWriteStream; Uses realloc to reallocate the internal buffer. Almost the same as the old WriteStream, except that it only takes an initial size. Adds one public method Steal() for taking ownership of the current buffer contents (after which the buffer is reset to an empty state). Instead of passing a pointer to a buffer, the internal buffer must be accessed via either Steal() or buffer(), which allows access to the current stream contents without changing ownership or resetting the stream. The internal buffer is freed on stream destruction. class ZoneWriteStream: NonStreamingWriteStream; Takes a zone and reallocates the internal buffer in that zone. No additional public methods beyond those available from NonStreamingWriteStream. class StreamingWriteStream : BaseWriteStream; Uses realloc to reallocate the internal buffer. Generally same as before, where the contents of the stream are periodically flushed using Dart_StreamingWriteCallback. Since it extends BaseWriteStream, there are now more methods available for writing data to the stream than just Print/VPrint/WriteBytes. Since portions of the stream may be flushed and thus no longer in the internal buffer, does not provide access to the contents of the stream or a way to reposition the current stream pointer. Flushes any unflushed data and frees the internal buffer on stream destruction. Also refactor things so that write streams are passed to appropriate recipients, instead of the recipients taking arguments they only used to create a WriteStream internally. Thus, recipients now can just specify the appropriate base class for the public API used: * BaseWriteStream for just writing to the stream, or * NonStreamingWriteStream if re-positioning or the stream contents are needed. Change-Id: I419096ecd9331483d168b079fca55b69ef397f15 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164080 Commit-Queue: Tess Strickland <sstrickl@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-09-23 21:05:59 +00:00
final genKernelResult = runAndPrintOutput(
genKernel,
[
'--aot',
'--platform=$platformDill',
'-o',
kernelOutput,
powTest,
],
);
Expect.equals(genKernelResult.exitCode, 0);
[vm] Consolidate the *WriteStream hierarchy. All *WriteStream classes are now part of the same hierarchy: class BaseWriteStream : ValueObject; Base class for all *WriteStreams. Provides all the methods from the old WriteStream except for buffer() and SetPosition() (relegated to NonStreamingWriteStreams). Has one pure virtual method Realloc that must be overridden by concrete subclasses. class NonStreamingWriteStream : BaseWriteStream; Base class for all *WriteStreams where the entire stream is available at all times (i.e., no flushing to an external sink). Extends the public BaseWriteStream API with buffer() (for accessing the stream contents) and SetPosition() (for changing the current stream pointer to the given absolute position in the stream). class MallocWriteStream : NonStreamingWriteStream; Uses realloc to reallocate the internal buffer. Almost the same as the old WriteStream, except that it only takes an initial size. Adds one public method Steal() for taking ownership of the current buffer contents (after which the buffer is reset to an empty state). Instead of passing a pointer to a buffer, the internal buffer must be accessed via either Steal() or buffer(), which allows access to the current stream contents without changing ownership or resetting the stream. The internal buffer is freed on stream destruction. class ZoneWriteStream: NonStreamingWriteStream; Takes a zone and reallocates the internal buffer in that zone. No additional public methods beyond those available from NonStreamingWriteStream. class StreamingWriteStream : BaseWriteStream; Uses realloc to reallocate the internal buffer. Generally same as before, where the contents of the stream are periodically flushed using Dart_StreamingWriteCallback. Since it extends BaseWriteStream, there are now more methods available for writing data to the stream than just Print/VPrint/WriteBytes. Since portions of the stream may be flushed and thus no longer in the internal buffer, does not provide access to the contents of the stream or a way to reposition the current stream pointer. Flushes any unflushed data and frees the internal buffer on stream destruction. Also refactor things so that write streams are passed to appropriate recipients, instead of the recipients taking arguments they only used to create a WriteStream internally. Thus, recipients now can just specify the appropriate base class for the public API used: * BaseWriteStream for just writing to the stream, or * NonStreamingWriteStream if re-positioning or the stream contents are needed. Change-Id: I419096ecd9331483d168b079fca55b69ef397f15 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164080 Commit-Queue: Tess Strickland <sstrickl@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-09-23 21:05:59 +00:00
print("Ran successfully.\n");
[vm] Consolidate the *WriteStream hierarchy. All *WriteStream classes are now part of the same hierarchy: class BaseWriteStream : ValueObject; Base class for all *WriteStreams. Provides all the methods from the old WriteStream except for buffer() and SetPosition() (relegated to NonStreamingWriteStreams). Has one pure virtual method Realloc that must be overridden by concrete subclasses. class NonStreamingWriteStream : BaseWriteStream; Base class for all *WriteStreams where the entire stream is available at all times (i.e., no flushing to an external sink). Extends the public BaseWriteStream API with buffer() (for accessing the stream contents) and SetPosition() (for changing the current stream pointer to the given absolute position in the stream). class MallocWriteStream : NonStreamingWriteStream; Uses realloc to reallocate the internal buffer. Almost the same as the old WriteStream, except that it only takes an initial size. Adds one public method Steal() for taking ownership of the current buffer contents (after which the buffer is reset to an empty state). Instead of passing a pointer to a buffer, the internal buffer must be accessed via either Steal() or buffer(), which allows access to the current stream contents without changing ownership or resetting the stream. The internal buffer is freed on stream destruction. class ZoneWriteStream: NonStreamingWriteStream; Takes a zone and reallocates the internal buffer in that zone. No additional public methods beyond those available from NonStreamingWriteStream. class StreamingWriteStream : BaseWriteStream; Uses realloc to reallocate the internal buffer. Generally same as before, where the contents of the stream are periodically flushed using Dart_StreamingWriteCallback. Since it extends BaseWriteStream, there are now more methods available for writing data to the stream than just Print/VPrint/WriteBytes. Since portions of the stream may be flushed and thus no longer in the internal buffer, does not provide access to the contents of the stream or a way to reposition the current stream pointer. Flushes any unflushed data and frees the internal buffer on stream destruction. Also refactor things so that write streams are passed to appropriate recipients, instead of the recipients taking arguments they only used to create a WriteStream internally. Thus, recipients now can just specify the appropriate base class for the public API used: * BaseWriteStream for just writing to the stream, or * NonStreamingWriteStream if re-positioning or the stream contents are needed. Change-Id: I419096ecd9331483d168b079fca55b69ef397f15 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164080 Commit-Queue: Tess Strickland <sstrickl@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-09-23 21:05:59 +00:00
final genAotResult = runAndPrintOutput(
genSnapshot,
[
'--snapshot_kind=app-aot-elf',
'--elf=$aotOutput',
kernelOutput,
],
);
Expect.equals(genAotResult.exitCode, 0);
[vm] Consolidate the *WriteStream hierarchy. All *WriteStream classes are now part of the same hierarchy: class BaseWriteStream : ValueObject; Base class for all *WriteStreams. Provides all the methods from the old WriteStream except for buffer() and SetPosition() (relegated to NonStreamingWriteStreams). Has one pure virtual method Realloc that must be overridden by concrete subclasses. class NonStreamingWriteStream : BaseWriteStream; Base class for all *WriteStreams where the entire stream is available at all times (i.e., no flushing to an external sink). Extends the public BaseWriteStream API with buffer() (for accessing the stream contents) and SetPosition() (for changing the current stream pointer to the given absolute position in the stream). class MallocWriteStream : NonStreamingWriteStream; Uses realloc to reallocate the internal buffer. Almost the same as the old WriteStream, except that it only takes an initial size. Adds one public method Steal() for taking ownership of the current buffer contents (after which the buffer is reset to an empty state). Instead of passing a pointer to a buffer, the internal buffer must be accessed via either Steal() or buffer(), which allows access to the current stream contents without changing ownership or resetting the stream. The internal buffer is freed on stream destruction. class ZoneWriteStream: NonStreamingWriteStream; Takes a zone and reallocates the internal buffer in that zone. No additional public methods beyond those available from NonStreamingWriteStream. class StreamingWriteStream : BaseWriteStream; Uses realloc to reallocate the internal buffer. Generally same as before, where the contents of the stream are periodically flushed using Dart_StreamingWriteCallback. Since it extends BaseWriteStream, there are now more methods available for writing data to the stream than just Print/VPrint/WriteBytes. Since portions of the stream may be flushed and thus no longer in the internal buffer, does not provide access to the contents of the stream or a way to reposition the current stream pointer. Flushes any unflushed data and frees the internal buffer on stream destruction. Also refactor things so that write streams are passed to appropriate recipients, instead of the recipients taking arguments they only used to create a WriteStream internally. Thus, recipients now can just specify the appropriate base class for the public API used: * BaseWriteStream for just writing to the stream, or * NonStreamingWriteStream if re-positioning or the stream contents are needed. Change-Id: I419096ecd9331483d168b079fca55b69ef397f15 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164080 Commit-Queue: Tess Strickland <sstrickl@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-09-23 21:05:59 +00:00
print("Ran successfully.\n");
final runAotDirectlyResult = runAndPrintOutput(
exePath,
[
aotOutput,
],
);
Expect.equals(runAotDirectlyResult.exitCode, 255);
Expect.contains(
"pow_test.aot is an AOT snapshot and should be run with 'dartaotruntime'",
runAotDirectlyResult.stderr);
print('Got expected error result.');
final runAotUsingCommandResult = runAndPrintOutput(
exePath,
[
'run',
aotOutput,
],
);
Expect.equals(runAotUsingCommandResult.exitCode, 255);
Reland "Tweak `expect.dart` library." This reverts commit cd2c566bcf2263e93bef877443a784f3afe35549. Reason for revert: Updating to not remove field used by Flutter engine. Original change's description: > Revert "Tweak `expect.dart` library." > > This reverts commit ff5f391c0a0247f449a959797ecf6e10ba950da2. > > Reason for revert: The expect library is used by Flutter engine, and some of its tests use assertStatementsEnabled. There should be a migration path that doesn't require an atomic change, like adding the replacement api before removing the old one. > > Original change's description: > > Tweak `expect.dart` library. > > > > Make API more consistent for a few methods. > > Reduce the number of language features used in tests: > > * Never iterating an iterable, always converting it > > using `.toList()` first and iterating using indices > > (fx `setEquals`). > > Also require a `List` in places where an `Iterable` > > wasn't necessary. > > * Avoid doing complicated computations that are also > > used for the error message. Do simple check first, > > then recompute to get better error messages > > (fx `allDistinct`). > > > > Renamed some rarely used members for consistency > > (`stringContainsInOrder`->`containsInOrder`, > > where other string-contains functions just start > > with `contains`, and `containsOneOf` -> `containsAny` > > to match `Iterable.any` phrasing, and also it accepts > > if containing at least one, not precisely one.) > > > > Removed a function that wasn't used anywhere. > > > > Moved `assertStatementsEnabled` to `variations.dart` as `asserts`. > > Removed `typeAssertionsEnabled` and `checkedModeEnabled`. The former used in one place, where it was replaced with `checkedImplicitDowncasts` from `variations.dart`, the latter wasn't used anywhere. > > > > Deprecates `package:expect/minitest.dart`. It was never intended > > to be used for new tests, only as a help to convert existing tests > > written against `package:unit_test`. > > All existing imports marked as `// ignore: deprecated_member_use`. > > > > Change-Id: I07e21d4c0f3ccf11b82ee34af2668fdbb22264d2 > > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352360 > > Reviewed-by: Slava Egorov <vegorov@google.com> > > Reviewed-by: Ömer Ağacan <omersa@google.com> > > Reviewed-by: Nate Bosch <nbosch@google.com> > > Reviewed-by: Stephen Adams <sra@google.com> > > Commit-Queue: Lasse Nielsen <lrn@google.com> > > Change-Id: I360b4347470a0bb2b63c3108e2b83ee2a771bf3f > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362020 > Reviewed-by: Nate Bosch <nbosch@google.com> > Reviewed-by: Ömer Ağacan <omersa@google.com> > Reviewed-by: Stephen Adams <sra@google.com> > Reviewed-by: Leaf Petersen <leafp@google.com> > Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: William Hesse <whesse@google.com> CoreLibraryReviewExempt: Reland Change-Id: I53db40edc0733842a008839c3913d51c885e39ab Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362502 Reviewed-by: Alexander Thomas <athom@google.com> Reviewed-by: Nate Bosch <nbosch@google.com> Reviewed-by: Ömer Ağacan <omersa@google.com> Reviewed-by: Slava Egorov <vegorov@google.com> Reviewed-by: William Hesse <whesse@google.com> Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-04-26 15:28:26 +00:00
Expect.containsAny(<String>[
"pow_test.aot is an AOT snapshot and should be run with 'dartaotruntime'",
// If dartdev itself failed, can happen on SIMARM as not enough is built
// to run it.
"Failed to start the Dart CLI isolate",
], runAotUsingCommandResult.stderr);
[vm] Consolidate the *WriteStream hierarchy. All *WriteStream classes are now part of the same hierarchy: class BaseWriteStream : ValueObject; Base class for all *WriteStreams. Provides all the methods from the old WriteStream except for buffer() and SetPosition() (relegated to NonStreamingWriteStreams). Has one pure virtual method Realloc that must be overridden by concrete subclasses. class NonStreamingWriteStream : BaseWriteStream; Base class for all *WriteStreams where the entire stream is available at all times (i.e., no flushing to an external sink). Extends the public BaseWriteStream API with buffer() (for accessing the stream contents) and SetPosition() (for changing the current stream pointer to the given absolute position in the stream). class MallocWriteStream : NonStreamingWriteStream; Uses realloc to reallocate the internal buffer. Almost the same as the old WriteStream, except that it only takes an initial size. Adds one public method Steal() for taking ownership of the current buffer contents (after which the buffer is reset to an empty state). Instead of passing a pointer to a buffer, the internal buffer must be accessed via either Steal() or buffer(), which allows access to the current stream contents without changing ownership or resetting the stream. The internal buffer is freed on stream destruction. class ZoneWriteStream: NonStreamingWriteStream; Takes a zone and reallocates the internal buffer in that zone. No additional public methods beyond those available from NonStreamingWriteStream. class StreamingWriteStream : BaseWriteStream; Uses realloc to reallocate the internal buffer. Generally same as before, where the contents of the stream are periodically flushed using Dart_StreamingWriteCallback. Since it extends BaseWriteStream, there are now more methods available for writing data to the stream than just Print/VPrint/WriteBytes. Since portions of the stream may be flushed and thus no longer in the internal buffer, does not provide access to the contents of the stream or a way to reposition the current stream pointer. Flushes any unflushed data and frees the internal buffer on stream destruction. Also refactor things so that write streams are passed to appropriate recipients, instead of the recipients taking arguments they only used to create a WriteStream internally. Thus, recipients now can just specify the appropriate base class for the public API used: * BaseWriteStream for just writing to the stream, or * NonStreamingWriteStream if re-positioning or the stream contents are needed. Change-Id: I419096ecd9331483d168b079fca55b69ef397f15 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164080 Commit-Queue: Tess Strickland <sstrickl@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-09-23 21:05:59 +00:00
print('Got expected error result.');
}
ProcessResult runAndPrintOutput(String command, List<String> args) {
print('Running $command ${args.join(' ')}...');
final result = Process.runSync(command, args);
if (result.stdout.isNotEmpty) {
print("stdout: ");
print(result.stdout);
}
if (result.stderr.isNotEmpty) {
print("stderr: ");
print(result.stderr);
}
return result;
}