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

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

Issue 1130753006: Hide Isolate pointer from embedder (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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
« no previous file with comments | « runtime/vm/debugger_api_impl.cc ('k') | runtime/vm/json_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "include/dart_mirrors_api.h" 6 #include "include/dart_mirrors_api.h"
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/lockers.h" 9 #include "vm/lockers.h"
10 #include "vm/unit_test.h" 10 #include "vm/unit_test.h"
(...skipping 1336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 name_handle = Dart_ListGetAt(fields, 2); 1347 name_handle = Dart_ListGetAt(fields, 2);
1348 EXPECT_VALID(name_handle); 1348 EXPECT_VALID(name_handle);
1349 EXPECT(Dart_IsString(name_handle)); 1349 EXPECT(Dart_IsString(name_handle));
1350 Dart_StringToCString(name_handle, &name); 1350 Dart_StringToCString(name_handle, &name);
1351 EXPECT_STREQ("error", name); 1351 EXPECT_STREQ("error", name);
1352 value_handle = Dart_ListGetAt(fields, 3); 1352 value_handle = Dart_ListGetAt(fields, 3);
1353 EXPECT(Dart_IsError(value_handle)); 1353 EXPECT(Dart_IsError(value_handle));
1354 } 1354 }
1355 1355
1356 1356
1357 static Dart_IsolateId test_isolate_id = ILLEGAL_ISOLATE_ID; 1357 static Dart_IsolateId test_isolate_id = DART_ILLEGAL_ISOLATE_ID;
1358 static int verify_callback = 0; 1358 static int verify_callback = 0;
1359 static void TestIsolateID(Dart_IsolateId isolate_id, Dart_IsolateEvent kind) { 1359 static void TestIsolateID(Dart_IsolateId isolate_id, Dart_IsolateEvent kind) {
1360 if (kind == kCreated) { 1360 if (kind == kCreated) {
1361 EXPECT(test_isolate_id == ILLEGAL_ISOLATE_ID); 1361 EXPECT(test_isolate_id == DART_ILLEGAL_ISOLATE_ID);
1362 test_isolate_id = isolate_id; 1362 test_isolate_id = isolate_id;
1363 Dart_Isolate isolate = Dart_GetIsolate(isolate_id); 1363 Dart_Isolate isolate = Dart_GetIsolate(isolate_id);
1364 EXPECT(isolate == Dart_CurrentIsolate()); 1364 EXPECT(isolate == Dart_CurrentIsolate());
1365 verify_callback |= 0x1; // Register create callback. 1365 verify_callback |= 0x1; // Register create callback.
1366 } else if (kind == kInterrupted) { 1366 } else if (kind == kInterrupted) {
1367 EXPECT(test_isolate_id == isolate_id); 1367 EXPECT(test_isolate_id == isolate_id);
1368 Dart_Isolate isolate = Dart_GetIsolate(isolate_id); 1368 Dart_Isolate isolate = Dart_GetIsolate(isolate_id);
1369 EXPECT(isolate == Dart_CurrentIsolate()); 1369 EXPECT(isolate == Dart_CurrentIsolate());
1370 verify_callback |= 0x2; // Register interrupt callback. 1370 verify_callback |= 0x2; // Register interrupt callback.
1371 } else if (kind == kShutdown) { 1371 } else if (kind == kShutdown) {
(...skipping 12 matching lines...) Expand all
1384 " static void foo() { \n" 1384 " static void foo() { \n"
1385 " moo('good news'); \n" 1385 " moo('good news'); \n"
1386 " } \n" 1386 " } \n"
1387 "} \n" 1387 "} \n"
1388 "void main() { \n" 1388 "void main() { \n"
1389 " A.foo(); \n" 1389 " A.foo(); \n"
1390 "} \n"; 1390 "} \n";
1391 1391
1392 Dart_SetIsolateEventHandler(&TestIsolateID); 1392 Dart_SetIsolateEventHandler(&TestIsolateID);
1393 Dart_Isolate isolate = TestCase::CreateTestIsolate(); 1393 Dart_Isolate isolate = TestCase::CreateTestIsolate();
1394 ASSERT(isolate != NULL); 1394 ASSERT(isolate != DART_ILLEGAL_ISOLATE);
1395 Dart_EnterScope(); 1395 Dart_EnterScope();
1396 LoadScript(kScriptChars); 1396 LoadScript(kScriptChars);
1397 Dart_Handle retval = Invoke("main"); 1397 Dart_Handle retval = Invoke("main");
1398 EXPECT_VALID(retval); 1398 EXPECT_VALID(retval);
1399 EXPECT(test_isolate_id != ILLEGAL_ISOLATE_ID); 1399 EXPECT(test_isolate_id != DART_ILLEGAL_ISOLATE_ID);
1400 EXPECT(Dart_GetIsolate(test_isolate_id) == isolate); 1400 EXPECT(Dart_GetIsolate(test_isolate_id) == isolate);
1401 EXPECT(Dart_GetIsolateId(isolate) == test_isolate_id); 1401 EXPECT(Dart_GetIsolateId(isolate) == test_isolate_id);
1402 Dart_ExitScope(); 1402 Dart_ExitScope();
1403 Dart_ShutdownIsolate(); 1403 Dart_ShutdownIsolate();
1404 EXPECT(verify_callback == 0x5); // Only created and shutdown events. 1404 EXPECT(verify_callback == 0x5); // Only created and shutdown events.
1405 } 1405 }
1406 1406
1407 1407
1408 static Monitor* sync = NULL; 1408 static Monitor* sync = NULL;
1409 static bool isolate_interrupted = false; 1409 static bool isolate_interrupted = false;
1410 static bool pause_event_handled = false; 1410 static bool pause_event_handled = false;
1411 static Dart_IsolateId interrupt_isolate_id = ILLEGAL_ISOLATE_ID; 1411 static Dart_IsolateId interrupt_isolate_id = DART_ILLEGAL_ISOLATE_ID;
1412 static volatile bool continue_isolate_loop = true; 1412 static volatile bool continue_isolate_loop = true;
1413 1413
1414 1414
1415 static void InterruptIsolateHandler(Dart_IsolateId isolateId, 1415 static void InterruptIsolateHandler(Dart_IsolateId isolateId,
1416 intptr_t breakpointId, 1416 intptr_t breakpointId,
1417 const Dart_CodeLocation& location) { 1417 const Dart_CodeLocation& location) {
1418 MonitorLocker ml(sync); 1418 MonitorLocker ml(sync);
1419 pause_event_handled = true; 1419 pause_event_handled = true;
1420 ml.Notify(); 1420 ml.Notify();
1421 } 1421 }
1422 1422
1423 static void TestInterruptIsolate(Dart_IsolateId isolate_id, 1423 static void TestInterruptIsolate(Dart_IsolateId isolate_id,
1424 Dart_IsolateEvent kind) { 1424 Dart_IsolateEvent kind) {
1425 if (kind == kCreated) { 1425 if (kind == kCreated) {
1426 EXPECT(interrupt_isolate_id == ILLEGAL_ISOLATE_ID); 1426 EXPECT(interrupt_isolate_id == DART_ILLEGAL_ISOLATE_ID);
1427 // Indicate that the isolate has been created. 1427 // Indicate that the isolate has been created.
1428 { 1428 {
1429 MonitorLocker ml(sync); 1429 MonitorLocker ml(sync);
1430 interrupt_isolate_id = isolate_id; 1430 interrupt_isolate_id = isolate_id;
1431 ml.Notify(); 1431 ml.Notify();
1432 } 1432 }
1433 } else if (kind == kInterrupted) { 1433 } else if (kind == kInterrupted) {
1434 // Indicate that isolate has been interrupted. 1434 // Indicate that isolate has been interrupted.
1435 { 1435 {
1436 MonitorLocker ml(sync); 1436 MonitorLocker ml(sync);
1437 isolate_interrupted = true; 1437 isolate_interrupted = true;
1438 continue_isolate_loop = false; 1438 continue_isolate_loop = false;
1439 Dart_SetStepInto(); 1439 Dart_SetStepInto();
1440 } 1440 }
1441 } else if (kind == kShutdown) { 1441 } else if (kind == kShutdown) {
1442 if (interrupt_isolate_id == isolate_id) { 1442 if (interrupt_isolate_id == isolate_id) {
1443 MonitorLocker ml(sync); 1443 MonitorLocker ml(sync);
1444 interrupt_isolate_id = ILLEGAL_ISOLATE_ID; 1444 interrupt_isolate_id = DART_ILLEGAL_ISOLATE_ID;
1445 ml.Notify(); 1445 ml.Notify();
1446 } 1446 }
1447 } 1447 }
1448 } 1448 }
1449 1449
1450 1450
1451 static void InterruptNativeFunction(Dart_NativeArguments args) { 1451 static void InterruptNativeFunction(Dart_NativeArguments args) {
1452 Dart_EnterScope(); 1452 Dart_EnterScope();
1453 Dart_Handle val = Dart_NewBoolean(continue_isolate_loop); 1453 Dart_Handle val = Dart_NewBoolean(continue_isolate_loop);
1454 Dart_SetReturnValue(args, val); 1454 Dart_SetReturnValue(args, val);
(...skipping 21 matching lines...) Expand all
1476 " moo('good news'); \n" 1476 " moo('good news'); \n"
1477 " loop = check(); \n" 1477 " loop = check(); \n"
1478 " } \n" 1478 " } \n"
1479 " } \n" 1479 " } \n"
1480 "} \n" 1480 "} \n"
1481 "void main() { \n" 1481 "void main() { \n"
1482 " A.foo(); \n" 1482 " A.foo(); \n"
1483 "} \n"; 1483 "} \n";
1484 1484
1485 Dart_Isolate isolate = TestCase::CreateTestIsolate(); 1485 Dart_Isolate isolate = TestCase::CreateTestIsolate();
1486 ASSERT(isolate != NULL); 1486 ASSERT(isolate != DART_ILLEGAL_ISOLATE);
1487 Dart_EnterScope(); 1487 Dart_EnterScope();
1488 LoadScript(kScriptChars); 1488 LoadScript(kScriptChars);
1489 1489
1490 Dart_Handle result = Dart_SetNativeResolver(script_lib, 1490 Dart_Handle result = Dart_SetNativeResolver(script_lib,
1491 &InterruptNativeResolver, 1491 &InterruptNativeResolver,
1492 NULL); 1492 NULL);
1493 EXPECT_VALID(result); 1493 EXPECT_VALID(result);
1494 1494
1495 Dart_Handle retval = Invoke("main"); 1495 Dart_Handle retval = Invoke("main");
1496 EXPECT_VALID(retval); 1496 EXPECT_VALID(retval);
1497 Dart_ExitScope(); 1497 Dart_ExitScope();
1498 Dart_ShutdownIsolate(); 1498 Dart_ShutdownIsolate();
1499 } 1499 }
1500 1500
1501 1501
1502 TEST_CASE(Debug_InterruptIsolate) { 1502 TEST_CASE(Debug_InterruptIsolate) {
1503 Dart_SetIsolateEventHandler(&TestInterruptIsolate); 1503 Dart_SetIsolateEventHandler(&TestInterruptIsolate);
1504 sync = new Monitor(); 1504 sync = new Monitor();
1505 EXPECT(interrupt_isolate_id == ILLEGAL_ISOLATE_ID); 1505 EXPECT(interrupt_isolate_id == DART_ILLEGAL_ISOLATE_ID);
1506 Dart_SetPausedEventHandler(InterruptIsolateHandler); 1506 Dart_SetPausedEventHandler(InterruptIsolateHandler);
1507 int result = OSThread::Start(InterruptIsolateRun, 0); 1507 int result = OSThread::Start(InterruptIsolateRun, 0);
1508 EXPECT_EQ(0, result); 1508 EXPECT_EQ(0, result);
1509 1509
1510 // Wait for the test isolate to be created. 1510 // Wait for the test isolate to be created.
1511 { 1511 {
1512 MonitorLocker ml(sync); 1512 MonitorLocker ml(sync);
1513 while (interrupt_isolate_id == ILLEGAL_ISOLATE_ID) { 1513 while (interrupt_isolate_id == DART_ILLEGAL_ISOLATE_ID) {
1514 ml.Wait(); 1514 ml.Wait();
1515 } 1515 }
1516 } 1516 }
1517 EXPECT(interrupt_isolate_id != ILLEGAL_ISOLATE_ID); 1517 EXPECT(interrupt_isolate_id != DART_ILLEGAL_ISOLATE_ID);
1518 1518
1519 Dart_Isolate isolate = Dart_GetIsolate(interrupt_isolate_id); 1519 Dart_Isolate isolate = Dart_GetIsolate(interrupt_isolate_id);
1520 EXPECT(isolate != NULL); 1520 EXPECT(isolate != DART_ILLEGAL_ISOLATE);
1521 Dart_InterruptIsolate(isolate); 1521 Dart_InterruptIsolate(isolate);
1522 1522
1523 // Wait for the test isolate to be interrupted. 1523 // Wait for the test isolate to be interrupted.
1524 { 1524 {
1525 MonitorLocker ml(sync); 1525 MonitorLocker ml(sync);
1526 while (!isolate_interrupted || !pause_event_handled) { 1526 while (!isolate_interrupted || !pause_event_handled) {
1527 ml.Wait(); 1527 ml.Wait();
1528 } 1528 }
1529 } 1529 }
1530 EXPECT(isolate_interrupted); 1530 EXPECT(isolate_interrupted);
1531 EXPECT(pause_event_handled); 1531 EXPECT(pause_event_handled);
1532 1532
1533 // Wait for the test isolate to shutdown. 1533 // Wait for the test isolate to shutdown.
1534 { 1534 {
1535 MonitorLocker ml(sync); 1535 MonitorLocker ml(sync);
1536 while (interrupt_isolate_id != ILLEGAL_ISOLATE_ID) { 1536 while (interrupt_isolate_id != DART_ILLEGAL_ISOLATE_ID) {
1537 ml.Wait(); 1537 ml.Wait();
1538 } 1538 }
1539 } 1539 }
1540 EXPECT(interrupt_isolate_id == ILLEGAL_ISOLATE_ID); 1540 EXPECT(interrupt_isolate_id == DART_ILLEGAL_ISOLATE_ID);
1541 } 1541 }
1542 1542
1543 1543
1544 static void StackTraceDump1BreakpointHandler( 1544 static void StackTraceDump1BreakpointHandler(
1545 Dart_IsolateId isolate_id, 1545 Dart_IsolateId isolate_id,
1546 intptr_t bp_id, 1546 intptr_t bp_id,
1547 const Dart_CodeLocation& location) { 1547 const Dart_CodeLocation& location) {
1548 Dart_StackTrace trace; 1548 Dart_StackTrace trace;
1549 Dart_GetStackTrace(&trace); 1549 Dart_GetStackTrace(&trace);
1550 const int kStackTraceLen = 4; 1550 const int kStackTraceLen = 4;
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
2308 " null, 3, 7, 1, 8, 6, 9, 10, 10, 11, 11, 13," 2308 " null, 3, 7, 1, 8, 6, 9, 10, 10, 11, 11, 13,"
2309 " null, 4, 13, 3, 14, 10," 2309 " null, 4, 13, 3, 14, 10,"
2310 " null, 5, 17, 5, 18, 9, 19, 12," 2310 " null, 5, 17, 5, 18, 9, 19, 12,"
2311 " null, 6, 21, 1," 2311 " null, 6, 21, 1,"
2312 " null, 8, 24, 1, 25, 5, 26, 6, 27, 8," 2312 " null, 8, 24, 1, 25, 5, 26, 6, 27, 8,"
2313 " null, 9, 29, 1]", 2313 " null, 9, 29, 1]",
2314 tokens_cstr); 2314 tokens_cstr);
2315 } 2315 }
2316 2316
2317 } // namespace dart 2317 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/debugger_api_impl.cc ('k') | runtime/vm/json_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698