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

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

Issue 9348048: Add support for medium integers to the native message format (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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
« runtime/vm/snapshot.cc ('K') | « runtime/vm/snapshot.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 "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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 switch (first->type) { 73 switch (first->type) {
74 case Dart_CObject::kNull: 74 case Dart_CObject::kNull:
75 // Nothing more to compare. 75 // Nothing more to compare.
76 break; 76 break;
77 case Dart_CObject::kBool: 77 case Dart_CObject::kBool:
78 EXPECT_EQ(first->value.as_bool, second->value.as_bool); 78 EXPECT_EQ(first->value.as_bool, second->value.as_bool);
79 break; 79 break;
80 case Dart_CObject::kInt32: 80 case Dart_CObject::kInt32:
81 EXPECT_EQ(first->value.as_int32, second->value.as_int32); 81 EXPECT_EQ(first->value.as_int32, second->value.as_int32);
82 break; 82 break;
83 case Dart_CObject::kInt64:
84 EXPECT_EQ(first->value.as_int64, second->value.as_int64);
85 break;
83 case Dart_CObject::kDouble: 86 case Dart_CObject::kDouble:
84 EXPECT_EQ(first->value.as_double, second->value.as_double); 87 EXPECT_EQ(first->value.as_double, second->value.as_double);
85 break; 88 break;
86 case Dart_CObject::kString: 89 case Dart_CObject::kString:
87 EXPECT_STREQ(first->value.as_string, second->value.as_string); 90 EXPECT_STREQ(first->value.as_string, second->value.as_string);
88 break; 91 break;
89 case Dart_CObject::kArray: 92 case Dart_CObject::kArray:
90 // Use invalid type as a visited marker to avoid infinite 93 // Use invalid type as a visited marker to avoid infinite
91 // recursion on graphs with cycles. 94 // recursion on graphs with cycles.
92 second->type = Dart_CObject::kNumberOfTypes; 95 second->type = Dart_CObject::kNumberOfTypes;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 Dart_CObject* root = DecodeMessage(buffer + Snapshot::kHeaderSize, 199 Dart_CObject* root = DecodeMessage(buffer + Snapshot::kHeaderSize,
197 writer.BytesWritten(), 200 writer.BytesWritten(),
198 &zone_allocator); 201 &zone_allocator);
199 EXPECT_NOTNULL(root); 202 EXPECT_NOTNULL(root);
200 EXPECT_EQ(Dart_CObject::kInt32, root->type); 203 EXPECT_EQ(Dart_CObject::kInt32, root->type);
201 EXPECT_EQ(smi.Value(), root->value.as_int32); 204 EXPECT_EQ(smi.Value(), root->value.as_int32);
202 CheckEncodeDecodeMessage(root); 205 CheckEncodeDecodeMessage(root);
203 } 206 }
204 207
205 208
209 Dart_CObject* SerializeAndDeserializeMint(const Mint& mint) {
210 // Write snapshot with object content.
211 uint8_t* buffer;
212 SnapshotWriter writer(Snapshot::kMessage, &buffer, &zone_allocator);
213 writer.WriteObject(mint.raw());
214 writer.FinalizeBuffer();
215
216 // Create a snapshot object using the buffer.
217 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
218
219 // Read object back from the snapshot.
220 SnapshotReader reader(snapshot, Isolate::Current());
221 const Object& serialized_object = Object::Handle(reader.ReadObject());
222 EXPECT(serialized_object.IsMint());
223
224 // Read object back from the snapshot into a C structure.
225 Dart_CObject* root = DecodeMessage(buffer + Snapshot::kHeaderSize,
226 writer.BytesWritten(),
227 &zone_allocator);
228 EXPECT_NOTNULL(root);
229 CheckEncodeDecodeMessage(root);
230 return root;
231 }
232
233
234 void CheckMint(int64_t value) {
235 Zone zone(Isolate::Current());
236
237 const Mint& mint = Mint::Handle(Mint::New(value));
238 Dart_CObject* mint_cobject = SerializeAndDeserializeMint(mint);
239 // On 64-bit platforms mints always require 64-bits as the smi range
240 // here covers most of the 64-bit range. On 32-bit platforms the smi
241 // range covers most of the 32-bit range and values outside that
242 // range are also represented as mints.
243 #if defined(ARCH_IS_64_BIT)
244 EXPECT_EQ(Dart_CObject::kInt64, mint_cobject->type);
245 EXPECT_EQ(value, mint_cobject->value.as_int64);
246 #else
247 if (kMinInt32 < value && value < kMaxInt32) {
248 EXPECT_EQ(Dart_CObject::kInt32, mint_cobject->type);
249 EXPECT_EQ(value, mint_cobject->value.as_int32);
250 } else {
251 EXPECT_EQ(Dart_CObject::kInt64, mint_cobject->type);
252 EXPECT_EQ(value, mint_cobject->value.as_int64);
253 }
254 #endif
255 }
256
257
258 TEST_CASE(SerializeMints) {
259 // Min positive mint.
260 CheckMint(Smi::kMaxValue + 1);
261 // Min positive mint + 1.
262 CheckMint(Smi::kMaxValue + 2);
263 // Max negative mint.
264 CheckMint(Smi::kMinValue - 1);
265 // Max negative mint - 1.
266 CheckMint(Smi::kMinValue - 2);
267 // Max positive mint.
268 CheckMint(kMaxInt64);
269 // Max positive mint - 1.
270 CheckMint(kMaxInt64 - 1);
271 // Min negative mint.
272 CheckMint(kMinInt64);
273 // Min negative mint + 1.
274 CheckMint(kMinInt64 + 1);
275 }
276
277
206 TEST_CASE(SerializeDouble) { 278 TEST_CASE(SerializeDouble) {
207 Zone zone(Isolate::Current()); 279 Zone zone(Isolate::Current());
208 280
209 // Write snapshot with object content. 281 // Write snapshot with object content.
210 uint8_t* buffer; 282 uint8_t* buffer;
211 SnapshotWriter writer(Snapshot::kMessage, &buffer, &zone_allocator); 283 SnapshotWriter writer(Snapshot::kMessage, &buffer, &zone_allocator);
212 const Double& dbl = Double::Handle(Double::New(101.29)); 284 const Double& dbl = Double::Handle(Double::New(101.29));
213 writer.WriteObject(dbl.raw()); 285 writer.WriteObject(dbl.raw());
214 writer.FinalizeBuffer(); 286 writer.FinalizeBuffer();
215 287
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 EXPECT(Dart_ErrorHasException(result)); 1278 EXPECT(Dart_ErrorHasException(result));
1207 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]\n", 1279 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]\n",
1208 Dart_GetError(result)); 1280 Dart_GetError(result));
1209 1281
1210 Dart_ExitScope(); 1282 Dart_ExitScope();
1211 } 1283 }
1212 1284
1213 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 1285 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
1214 1286
1215 } // namespace dart 1287 } // namespace dart
OLDNEW
« runtime/vm/snapshot.cc ('K') | « runtime/vm/snapshot.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698