OLD | NEW |
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 "platform/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "include/dart_tools_api.h" | 7 #include "include/dart_tools_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/clustered_snapshot.h" | 10 #include "vm/clustered_snapshot.h" |
(...skipping 1644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1655 result = Dart_Invoke(lib, NewString("test_b"), 0, NULL); | 1655 result = Dart_Invoke(lib, NewString("test_b"), 0, NULL); |
1656 EXPECT(Dart_IsError(result) == saved_enable_type_checks_mode); | 1656 EXPECT(Dart_IsError(result) == saved_enable_type_checks_mode); |
1657 Dart_ExitScope(); | 1657 Dart_ExitScope(); |
1658 } | 1658 } |
1659 Dart_ShutdownIsolate(); | 1659 Dart_ShutdownIsolate(); |
1660 free(full_snapshot); | 1660 free(full_snapshot); |
1661 free(script_snapshot); | 1661 free(script_snapshot); |
1662 } | 1662 } |
1663 | 1663 |
1664 | 1664 |
| 1665 UNIT_TEST_CASE(MismatchedSnapshotKinds) { |
| 1666 const char* kScriptChars = |
| 1667 "main() { print('Hello, world!'); }"; |
| 1668 Dart_Handle result; |
| 1669 |
| 1670 uint8_t* buffer; |
| 1671 intptr_t size; |
| 1672 intptr_t vm_isolate_snapshot_size; |
| 1673 uint8_t* isolate_snapshot = NULL; |
| 1674 intptr_t isolate_snapshot_size; |
| 1675 uint8_t* full_snapshot = NULL; |
| 1676 uint8_t* script_snapshot = NULL; |
| 1677 |
| 1678 bool saved_load_deferred_eagerly_mode = FLAG_load_deferred_eagerly; |
| 1679 FLAG_load_deferred_eagerly = true; |
| 1680 bool saved_concurrent_sweep_mode = FLAG_concurrent_sweep; |
| 1681 FLAG_concurrent_sweep = false; |
| 1682 { |
| 1683 // Start an Isolate, and create a full snapshot of it. |
| 1684 TestIsolateScope __test_isolate__; |
| 1685 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| 1686 |
| 1687 // Write out the script snapshot. |
| 1688 result = Dart_CreateSnapshot(NULL, |
| 1689 &vm_isolate_snapshot_size, |
| 1690 &isolate_snapshot, |
| 1691 &isolate_snapshot_size); |
| 1692 EXPECT_VALID(result); |
| 1693 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); |
| 1694 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); |
| 1695 Dart_ExitScope(); |
| 1696 } |
| 1697 FLAG_concurrent_sweep = saved_concurrent_sweep_mode; |
| 1698 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; |
| 1699 |
| 1700 { |
| 1701 // Create an Isolate using the full snapshot, load a script and create |
| 1702 // a script snapshot of the script. |
| 1703 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); |
| 1704 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| 1705 |
| 1706 // Create a test library and Load up a test script in it. |
| 1707 TestCase::LoadTestScript(kScriptChars, NULL); |
| 1708 |
| 1709 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(Thread::Current())); |
| 1710 |
| 1711 // Write out the script snapshot. |
| 1712 result = Dart_CreateScriptSnapshot(&buffer, &size); |
| 1713 EXPECT_VALID(result); |
| 1714 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size)); |
| 1715 memmove(script_snapshot, buffer, size); |
| 1716 Dart_ExitScope(); |
| 1717 Dart_ShutdownIsolate(); |
| 1718 } |
| 1719 |
| 1720 { |
| 1721 // Use a script snapshot where a full snapshot is expected. |
| 1722 char* error = NULL; |
| 1723 Dart_Isolate isolate = Dart_CreateIsolate("script-uri", "main", |
| 1724 script_snapshot, NULL, NULL, |
| 1725 &error); |
| 1726 EXPECT(isolate == NULL); |
| 1727 EXPECT(error != NULL); |
| 1728 EXPECT_SUBSTRING("got 'script', expected 'core'", error); |
| 1729 } |
| 1730 |
| 1731 { |
| 1732 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); |
| 1733 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
| 1734 |
| 1735 // Use a full snapshot where a script snapshot is expected. |
| 1736 Dart_Handle result = Dart_LoadScriptFromSnapshot(full_snapshot, size); |
| 1737 EXPECT_ERROR(result, "Dart_LoadScriptFromSnapshot expects parameter" |
| 1738 " 'buffer' to be a script type snapshot."); |
| 1739 |
| 1740 Dart_ExitScope(); |
| 1741 } |
| 1742 Dart_ShutdownIsolate(); |
| 1743 free(full_snapshot); |
| 1744 free(script_snapshot); |
| 1745 } |
| 1746 |
| 1747 |
1665 #endif // !PRODUCT | 1748 #endif // !PRODUCT |
1666 | 1749 |
1667 | 1750 |
1668 TEST_CASE(IntArrayMessage) { | 1751 TEST_CASE(IntArrayMessage) { |
1669 StackZone zone(Thread::Current()); | 1752 StackZone zone(Thread::Current()); |
1670 uint8_t* buffer = NULL; | 1753 uint8_t* buffer = NULL; |
1671 ApiMessageWriter writer(&buffer, &zone_allocator); | 1754 ApiMessageWriter writer(&buffer, &zone_allocator); |
1672 | 1755 |
1673 static const int kArrayLength = 2; | 1756 static const int kArrayLength = 2; |
1674 intptr_t data[kArrayLength] = {1, 2}; | 1757 intptr_t data[kArrayLength] = {1, 2}; |
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3012 StackZone zone(Thread::Current()); | 3095 StackZone zone(Thread::Current()); |
3013 uint8_t* buffer; | 3096 uint8_t* buffer; |
3014 MessageWriter writer(&buffer, &zone_allocator, true); | 3097 MessageWriter writer(&buffer, &zone_allocator, true); |
3015 writer.WriteInlinedObjectHeader(kOmittedObjectId); | 3098 writer.WriteInlinedObjectHeader(kOmittedObjectId); |
3016 // For performance, we'd like single-byte headers when ids are omitted. | 3099 // For performance, we'd like single-byte headers when ids are omitted. |
3017 // If this starts failing, consider renumbering the snapshot ids. | 3100 // If this starts failing, consider renumbering the snapshot ids. |
3018 EXPECT_EQ(1, writer.BytesWritten()); | 3101 EXPECT_EQ(1, writer.BytesWritten()); |
3019 } | 3102 } |
3020 | 3103 |
3021 } // namespace dart | 3104 } // namespace dart |
OLD | NEW |