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

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

Issue 12907010: Fix some of teh scalarlist tests to use the TypedData VM class. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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/raw_object.h ('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 "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/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_api_message.h" 10 #include "vm/dart_api_message.h"
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 CheckEncodeDecodeMessage(root); 640 CheckEncodeDecodeMessage(root);
641 } 641 }
642 642
643 643
644 #define TEST_TYPED_ARRAY(darttype, ctype) \ 644 #define TEST_TYPED_ARRAY(darttype, ctype) \
645 { \ 645 { \
646 StackZone zone(Isolate::Current()); \ 646 StackZone zone(Isolate::Current()); \
647 uint8_t* buffer; \ 647 uint8_t* buffer; \
648 MessageWriter writer(&buffer, &zone_allocator); \ 648 MessageWriter writer(&buffer, &zone_allocator); \
649 const int kArrayLength = 127; \ 649 const int kArrayLength = 127; \
650 darttype& array = darttype::Handle(darttype::New(kArrayLength)); \ 650 TypedData& array = TypedData::Handle( \
651 TypedData::New(kTypedData##darttype##ArrayCid, kArrayLength)); \
652 intptr_t scale = array.ElementSizeInBytes(); \
651 for (int i = 0; i < kArrayLength; i++) { \ 653 for (int i = 0; i < kArrayLength; i++) { \
652 array.SetAt(i, i); \ 654 array.Set##darttype((i * scale), i); \
653 } \ 655 } \
654 writer.WriteMessage(array); \ 656 writer.WriteMessage(array); \
655 intptr_t buffer_len = writer.BytesWritten(); \ 657 intptr_t buffer_len = writer.BytesWritten(); \
656 SnapshotReader reader(buffer, buffer_len, \ 658 SnapshotReader reader(buffer, buffer_len, \
657 Snapshot::kMessage, Isolate::Current()); \ 659 Snapshot::kMessage, Isolate::Current()); \
658 darttype& serialized_array = darttype::Handle(); \ 660 TypedData& serialized_array = TypedData::Handle(); \
659 serialized_array ^= reader.ReadObject(); \ 661 serialized_array ^= reader.ReadObject(); \
660 for (int i = 0; i < kArrayLength; i++) { \ 662 for (int i = 0; i < kArrayLength; i++) { \
661 EXPECT_EQ(static_cast<ctype>(i), serialized_array.At(i)); \ 663 EXPECT_EQ(static_cast<ctype>(i), \
664 serialized_array.Get##darttype(i*scale)); \
662 } \ 665 } \
663 } 666 }
664 667
665 668
666 #define TEST_EXTERNAL_TYPED_ARRAY(darttype, ctype) \ 669 #define TEST_EXTERNAL_TYPED_ARRAY(darttype, ctype) \
667 { \ 670 { \
668 StackZone zone(Isolate::Current()); \ 671 StackZone zone(Isolate::Current()); \
669 ctype data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; \ 672 ctype data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; \
670 intptr_t length = ARRAY_SIZE(data); \ 673 intptr_t length = ARRAY_SIZE(data); \
671 External##darttype& array = External##darttype::Handle( \ 674 ExternalTypedData& array = ExternalTypedData::Handle( \
672 External##darttype::New(data, length)); \ 675 ExternalTypedData::New(kExternalTypedData##darttype##ArrayCid, \
676 reinterpret_cast<uint8_t*>(data), length)); \
677 intptr_t scale = array.ElementSizeInBytes(); \
673 uint8_t* buffer; \ 678 uint8_t* buffer; \
674 MessageWriter writer(&buffer, &zone_allocator); \ 679 MessageWriter writer(&buffer, &zone_allocator); \
675 writer.WriteMessage(array); \ 680 writer.WriteMessage(array); \
676 intptr_t buffer_len = writer.BytesWritten(); \ 681 intptr_t buffer_len = writer.BytesWritten(); \
677 SnapshotReader reader(buffer, buffer_len, \ 682 SnapshotReader reader(buffer, buffer_len, \
678 Snapshot::kMessage, Isolate::Current()); \ 683 Snapshot::kMessage, Isolate::Current()); \
679 darttype& serialized_array = darttype::Handle(); \ 684 TypedData& serialized_array = TypedData::Handle(); \
680 serialized_array ^= reader.ReadObject(); \ 685 serialized_array ^= reader.ReadObject(); \
681 for (int i = 0; i < length; i++) { \ 686 for (int i = 0; i < length; i++) { \
682 EXPECT_EQ(static_cast<ctype>(data[i]), serialized_array.At(i)); \ 687 EXPECT_EQ(static_cast<ctype>(data[i]), \
688 serialized_array.Get##darttype(i*scale)); \
683 } \ 689 } \
684 } 690 }
685 691
686 692
687 TEST_CASE(SerializeTypedArray) { 693 TEST_CASE(SerializeTypedArray) {
688 TEST_TYPED_ARRAY(Int8Array, int8_t); 694 TEST_TYPED_ARRAY(Int8, int8_t);
689 TEST_TYPED_ARRAY(Uint8Array, uint8_t); 695 TEST_TYPED_ARRAY(Uint8, uint8_t);
690 TEST_TYPED_ARRAY(Int16Array, int16_t); 696 TEST_TYPED_ARRAY(Int16, int16_t);
691 TEST_TYPED_ARRAY(Uint16Array, uint16_t); 697 TEST_TYPED_ARRAY(Uint16, uint16_t);
692 TEST_TYPED_ARRAY(Int32Array, int32_t); 698 TEST_TYPED_ARRAY(Int32, int32_t);
693 TEST_TYPED_ARRAY(Uint32Array, uint32_t); 699 TEST_TYPED_ARRAY(Uint32, uint32_t);
694 TEST_TYPED_ARRAY(Int64Array, int64_t); 700 TEST_TYPED_ARRAY(Int64, int64_t);
695 TEST_TYPED_ARRAY(Uint64Array, uint64_t); 701 TEST_TYPED_ARRAY(Uint64, uint64_t);
696 TEST_TYPED_ARRAY(Float32Array, float); 702 TEST_TYPED_ARRAY(Float32, float);
697 TEST_TYPED_ARRAY(Float64Array, double); 703 TEST_TYPED_ARRAY(Float64, double);
698 } 704 }
699 705
700 706
701 TEST_CASE(SerializeExternalTypedArray) { 707 TEST_CASE(SerializeExternalTypedArray) {
702 TEST_EXTERNAL_TYPED_ARRAY(Int8Array, int8_t); 708 TEST_EXTERNAL_TYPED_ARRAY(Int8, int8_t);
703 TEST_EXTERNAL_TYPED_ARRAY(Uint8Array, uint8_t); 709 TEST_EXTERNAL_TYPED_ARRAY(Uint8, uint8_t);
704 TEST_EXTERNAL_TYPED_ARRAY(Int16Array, int16_t); 710 TEST_EXTERNAL_TYPED_ARRAY(Int16, int16_t);
705 TEST_EXTERNAL_TYPED_ARRAY(Uint16Array, uint16_t); 711 TEST_EXTERNAL_TYPED_ARRAY(Uint16, uint16_t);
706 TEST_EXTERNAL_TYPED_ARRAY(Int32Array, int32_t); 712 TEST_EXTERNAL_TYPED_ARRAY(Int32, int32_t);
707 TEST_EXTERNAL_TYPED_ARRAY(Uint32Array, uint32_t); 713 TEST_EXTERNAL_TYPED_ARRAY(Uint32, uint32_t);
708 TEST_EXTERNAL_TYPED_ARRAY(Int64Array, int64_t); 714 TEST_EXTERNAL_TYPED_ARRAY(Int64, int64_t);
709 TEST_EXTERNAL_TYPED_ARRAY(Uint64Array, uint64_t); 715 TEST_EXTERNAL_TYPED_ARRAY(Uint64, uint64_t);
710 TEST_EXTERNAL_TYPED_ARRAY(Float32Array, float); 716 TEST_EXTERNAL_TYPED_ARRAY(Float32, float);
711 TEST_EXTERNAL_TYPED_ARRAY(Float64Array, double); 717 TEST_EXTERNAL_TYPED_ARRAY(Float64, double);
712 } 718 }
713 719
714 720
715 TEST_CASE(SerializeEmptyByteArray) { 721 TEST_CASE(SerializeEmptyByteArray) {
716 StackZone zone(Isolate::Current()); 722 StackZone zone(Isolate::Current());
717 723
718 // Write snapshot with object content. 724 // Write snapshot with object content.
719 uint8_t* buffer; 725 uint8_t* buffer;
720 MessageWriter writer(&buffer, &zone_allocator); 726 MessageWriter writer(&buffer, &zone_allocator);
721 const int kByteArrayLength = 0; 727 const int kByteArrayLength = 0;
(...skipping 1477 matching lines...) Expand 10 before | Expand all | Expand 10 after
2199 EXPECT(Dart_ErrorHasException(result)); 2205 EXPECT(Dart_ErrorHasException(result));
2200 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", 2206 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n",
2201 Dart_GetError(result)); 2207 Dart_GetError(result));
2202 2208
2203 Dart_ExitScope(); 2209 Dart_ExitScope();
2204 } 2210 }
2205 2211
2206 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 2212 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
2207 2213
2208 } // namespace dart 2214 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/raw_object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698