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

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

Issue 3003333002: [VM] Fix deserialization of arrays with type arguments in ApiMessageReader. (Closed)
Patch Set: Created 3 years, 4 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
« no previous file with comments | « runtime/vm/dart_api_message.cc ('k') | no next file » | 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 "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 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 EXPECT_EQ(Dart_CObject_kArray, root->type); 593 EXPECT_EQ(Dart_CObject_kArray, root->type);
594 EXPECT_EQ(kArrayLength, root->value.as_array.length); 594 EXPECT_EQ(kArrayLength, root->value.as_array.length);
595 for (int i = 0; i < kArrayLength; i++) { 595 for (int i = 0; i < kArrayLength; i++) {
596 Dart_CObject* element = root->value.as_array.values[i]; 596 Dart_CObject* element = root->value.as_array.values[i];
597 EXPECT_EQ(Dart_CObject_kInt32, element->type); 597 EXPECT_EQ(Dart_CObject_kInt32, element->type);
598 EXPECT_EQ(i, element->value.as_int32); 598 EXPECT_EQ(i, element->value.as_int32);
599 } 599 }
600 CheckEncodeDecodeMessage(root); 600 CheckEncodeDecodeMessage(root);
601 } 601 }
602 602
603 TEST_CASE(SerializeArrayWithTypeArgument) {
604 // Write snapshot with object content.
605 const int kArrayLength = 10;
606 Array& array = Array::Handle(Array::New(kArrayLength));
607
608 TypeArguments& type_args = TypeArguments::Handle();
609 type_args ^= TypeArguments::New(1);
610 type_args.SetTypeAt(0, Type::Handle(Type::ObjectType()));
611 type_args = type_args.Canonicalize();
612
613 array.SetTypeArguments(type_args);
614
615 Smi& smi = Smi::Handle();
616 for (int i = 0; i < kArrayLength; i++) {
617 smi ^= Smi::New(i);
618 array.SetAt(i, smi);
619 }
620 uint8_t* buffer;
621 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true);
622 writer.WriteMessage(array);
623 intptr_t buffer_len = writer.BytesWritten();
624
625 // Read object back from the snapshot.
626 MessageSnapshotReader reader(buffer, buffer_len, thread);
627 Array& serialized_array = Array::Handle();
628 serialized_array ^= reader.ReadObject();
629 EXPECT(array.CanonicalizeEquals(serialized_array));
630
631 // Read object back from the snapshot into a C structure.
632 ApiNativeScope scope;
633 ApiMessageReader api_reader(buffer, buffer_len);
634 Dart_CObject* root = api_reader.ReadMessage();
635 EXPECT_EQ(Dart_CObject_kArray, root->type);
636 EXPECT_EQ(kArrayLength, root->value.as_array.length);
637 for (int i = 0; i < kArrayLength; i++) {
638 Dart_CObject* element = root->value.as_array.values[i];
639 EXPECT_EQ(Dart_CObject_kInt32, element->type);
640 EXPECT_EQ(i, element->value.as_int32);
641 }
642 CheckEncodeDecodeMessage(root);
643 }
644
603 TEST_CASE(FailSerializeLargeArray) { 645 TEST_CASE(FailSerializeLargeArray) {
604 Dart_CObject root; 646 Dart_CObject root;
605 root.type = Dart_CObject_kArray; 647 root.type = Dart_CObject_kArray;
606 root.value.as_array.length = Array::kMaxElements + 1; 648 root.value.as_array.length = Array::kMaxElements + 1;
607 root.value.as_array.values = NULL; 649 root.value.as_array.values = NULL;
608 ExpectEncodeFail(&root); 650 ExpectEncodeFail(&root);
609 } 651 }
610 652
611 TEST_CASE(FailSerializeLargeNestedArray) { 653 TEST_CASE(FailSerializeLargeNestedArray) {
612 Dart_CObject parent; 654 Dart_CObject parent;
(...skipping 2479 matching lines...) Expand 10 before | Expand all | Expand 10 after
3092 StackZone zone(Thread::Current()); 3134 StackZone zone(Thread::Current());
3093 uint8_t* buffer; 3135 uint8_t* buffer;
3094 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true); 3136 MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true);
3095 writer.WriteInlinedObjectHeader(kOmittedObjectId); 3137 writer.WriteInlinedObjectHeader(kOmittedObjectId);
3096 // For performance, we'd like single-byte headers when ids are omitted. 3138 // For performance, we'd like single-byte headers when ids are omitted.
3097 // If this starts failing, consider renumbering the snapshot ids. 3139 // If this starts failing, consider renumbering the snapshot ids.
3098 EXPECT_EQ(1, writer.BytesWritten()); 3140 EXPECT_EQ(1, writer.BytesWritten());
3099 } 3141 }
3100 3142
3101 } // namespace dart 3143 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_message.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698