Files
sdk/runtime/vm/isolate_test.cc
T
zra@google.com 2fe51715e5 Begins work on ARM64, first assembler test.
Most new code is in constants_arm64.h and
{assembler,disassembler,simulator}_arm64.{h,cc}

The rest of the CL just #def's out tests, modifies status files,
and adds UNIMPLEMENTED functions, etc.

R=regis@google.com

Review URL: https://codereview.chromium.org//221133002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@34654 260f80e4-7a28-3924-810f-c04153c831b5
2014-04-02 17:39:32 +00:00

89 lines
3.0 KiB
C++

// Copyright (c) 2012, 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.
// TODO(zra): Remove when tests are ready to enable.
#include "platform/globals.h"
#if !defined(TARGET_ARCH_ARM64)
#include "platform/assert.h"
#include "vm/globals.h"
#include "vm/isolate.h"
#include "vm/unit_test.h"
namespace dart {
UNIT_TEST_CASE(IsolateCurrent) {
Isolate* isolate = Isolate::Init(NULL);
EXPECT_EQ(isolate, Isolate::Current());
isolate->Shutdown();
EXPECT_EQ(reinterpret_cast<Isolate*>(NULL), Isolate::Current());
delete isolate;
}
// Test to ensure that an exception is thrown if no isolate creation
// callback has been set by the embedder when an isolate is spawned.
TEST_CASE(IsolateSpawn) {
const char* kScriptChars =
"import 'dart:isolate';\n"
// Ignores printed lines.
"var _nullPrintClosure = (String line) {};\n"
"void entry(message) {}\n"
"int testMain() {\n"
" Isolate.spawn(entry, null);\n"
// TODO(floitsch): the following code is only to bump the event loop
// so it executes asynchronous microtasks.
" var rp = new RawReceivePort();\n"
" rp.sendPort.send(null);\n"
" rp.handler = (_) { rp.close(); };\n"
"}\n";
Dart_Handle test_lib = TestCase::LoadTestScript(kScriptChars, NULL);
// Setup the internal library's 'internalPrint' function.
// Necessary because asynchronous errors use "print" to print their
// stack trace.
Dart_Handle url = NewString("dart:_internal");
DART_CHECK_VALID(url);
Dart_Handle internal_lib = Dart_LookupLibrary(url);
DART_CHECK_VALID(internal_lib);
Dart_Handle print = Dart_GetField(test_lib, NewString("_nullPrintClosure"));
Dart_Handle result = Dart_SetField(internal_lib,
NewString("_printClosure"),
print);
DART_CHECK_VALID(result);
// Setup the 'scheduleImmediate' closure.
url = NewString("dart:isolate");
DART_CHECK_VALID(url);
Dart_Handle isolate_lib = Dart_LookupLibrary(url);
DART_CHECK_VALID(isolate_lib);
Dart_Handle schedule_immediate_closure =
Dart_Invoke(isolate_lib, NewString("_getIsolateScheduleImmediateClosure"),
0, NULL);
Dart_Handle args[1];
args[0] = schedule_immediate_closure;
url = NewString("dart:async");
DART_CHECK_VALID(url);
Dart_Handle async_lib = Dart_LookupLibrary(url);
DART_CHECK_VALID(async_lib);
DART_CHECK_VALID(Dart_Invoke(
async_lib, NewString("_setScheduleImmediateClosure"), 1, args));
result = Dart_Invoke(test_lib, NewString("testMain"), 0, NULL);
EXPECT(!Dart_IsError(result));
// Run until all ports to isolate are closed.
result = Dart_RunLoop();
EXPECT_ERROR(result, "Null callback specified for isolate creation");
EXPECT(Dart_ErrorHasException(result));
Dart_Handle exception_result = Dart_ErrorGetException(result);
EXPECT_VALID(exception_result);
}
} // namespace dart
#endif // !defined(TARGET_ARCH_ARM64)