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

Side by Side Diff: vm/debugger_api_impl_test.cc

Issue 11052006: 1. Create a port when a debugger object is created for an isolate, use this (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 2 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_debugger_api.h" 5 #include "include/dart_debugger_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "vm/dart_api_impl.h" 7 #include "vm/dart_api_impl.h"
8 #include "vm/thread.h"
8 #include "vm/unit_test.h" 9 #include "vm/unit_test.h"
9 10
10 namespace dart { 11 namespace dart {
11 12
12 // Only ia32 and x64 can run execution tests. 13 // Only ia32 and x64 can run execution tests.
13 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) 14 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
14 15
15 static bool breakpoint_hit = false; 16 static bool breakpoint_hit = false;
16 static int breakpoint_hit_counter = 0; 17 static int breakpoint_hit_counter = 0;
17 static Dart_Handle script_lib = NULL; 18 static Dart_Handle script_lib = NULL;
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 lib_list = Dart_GetLibraryURLs(); 1033 lib_list = Dart_GetLibraryURLs();
1033 EXPECT_VALID(lib_list); 1034 EXPECT_VALID(lib_list);
1034 EXPECT(Dart_IsList(lib_list)); 1035 EXPECT(Dart_IsList(lib_list));
1035 list_as_string = Dart_ToString(lib_list); 1036 list_as_string = Dart_ToString(lib_list);
1036 list_cstr = ""; 1037 list_cstr = "";
1037 EXPECT_VALID(Dart_StringToCString(list_as_string, &list_cstr)); 1038 EXPECT_VALID(Dart_StringToCString(list_as_string, &list_cstr));
1038 EXPECT_SUBSTRING(TestCase::url(), list_cstr); 1039 EXPECT_SUBSTRING(TestCase::url(), list_cstr);
1039 } 1040 }
1040 1041
1041 1042
1043 static Dart_IsolateId test_isolate_id = ILLEGAL_ISOLATE_ID;
1044 static void TestIsolateID(Dart_IsolateId isolate_id, Dart_IsolateEvent kind) {
1045 if (kind == kCreated) {
1046 EXPECT(test_isolate_id == ILLEGAL_ISOLATE_ID);
1047 test_isolate_id = isolate_id;
1048 Dart_Isolate isolate = Dart_GetIsolate(isolate_id);
1049 EXPECT(isolate == Dart_CurrentIsolate());
1050 } else if (kind == kInterrupted) {
1051 EXPECT(test_isolate_id == isolate_id);
1052 Dart_Isolate isolate = Dart_GetIsolate(isolate_id);
1053 EXPECT(isolate == Dart_CurrentIsolate());
1054 } else if (kind == kShutdown) {
1055 EXPECT(test_isolate_id == isolate_id);
1056 Dart_Isolate isolate = Dart_GetIsolate(isolate_id);
1057 EXPECT(isolate == Dart_CurrentIsolate());
1058 }
1059 }
1060
1061
1062 UNIT_TEST_CASE(Debug_IsolateID) {
1063 const char* kScriptChars =
1064 "void moo(s) { } \n"
1065 "class A { \n"
1066 " static void foo() { \n"
1067 " moo('good news'); \n"
1068 " } \n"
1069 "} \n"
1070 "void main() { \n"
1071 " A.foo(); \n"
1072 "} \n";
1073
1074 Dart_SetIsolateEventHandler(&TestIsolateID);
1075 Dart_Isolate isolate = TestCase::CreateTestIsolate();
1076 ASSERT(isolate != NULL);
1077 Dart_EnterScope();
1078 LoadScript(kScriptChars);
1079 Dart_Handle retval = Invoke("main");
1080 EXPECT_VALID(retval);
hausner 2012/10/03 18:53:13 Maybe check that test_isolate_id contains a value
siva 2012/10/03 23:59:45 Done.
1081 Dart_ExitScope();
1082 Dart_ShutdownIsolate();
1083 }
1084
1085
1086 static Monitor* sync = NULL;
1087 static bool isolate_interrupted = false;
1088 static Dart_IsolateId interrupt_isolate_id = ILLEGAL_ISOLATE_ID;
1089 static volatile bool continue_isolate_loop = true;
1090
1091
1092 static void TestInterruptIsolate(Dart_IsolateId isolate_id,
1093 Dart_IsolateEvent kind) {
1094 if (kind == kCreated) {
1095 EXPECT(interrupt_isolate_id == ILLEGAL_ISOLATE_ID);
1096 // Indicate that the isolate has been created.
1097 {
1098 MonitorLocker ml(sync);
1099 interrupt_isolate_id = isolate_id;
1100 ml.Notify();
1101 }
1102 } else if (kind == kInterrupted) {
1103 // Indicate that isolate has been interrupted.
1104 {
1105 MonitorLocker ml(sync);
1106 isolate_interrupted = true;
1107 continue_isolate_loop = false;
1108 ml.Notify();
1109 }
1110 } else if (kind == kShutdown) {
1111 if (interrupt_isolate_id == isolate_id) {
1112 MonitorLocker ml(sync);
1113 interrupt_isolate_id = ILLEGAL_ISOLATE_ID;
1114 ml.Notify();
1115 }
1116 }
1117 }
1118
1119
1120 static void InterruptNativeFunction(Dart_NativeArguments args) {
1121 Dart_EnterScope();
1122 Dart_Handle val = Dart_NewBoolean(continue_isolate_loop);
1123 Dart_SetReturnValue(args, val);
1124 Dart_ExitScope();
1125 }
1126
1127
1128 static Dart_NativeFunction InterruptNativeResolver(Dart_Handle name,
1129 int arg_count) {
1130 return &InterruptNativeFunction;
1131 }
1132
1133
1134 void InterruptIsolateRun(uword unused) {
Ivan Posva 2012/10/03 20:18:57 static?
siva 2012/10/03 23:59:45 Done.
1135 const char* kScriptChars =
1136 "void moo(s) { } \n"
1137 "class A { \n"
1138 " static check() native 'a'; \n"
1139 " static void foo() { \n"
1140 " var loop = true; \n"
1141 " while (loop) { \n"
1142 " moo('good news'); \n"
1143 " loop = check(); \n"
1144 " } \n"
1145 " } \n"
1146 "} \n"
1147 "void main() { \n"
1148 " A.foo(); \n"
1149 "} \n";
1150
1151 Dart_Isolate isolate = TestCase::CreateTestIsolate();
1152 ASSERT(isolate != NULL);
1153 Dart_EnterScope();
1154 LoadScript(kScriptChars);
1155
1156 Dart_Handle result = Dart_SetNativeResolver(script_lib,
1157 &InterruptNativeResolver);
1158 EXPECT_VALID(result);
1159
1160 Dart_Handle retval = Invoke("main");
1161 EXPECT_VALID(retval);
1162 Dart_ExitScope();
1163 Dart_ShutdownIsolate();
1164 }
1165
1166
1167 TEST_CASE(Debug_InterruptIsolate) {
1168 Dart_SetIsolateEventHandler(&TestInterruptIsolate);
1169 sync = new Monitor();
1170 EXPECT(interrupt_isolate_id == ILLEGAL_ISOLATE_ID);
1171 int result = Thread::Start(InterruptIsolateRun, 0);
1172 EXPECT_EQ(0, result);
1173
1174 // Wait for the test isolate to be created.
1175 {
1176 MonitorLocker ml(sync);
1177 while (interrupt_isolate_id == ILLEGAL_ISOLATE_ID) {
1178 ml.Wait();
1179 }
1180 }
1181 EXPECT(interrupt_isolate_id != ILLEGAL_ISOLATE_ID);
1182
1183 Dart_Isolate isolate = Dart_GetIsolate(interrupt_isolate_id);
1184 EXPECT(isolate != NULL);
1185 Dart_InterruptIsolate(isolate);
1186
1187 // Wait for the test isolate to be interrupted.
1188 {
1189 MonitorLocker ml(sync);
1190 while (!isolate_interrupted) {
1191 ml.Wait();
1192 }
1193 }
1194 EXPECT(isolate_interrupted);
1195
1196 // Wait for the test isolate to shutdown.
1197 {
1198 MonitorLocker ml(sync);
1199 while (interrupt_isolate_id != ILLEGAL_ISOLATE_ID) {
1200 ml.Wait();
1201 }
1202 }
1203 EXPECT(interrupt_isolate_id == ILLEGAL_ISOLATE_ID);
1204 }
1205
1042 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 1206 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
1043 1207
1044 } // namespace dart 1208 } // namespace dart
OLDNEW
« vm/debugger.h ('K') | « vm/debugger_api_impl.cc ('k') | vm/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698