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

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: Addressed review comments from asiva@ 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
« no previous file with comments | « 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::kByteArray: 92 case Dart_CObject::kByteArray:
90 EXPECT_EQ(first->value.as_byte_array.length, 93 EXPECT_EQ(first->value.as_byte_array.length,
91 second->value.as_byte_array.length); 94 second->value.as_byte_array.length);
92 for (int i = 0; i < first->value.as_byte_array.length; i++) { 95 for (int i = 0; i < first->value.as_byte_array.length; i++) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 Dart_CObject* root = DecodeMessage(buffer + Snapshot::kHeaderSize, 209 Dart_CObject* root = DecodeMessage(buffer + Snapshot::kHeaderSize,
207 writer.BytesWritten(), 210 writer.BytesWritten(),
208 &zone_allocator); 211 &zone_allocator);
209 EXPECT_NOTNULL(root); 212 EXPECT_NOTNULL(root);
210 EXPECT_EQ(Dart_CObject::kInt32, root->type); 213 EXPECT_EQ(Dart_CObject::kInt32, root->type);
211 EXPECT_EQ(smi.Value(), root->value.as_int32); 214 EXPECT_EQ(smi.Value(), root->value.as_int32);
212 CheckEncodeDecodeMessage(root); 215 CheckEncodeDecodeMessage(root);
213 } 216 }
214 217
215 218
219 Dart_CObject* SerializeAndDeserializeMint(const Mint& mint) {
220 // Write snapshot with object content.
221 uint8_t* buffer;
222 SnapshotWriter writer(Snapshot::kMessage, &buffer, &zone_allocator);
223 writer.WriteObject(mint.raw());
224 writer.FinalizeBuffer();
225
226 // Create a snapshot object using the buffer.
227 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
228
229 // Read object back from the snapshot.
230 SnapshotReader reader(snapshot, Isolate::Current());
231 const Object& serialized_object = Object::Handle(reader.ReadObject());
232 EXPECT(serialized_object.IsMint());
233
234 // Read object back from the snapshot into a C structure.
235 Dart_CObject* root = DecodeMessage(buffer + Snapshot::kHeaderSize,
236 writer.BytesWritten(),
237 &zone_allocator);
238 EXPECT_NOTNULL(root);
239 CheckEncodeDecodeMessage(root);
240 return root;
241 }
242
243
244 void CheckMint(int64_t value) {
245 Zone zone(Isolate::Current());
246
247 const Mint& mint = Mint::Handle(Mint::New(value));
248 ApiNativeScope scope;
249 Dart_CObject* mint_cobject = SerializeAndDeserializeMint(mint);
250 // On 64-bit platforms mints always require 64-bits as the smi range
251 // here covers most of the 64-bit range. On 32-bit platforms the smi
252 // range covers most of the 32-bit range and values outside that
253 // range are also represented as mints.
254 #if defined(ARCH_IS_64_BIT)
255 EXPECT_EQ(Dart_CObject::kInt64, mint_cobject->type);
256 EXPECT_EQ(value, mint_cobject->value.as_int64);
257 #else
258 if (kMinInt32 < value && value < kMaxInt32) {
259 EXPECT_EQ(Dart_CObject::kInt32, mint_cobject->type);
260 EXPECT_EQ(value, mint_cobject->value.as_int32);
261 } else {
262 EXPECT_EQ(Dart_CObject::kInt64, mint_cobject->type);
263 EXPECT_EQ(value, mint_cobject->value.as_int64);
264 }
265 #endif
266 }
267
268
269 TEST_CASE(SerializeMints) {
270 // Min positive mint.
271 CheckMint(Smi::kMaxValue + 1);
272 // Min positive mint + 1.
273 CheckMint(Smi::kMaxValue + 2);
274 // Max negative mint.
275 CheckMint(Smi::kMinValue - 1);
276 // Max negative mint - 1.
277 CheckMint(Smi::kMinValue - 2);
278 // Max positive mint.
279 CheckMint(kMaxInt64);
280 // Max positive mint - 1.
281 CheckMint(kMaxInt64 - 1);
282 // Min negative mint.
283 CheckMint(kMinInt64);
284 // Min negative mint + 1.
285 CheckMint(kMinInt64 + 1);
286 }
287
288
216 TEST_CASE(SerializeDouble) { 289 TEST_CASE(SerializeDouble) {
217 Zone zone(Isolate::Current()); 290 Zone zone(Isolate::Current());
218 291
219 // Write snapshot with object content. 292 // Write snapshot with object content.
220 uint8_t* buffer; 293 uint8_t* buffer;
221 SnapshotWriter writer(Snapshot::kMessage, &buffer, &zone_allocator); 294 SnapshotWriter writer(Snapshot::kMessage, &buffer, &zone_allocator);
222 const Double& dbl = Double::Handle(Double::New(101.29)); 295 const Double& dbl = Double::Handle(Double::New(101.29));
223 writer.WriteObject(dbl.raw()); 296 writer.WriteObject(dbl.raw());
224 writer.FinalizeBuffer(); 297 writer.FinalizeBuffer();
225 298
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 EXPECT(Dart_ErrorHasException(result)); 1390 EXPECT(Dart_ErrorHasException(result));
1318 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]\n", 1391 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]\n",
1319 Dart_GetError(result)); 1392 Dart_GetError(result));
1320 1393
1321 Dart_ExitScope(); 1394 Dart_ExitScope();
1322 } 1395 }
1323 1396
1324 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 1397 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
1325 1398
1326 } // namespace dart 1399 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/snapshot.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698