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

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: '' Created 8 years, 10 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 2783 matching lines...) Expand 10 before | Expand all | Expand 10 after
2794 2794
2795 result = Dart_InvokeStatic(result, 2795 result = Dart_InvokeStatic(result,
2796 Dart_NewString(""), 2796 Dart_NewString(""),
2797 Dart_NewString("main"), 2797 Dart_NewString("main"),
2798 0, 2798 0,
2799 NULL); 2799 NULL);
2800 EXPECT_VALID(result); 2800 EXPECT_VALID(result);
2801 } 2801 }
2802 2802
2803 2803
2804 void NewNativePort_send123(Dart_Port dest_port_id,
2805 Dart_Port reply_port_id,
2806 uint8_t* data) {
2807 intptr_t response = 123;
2808 Dart_PostIntArray(reply_port_id, 1, &response);
2809 }
2810
2811
2812 void NewNativePort_send321(Dart_Port dest_port_id,
2813 Dart_Port reply_port_id,
2814 uint8_t* data) {
2815 intptr_t response = 321;
2816 Dart_PostIntArray(reply_port_id, 1, &response);
2817 }
2818
2819
2820 UNIT_TEST_CASE(NewNativePort) {
2821 // Create the port w/o a current isolate, just to make sure that works.
2822 Dart_Port port_id1 =
2823 Dart_NewNativePort("Port123", NewNativePort_send123, true);
2824
2825 TestIsolateScope __test_isolate__;
2826 const char* kScriptChars =
2827 "void callPort(SendPort port) {\n"
2828 " port.call(null).receive((message, replyTo) {\n"
2829 " throw new Exception(message[0]);\n"
2830 " });\n"
2831 "}\n";
2832 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2833 Dart_EnterScope();
2834
2835 // Create a port w/ a current isolate, to make sure that works too.
2836 Dart_Port port_id2 =
2837 Dart_NewNativePort("Port321", NewNativePort_send321, true);
2838
2839 Dart_Handle send_port1 = Dart_NewSendPort(port_id1);
2840 EXPECT_VALID(send_port1);
2841 Dart_Handle send_port2 = Dart_NewSendPort(port_id2);
2842 EXPECT_VALID(send_port2);
2843
2844 // Test first port.
2845 Dart_Handle dart_args[1];
2846 dart_args[0] = send_port1;
2847 Dart_Handle result = Dart_InvokeStatic(lib,
2848 Dart_NewString(""),
2849 Dart_NewString("callPort"),
2850 1,
2851 dart_args);
2852 EXPECT_VALID(result);
2853 result = Dart_RunLoop();
2854 EXPECT(Dart_IsError(result));
2855 EXPECT(Dart_ErrorHasException(result));
2856 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result));
2857
2858 // Test second port.
2859 dart_args[0] = send_port2;
2860 result = Dart_InvokeStatic(lib,
2861 Dart_NewString(""),
2862 Dart_NewString("callPort"),
2863 1,
2864 dart_args);
2865 EXPECT_VALID(result);
2866 result = Dart_RunLoop();
2867 EXPECT(Dart_IsError(result));
2868 EXPECT(Dart_ErrorHasException(result));
2869 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result));
2870
2871 Dart_ExitScope();
2872
2873 // Delete the native ports.
2874 EXPECT(Dart_CloseNativePort(port_id1));
2875 EXPECT(Dart_CloseNativePort(port_id2));
2876 }
2877
2878
2804 static bool RunLoopTestCallback(const char* name_prefix, 2879 static bool RunLoopTestCallback(const char* name_prefix,
2805 void* data, char** error) { 2880 void* data, char** error) {
2806 const char* kScriptChars = 2881 const char* kScriptChars =
2807 "#import('builtin');\n" 2882 "#import('builtin');\n"
2808 "class MyIsolate extends Isolate {\n" 2883 "class MyIsolate extends Isolate {\n"
2809 " MyIsolate() : super() { }\n" 2884 " MyIsolate() : super() { }\n"
2810 " void main() {\n" 2885 " void main() {\n"
2811 " port.receive((message, replyTo) {\n" 2886 " port.receive((message, replyTo) {\n"
2812 " if (message) {\n" 2887 " if (message) {\n"
2813 " throw new Exception('MakeChildExit');\n" 2888 " throw new Exception('MakeChildExit');\n"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
3052 // We should have received the expected number of interrupts. 3127 // We should have received the expected number of interrupts.
3053 EXPECT_EQ(kInterruptCount, interrupt_count); 3128 EXPECT_EQ(kInterruptCount, interrupt_count);
3054 3129
3055 // Give the spawned thread enough time to properly exit. 3130 // Give the spawned thread enough time to properly exit.
3056 Isolate::SetInterruptCallback(saved); 3131 Isolate::SetInterruptCallback(saved);
3057 } 3132 }
3058 3133
3059 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 3134 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
3060 3135
3061 } // namespace dart 3136 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698