Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 9169063: Add support for native ports in the vm. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Patch Set Four Rules Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "platform/utils.h" 7 #include "platform/utils.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_api_state.h" 9 #include "vm/dart_api_state.h"
10 #include "vm/thread.h" 10 #include "vm/thread.h"
(...skipping 2730 matching lines...) Expand 10 before | Expand all | Expand 10 after
2741 2741
2742 result = Dart_InvokeStatic(result, 2742 result = Dart_InvokeStatic(result,
2743 Dart_NewString(""), 2743 Dart_NewString(""),
2744 Dart_NewString("main"), 2744 Dart_NewString("main"),
2745 0, 2745 0,
2746 NULL); 2746 NULL);
2747 EXPECT_VALID(result); 2747 EXPECT_VALID(result);
2748 } 2748 }
2749 2749
2750 2750
2751 void NewNativePort_send123(Dart_Port dest_port_id,
2752 Dart_Port reply_port_id,
2753 uint8_t* data) {
2754 intptr_t response = 123;
2755 Dart_PostIntArray(reply_port_id, 1, &response);
2756 }
2757
2758
2759 TEST_CASE(NewNativePort) {
2760 const char* kScriptChars =
2761 "void callPort(SendPort port) {\n"
2762 " port.call(null).receive((message, replyTo) {\n"
2763 " throw new Exception(message[0]);\n"
2764 " });\n"
2765 "}\n";
2766 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2767 Dart_Port port_id =
2768 Dart_NewNativePort("Port123", NewNativePort_send123, true);
siva 2012/01/28 00:21:05 For completeness should we make this test case a U
turnidge 2012/01/31 20:04:31 I don't understand why this helps. On 2012/01/28
siva 2012/02/01 00:38:56 This ties back to my comment regarding Dart_NewNat
turnidge 2012/02/01 18:51:26 I now test in both configurations.
2769
2770 Dart_Handle send_port = Dart_NewSendPort(port_id);
2771 EXPECT_VALID(send_port);
2772
2773 Dart_Handle dart_args[1];
2774 dart_args[0] = send_port;
2775 Dart_Handle result = Dart_InvokeStatic(lib,
2776 Dart_NewString(""),
2777 Dart_NewString("callPort"),
2778 1,
2779 dart_args);
2780 EXPECT_VALID(result);
2781 result = Dart_RunLoop();
2782 EXPECT(Dart_IsError(result));
2783 EXPECT(Dart_ErrorHasException(result));
2784 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result));
2785
2786 // Delete the native port.
2787 EXPECT(Dart_CloseNativePort(port_id));
2788 }
2789
2790
2751 static bool RunLoopTestCallback(const char* name_prefix, 2791 static bool RunLoopTestCallback(const char* name_prefix,
2752 void* data, char** error) { 2792 void* data, char** error) {
2753 const char* kScriptChars = 2793 const char* kScriptChars =
2754 "#import('builtin');\n" 2794 "#import('builtin');\n"
2755 "class MyIsolate extends Isolate {\n" 2795 "class MyIsolate extends Isolate {\n"
2756 " MyIsolate() : super() { }\n" 2796 " MyIsolate() : super() { }\n"
2757 " void main() {\n" 2797 " void main() {\n"
2758 " port.receive((message, replyTo) {\n" 2798 " port.receive((message, replyTo) {\n"
2759 " if (message) {\n" 2799 " if (message) {\n"
2760 " throw new Exception('MakeChildExit');\n" 2800 " throw new Exception('MakeChildExit');\n"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
2999 // We should have received the expected number of interrupts. 3039 // We should have received the expected number of interrupts.
3000 EXPECT_EQ(kInterruptCount, interrupt_count); 3040 EXPECT_EQ(kInterruptCount, interrupt_count);
3001 3041
3002 // Give the spawned thread enough time to properly exit. 3042 // Give the spawned thread enough time to properly exit.
3003 Isolate::SetInterruptCallback(saved); 3043 Isolate::SetInterruptCallback(saved);
3004 } 3044 }
3005 3045
3006 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 3046 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
3007 3047
3008 } // namespace dart 3048 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698